I am admittedly a fairly simple Python programmer trying to learn when I encounter problems related to various research issues. And I hit one of these problems - in particular, how to handle loops, where I return a bunch of data, rather than the usual "exit from one number" examples, where you simply add the loop result to the previous one.
There is a Gist unlooped script here I'm trying to run: https://gist.github.com/1390355
In fact, the important point is the end of the model_solve function:
def model_solve(t): # lots of variables set params = np.zeroes((n_steps,n_params) params[:,0] = beta params[:,1] = gamma timer = np.arange(n_steps).reshape(n_steps,1) SIR = spi.odeint(eq_system, startPop, t_interval) output = np.hstack((timer,SIR,params)) return output
This returns the results of the ODE integration bit ( spi.odeint ) along with the simple βWhat step are we now?β a timer and essentially two columns, the values ββof two random variables are repeated many, many times in the form of an array of 4950 rows and 7 NumPy columns.
However, the goal is to run a Monte Carlo analysis of two parameters (beta and gamma) that have random values. Essentially, I want to create a function that will alternate like this:
def loop_function(runs): for i in range(runs): model_solve(100)
Then the collected output will be written to a file. Normally, I would simply use each model_solve function for its own results for the file, but this code will be run on PiCloud or another platform where I do not have the ability to write the file until the results are returned to the local computer. Instead, I am trying to get a huge NumPy array from the columns runs * 7 and 4950 rows, which can then be written to a file on my local machine.
Any tips on how to approach this?