Statsrs: Generate normal distribution from a vector of means and a scalar variance

This Python code generates a 10_000 vector xt given a vector of values mean and a scalar variance v.

x0 = np.random.normal(loc = 0, scale = 1, size = 10000) // initial points, outputs a 10_000 vector
mean = X0*np.exp(-0.5) // 10_000 vector 
variance = np.sqrt(4/(1-np.exp(-1)) // = 1.5901201952413002
xt = np.random.normal(m,v) // = 10_000 vector

In statsrs, there is a type mismatch (understandably so!) when inserting a vector into the argument mean in statsrs::distribution::Normal. Are there any work-arounds for this?

My Rust code (which does not work, as there is a type mismatch) is below.

let x0: Vec<f64> = thread_rng().sample_iter(Standard).take(size).collect();

    // Calculate the endpoint using the initial point, x0.
    // Since f64 implements the Copy trait,
    // we don't have to clone into a new place in the heap
    let endpoint_mean: Vec<_> = x0
        .map(|&x| THETA + (x - THETA) * (-KAPPA * TIME).exp())

    let endpoint_variance: f64 =
        (SIGMA.pow(2) as f64 / (2.0 * KAPPA) * (1.0 - (-2.0 * KAPPA * TIME).exp())).sqrt();

    let n = Normal::new(endpoint_mean, endpoint_variance).unwrap();
    println!("{}", n.pdf(1.0))

What is the error?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.