print p,result.x[i] # For visualization
    k_result.append(result.x[i])
    
# Store IC results in an empty list that is appended with an empty list for each iteration of ICs. The inner empty list is filled with the 
# IC values from the previous simulation (or initial for first - index + IC list (1 list) * 3 (items in list) + 7 (after all rate parameters).
# The previous result is then overwritten with the new parameters (using same equation above) - values are printed to screen
ic_result = []
for n in range(len(ICs())):
    ic_result.append([])
    print ICs()[n]," = [",
    for i,p in enumerate(model.parameters[:3]):
        print str(result.x[i+n*3+7]) + ",",
        ic_result[-1].append(result.x[i+n*3+7])
    print "]"

### Plotting parameter optimized model output ###
# Append a numpy array of 0s with rate parameters (last 7) and ICs (first 3). The rate parameters are the same for all the model outputs, 
# while the ICs change. In each iteration, the parameter values are saved, normalized, and plotted.
param_values = np.zeros(len(model.parameters))
param_values[3:] = k_result
for i, ic in enumerate(ICs()):
    param_values[:3] = ic_result[i] # N lists that contain 3 numbers
    solver.verbose = False
    solver.run(param_values=param_values) # saved in array - species y, obs in yobs, ic is 3 element list
    nl2_sim = np.log2(solver.yobs["Obs_All"]/solver.yobs["Obs_All"][0]) # making it nl2
    plt.figure(i)
    plt.plot(time, nl2_sim, 'go-', ms = 12, mfc = "None", mew = 2, mec = "g")
    plt.xlabel('Time')
    plt.ylabel('Population Doublings (nl2)')
    plt.title('Parameter Estimation')
plt.show()
Beispiel #2
0
    t90 = scipy.interpolate.sproot((st, sc - 0.90, sk))[0]
    # Calculate Td as the mean of these times
    td = (t10 + t90) / 2
    # Calculate Ts as their difference
    ts = t90 - t10
    # Get yfinal, the last element from the trajectory
    yfinal = ysim_momp[-1]
    # Build a vector of the 3 variables to fit
    momp_sim = [td, ts, yfinal]
    # Perform chi-squared calculation against mean and variance vectors
    e2 = np.sum((momp_data - momp_sim)**2 / (2 * momp_var)) / 3
    return [emBid, ecPARP, e2]


N_SAMPLES = range(10, 100, 10) + range(100, 501, 50)
solver.verbose = False

for n_samples in N_SAMPLES:

    sample = Sample(
        len(model.parameters_rules()),
        n_samples,
        lambda x: scale.linear(x, lower_bound=0.1 * ref, upper_bound=10 * ref),
        verbose=True)
    objective = Objective(len(model.parameters_rules()),
                          n_samples,
                          sample,
                          objective_func,
                          verbose=True)
    v = Varsens(objective, verbose=True)