Skip to content

Commit

Permalink
make 1-hierarchical model work
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesBuchner committed Mar 18, 2024
1 parent 624a5e5 commit b67d985
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 0 additions & 4 deletions bxa/xspec/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ def store_chain(chainfilename, transformations, posterior, fit_statistic):
old_model = transformations[0]['model']
names = []
for t in transformations:
if t.get('skip_setting', False):
continue
if t['model'] != old_model:
group_index += 1
old_model = t['model']
Expand All @@ -89,8 +87,6 @@ def set_parameters(transformations, values):
assert len(values) == len(transformations)
pars = []
for i, t in enumerate(transformations):
if t.get('skip_setting', False):
continue
v = t['aftertransform'](values[i])
assert not isnan(v) and not isinf(v), 'ERROR: parameter %d (index %d, %s) to be set to %f' % (
i, t['index'], t['name'], v)
Expand Down
15 changes: 13 additions & 2 deletions examples/xspec/series/example_simplest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,17 @@ def loggaussian_hierarchical_prior(cube):
for i, filename in enumerate(['sim1.fak', 'sim2.fak', 'sim3.fak'], start=1):
AllData("%d:%d %s" % (i, i, filename))
s1 = AllData(i)
s1.ignore("**"); s1.notice("0.2-8.0")
s1.ignore("**-0.2, 8.0-**")
print("setting up model")
m1 = AllModels(i)
m1.wabs.nH.values = ",,0.01,0.01,1000,1000"
m1.powerlaw.norm.values = ",,1e-10,1e-10,1e1,1e1"
#m1.powerlaw.norm.values = ",,1e-10,1e-10,1e1,1e1"
#m1.powerlaw.PhoIndex.values = ",,1,1,3,3"
if i != 1:
m1.powerlaw.PhoIndex.link = '=%d' % AllModels(1).powerlaw.PhoIndex.index
if i != 1:
m1.powerlaw.norm.link = '=%d' % AllModels(1).powerlaw.norm.index
transformations += [
bxa.create_uniform_prior_for( m1, m1.wabs.nH),
]
Expand Down Expand Up @@ -128,5 +134,10 @@ def loggaussian_hierarchical_prior(cube):
prior_function=combined_prior,
outputfiles_basename='hierarchical3/',
)
results = solver.run(resume=True)
import ultranest.stepsampler
results = solver.run(resume=True,
run_kwargs=dict(frac_remain=0.5),
stepsampler_kwargs=dict(
generate_direction=ultranest.stepsampler.generate_mixture_random_direction,
initial_max_ncalls=100000, nsteps=100))
print('running analysis ... done!')

0 comments on commit b67d985

Please sign in to comment.