A python function (m, cv) = program(fun, nSamples, nOutput, nInput, mn, sd) which implements a Monte Carlo
Question:
A python function (m, cv) = program(fun, nSamples, nOutput, nInput, mn, sd) which implements a Monte Carlo simulation. The model of the simulation is contained in fun and all input variables follow a normal distribution.
Inputs:
fun: A function with the call out = fun(in) where in is a 1D numpy array of length nInput and out is a 1D numpy array of length nOutput.
'nSamples': The number of samples to collect.
nOutput: The length of the output array of func.
nInput: The length of the input array of func.
mn: A 1D numpy array of length nInput listing the mean of each input variable
.
sd: A 1D numpy array of length nInput listing the standard deviation of each input variable.
Outputs:
m: A 1D numpy array of length nOutput with the mean of each output variable.
cv: A 2D numpy array of size nOutput by nOutput containing the covariance matrix of the output variables.
You can use numpy functions like:
empty or zeros, mean, cov, random.normal
Introduction To Probability And Statistics
ISBN: 9781133103752
14th Edition
Authors: William Mendenhall, Robert Beaver, Barbara Beaver