Optimize the loading of .stan model in expan. Minor changes.
@@ -181,16 +181,14 @@ def _bayes_sampling(x, y, distribution='normal', num_iters=25000):
else:
# Compile the model if no compiled version of it exists
sm = StanModel(file=model_file)
+ # Save compiled model
+ with open(__location__ + '/../models/' + distribution + '_kpi.pkl', 'wb') as f:
+ pickle.dump(sm, f)
fit = sm.sampling(data=fit_data, iter=num_iters, chains=4, n_jobs=1, seed=1,
control={'stepsize': 0.01, 'adapt_delta': 0.99})
traces = fit.extract()
- # Save compiled model
- if not os.path.isfile(compiled_model_file):
- with open(__location__ + '/../models/' + distribution + '_kpi.pkl', 'wb') as f:
- pickle.dump(sm, f)
-
return traces, n_x, n_y, mu_x, mu_y
