SDXorg / PySD-Cookbook

Simple Recipes for Powerful Analysis of System Dynamics Models
62 stars 32 forks source link

Bug : Parallel Model Fitting Example #23

Open AlABarazi opened 4 years ago

AlABarazi commented 4 years ago

Hi, I am getting error in cookbook example Parallel Model Fitting

TypeError: ("run() got an unexpected keyword argument 'rtol'", 'occurred at index 0')

When I run the code


param_names = ['dec_%i_loss_rate'%i for i in range(1,10)]

def error(param_vals, measurements):
    predictions = model.run(params=dict(zip(param_names, param_vals)),
                            initial_condition=(2000,measurements['2000']),
                            return_timestamps=2010, rtol=1).loc[2010]

    errors = predictions - measurements['2010']
    return sum(errors.values[1:]**2) #ignore first decade: no birth info

def fit(row):
    res = scipy.optimize.minimize(error, args=row,
                                  x0=[.05]*9,
                                  method='L-BFGS-B');
    return pd.Series(index=['dec_%i_loss_rate'%i for i in range(1,10)], data=res['x'])

%%capture
county_params = data.apply(fit, axis=1)