Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
WuShichao committed Aug 1, 2024
1 parent 87f10cb commit cbcd5a2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
7 changes: 7 additions & 0 deletions pycbc/inference/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,16 @@ def _trytoget(self, statname, fallback, apply_transforms=False, **kwargs):
return getattr(self._current_stats, statname)
except AttributeError:
# apply waveform transforms if requested
print("[BaseModel _trytoget] apply_transforms: ", apply_transforms)
print("[BaseModel _trytoget] self.waveform_transforms: ", self.waveform_transforms)
print("[BaseModel _trytoget] self._current_params 1: ", self._current_params)
if apply_transforms and self.waveform_transforms is not None:
self._current_params = transforms.apply_transforms(
self._current_params, self.waveform_transforms,
inverse=False)
val = fallback(**kwargs)
setattr(self._current_stats, statname, val)
print("[BaseModel _trytoget] self._current_params 2: ", self._current_params)
return val

@property
Expand All @@ -520,6 +524,7 @@ def loglikelihood(self):
If that raises an ``AttributeError``, will call `_loglikelihood`` to
calculate it and store it to ``current_stats``.
"""
print("[BaseModel] loglikelihood")
return self._trytoget('loglikelihood', self._loglikelihood,
apply_transforms=True)

Expand All @@ -546,6 +551,7 @@ def logjacobian(self):
float :
The value of the jacobian.
"""
print("[BaseModel] logjacobian")
return self._trytoget('logjacobian', self._logjacobian)

def _logjacobian(self):
Expand All @@ -560,6 +566,7 @@ def _logjacobian(self):
@property
def logprior(self):
"""Returns the log prior at the current parameters."""
print("[BaseModel] logprior")
return self._trytoget('logprior', self._logprior)

def _logprior(self):
Expand Down
4 changes: 4 additions & 0 deletions pycbc/inference/models/gaussian_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def __init__(self, variable_params, data, low_frequency_cutoff, psds=None,
static_params=static_params,
no_save_data=no_save_data,
**kwargs)
print("[BaseGaussianNoise __init__] self.sampling_transforms :", self.sampling_transforms)
print("[BaseGaussianNoise __init__] self.waveform_transforms :", self.waveform_transforms)
self.ignore_failed_waveforms = ignore_failed_waveforms
self.no_save_data = no_save_data
# check if low frequency cutoff has been provided for every IFO with
Expand Down Expand Up @@ -536,6 +538,7 @@ def from_config(cls, cp, data_section='data', data=None, psds=None,
All additional keyword arguments are passed to the class. Any
provided keyword will override what is in the config file.
"""
print("[BaseGaussianNoise from_config] cp.sections() :", cp.sections())
# get the injection file, to replace any FROM_INJECTION settings
if 'injection-file' in cp.options('data'):
injection_file = cp.get('data', 'injection-file')
Expand Down Expand Up @@ -617,6 +620,7 @@ def from_config(cls, cp, data_section='data', data=None, psds=None,
if gates:
args['gates'] = gates
args.update(kwargs)
print("[BaseGaussianNoise from_config] args: ", args)
return cls(**args)


Expand Down
14 changes: 3 additions & 11 deletions pycbc/inference/models/hierarchical.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ def from_config(cls, cp, **kwargs):
submodels = {}
logging.info("Loading submodels")
for lbl in submodel_lbls:
print("lbl: ", lbl)
logging.info("============= %s =============", lbl)
# create a config parser to pass to the model
subcp = WorkflowConfigParser()
Expand All @@ -887,6 +888,7 @@ def from_config(cls, cp, **kwargs):
"individual parameter names with the "
"model label. See HierarchicalParam for "
"details.".format(sec))
print("[from_config] sec.subname: ", sec.subname)
subcp.add_section(sec.subname)
for opt, val in cp.items(sec):
subcp.set(sec.subname, opt, val)
Expand Down Expand Up @@ -915,21 +917,10 @@ def from_config(cls, cp, **kwargs):
subcp.set('static_params', param.subname, 'REPLACE')

for section in cp.sections():
print("[from_config] section: ", section)
print("[from_config] '%s__waveform_transforms' % lbl: ", '%s__waveform_transforms' % lbl)
print("[from_config] '%s__waveform_transforms' % lbl in section: ", '%s__waveform_transforms' % lbl in section)
# the primary model needs prior of marginlized parameters
if 'prior-' in section and lbl in kwargs['primary_lbl']:
prior_section = '%s' % section
subcp[prior_section] = cp[prior_section]
# if `waveform_transforms` has a prefix,
# add it into sub-models' config
elif '%s__waveform_transforms' % lbl in section:
transforms_section = '%s' % section
subcp[transforms_section] = cp[transforms_section]
print("[from_config] subcp[transforms_section]: ", subcp[transforms_section])
else:
pass

# similar to the standard hierarchical model,
# add the outputs from the waveform transforms if sub-model
Expand All @@ -938,6 +929,7 @@ def from_config(cls, cp, **kwargs):
for param in wfparam_map[lbl]:
subcp.set('static_params', param.subname, 'REPLACE')

print("[from_config] subcp.sections(): ", subcp.sections())
# save the vitual config file to disk for later check
with open('%s.ini' % lbl, 'w', encoding='utf-8') as file:
subcp.write(file)
Expand Down
1 change: 1 addition & 0 deletions pycbc/inference/models/relbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ def get_waveforms(self, params):
"""
if self.still_needs_det_response:
wfs = {}
print("[relbin] params: ", params)
for ifo in self.data:
wfs.update(get_fd_det_waveform_sequence(
ifos=ifo, sample_points=self.fedges[ifo], **params))
Expand Down

0 comments on commit cbcd5a2

Please sign in to comment.