Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
>> higher "a" indicatively leads to slower learning, but smoother learning
resample_thresh: provides an indicator of how frequently to call resampling.
>> higher the "thresh" value, more frequently resampling events will occur, indicatively leading to faster but less smooth learning
TBC: continues the learning from a previous prior instead of wiping it and restarting
"""
if TBC:
print("Continuing from...")
print(self.prior)
else:
self.prior = qi.UniformDistribution([self.freq_min, self.freq_max])
self.updater = qi.SMCUpdater(self.model, self.n_particles, self.prior, resample_a=resample_a,
resample_thresh=resample_thresh)
if use_heuristic is "PGH":
self.heuristic = stdPGH(self.updater, inv_field='w_')
elif use_heuristic is "rootPGH":
self.heuristic = rootPGH(self.updater, root=1, inv_field='w_')
else:
self.heuristic = stepwise_heuristic(self.updater, n_shots=1, ts=data[0])
if data is None:
self.sim = True
if verbose: print("Simulated run with")
true_params = self.prior.sample()
elif len(data) is 1:
self.sim = True
if verbose: print("Simulated run with")
true_params = data
else:
next_tau = tau_0 * self.exp_base**i_tau
next_tau_s = next_tau
if self.readout_phase_rad is None:
try:
phi_read = m_phase * 2*np.pi / m_tot_phases
except ZeroDivisionError:
phi_read = 0
else:
phi_read = self.readout_phase_rad
# not in normal format of heuristics!
return (next_tau_s, phi_read)
class T2RandPenalty_PGH(stdPGH):
def __init__(self, updater, tau_thresh_rescale, inv_field='x_', t_field='t',
inv_func=qi.expdesign.identity,
t_func=qi.expdesign.identity,
maxiters=10,
other_fields=None, scale_f=2.0):
"""
Apply a penalty on taus calculated from stdPGH and rescale them to lower values.
:param tau_thresh_rescale: values above will be rescaled
:param scale_f: controls the cut off tau. tau_cut = tau_thresh_rescale + scale_f * tau_thresh_rescale
= 2 -> tau_max = 3*tau_thresh_rescale
"""
super().__init__(updater, inv_field, t_field, inv_func, t_func, maxiters, other_fields)
self.tau_thresh_rescale = tau_thresh_rescale
self.scale_f = scale_f
def __init__(self, updater, inv_field='x_', t_field='t',
inv_func=qi.expdesign.identity,
t_func=qi.expdesign.identity,
maxiters=10,
other_fields=None
):
super(stdPGH, self).__init__(updater)
self._x_ = inv_field
self._t = t_field
self._inv_func = inv_func
self._t_func = t_func
self._maxiters = maxiters
self._other_fields = other_fields if other_fields is not None else {}