Skip to content

Commit

Permalink
optimizer working!
Browse files Browse the repository at this point in the history
  • Loading branch information
karllark committed Aug 29, 2024
1 parent afb97d5 commit a51f1c6
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions megabeast/mbmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def _get_best_fit_params(sampler):
return fit_params_best


def fit_ensemble(megabeast_model, star_lnpgriddata, beast_moddata):
def fit_ensemble(megabeast_model, star_lnpgriddata, beast_moddata, nsteps=300):
"""
Run the MegaBEAST on a single set of BEAST results.
Expand Down Expand Up @@ -364,15 +364,15 @@ def chi2(*args):

sparams = megabeast_model.start_params()[1]

# result = op.minimize(
# result = op.least_squares(
# chi2,
# sparams,
# args=(megabeast_model, star_lnpgriddata, beast_moddata),
# ftol=1e-20,
# xtol=1e-20
# method="Nelder-Mead",
# )
result = scipy.optimize.minimize(
chi2,
sparams,
args=(megabeast_model, star_lnpgriddata, beast_moddata),
#ftol=1e-20,
#xtol=1e-20,
method="Nelder-Mead",
)
return result["x"]
# exit()

ndim, nwalkers = len(sparams), 5 * len(sparams)
Expand All @@ -382,7 +382,6 @@ def chi2(*args):
sampler = emcee.EnsembleSampler(
nwalkers, ndim, lnprob, args=(megabeast_model, star_lnpgriddata, beast_moddata)
)
nsteps = 300
sampler.run_mcmc(pos, nsteps, progress=True)
# samples = sampler.get_chain()

Expand Down

0 comments on commit a51f1c6

Please sign in to comment.