Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13921

Python argument type randomly taking on scipy interp1d type

$
0
0

I'm creating code to simulate differential equations driven by stochastic processes, but I'm having an issue where I get the error:

return (-2)/(h - (np.sqrt(kappa) * stochastic(t) + alpha * t))TypeError: loop of ufunc does not support argument 0 of type interp1d which has no callable sqrt method

But my argument kappa is type float. The code generating the error is:

bmv = brownian_motion(t, steps)bm = interp1d(x=t_eval, y=bmv)range_kappa = np.linspace(0.1, 1.1, 11)sols = []for i in range(len(range_kappa)):    sol = solve_diffeq_scaled(t, steps, h0, range_kappa[i], bm, alpha)    sols = np.vstack([sols, sol])

and my def for brownian_motion and solve_diffeq_scaled is:

def brownian_motion(t, steps):    dt = t / steps    sd = np.sqrt(dt)    array = np.random.normal(0, sd, steps)    array = np.concatenate([[0], array])    array = np.cumsum(array)    return arraydef scaled_dh_dt(t, h, stochastic, kappa, alpha):    return (-2)/(h - (np.sqrt(kappa) * stochastic(t) + alpha * t))def solve_diffeq_scaled(t, steps, h0, kappa, stochastic, alpha):    t_span = [0, t]    t_eval = np.linspace(0, t, steps + 1)    sol = solve_ivp(scaled_dh_dt, t_span=t_span, y0=[h0], t_eval=t_eval, args=(kappa, stochastic, alpha))    return sol

As you can see, interp1d is isn't being applied to kappa at all so I'm wondering why my code isn't working.

I have no idea how to fix this.


Viewing all articles
Browse latest Browse all 13921

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>