Skip to content

Commit

Permalink
full_wideband_designmatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisrkckl committed Feb 14, 2025
1 parent 8289c76 commit aa07a51
Showing 1 changed file with 5 additions and 51 deletions.
56 changes: 5 additions & 51 deletions src/pint/fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,12 +1468,11 @@ def M_params_units_norm(self):
)

if not self.full_cov:
Mn = DesignMatrixMaker("toa_noise", u.s)(self.fitter.toas, self.model)
# Mn = DesignMatrixMaker("toa_noise", u.s)(self.fitter.toas, self.model)
phiinv = 1 / self.model.full_basis_weight(self.fitter.toas)
if Mn is not None:
M, params, units, _ = self.model.full_wideband_designmatrix(
self.fitter.toas
)
M, params, units, _ = self.model.full_wideband_designmatrix(
self.fitter.toas
)

M, norm = normalize_designmatrix(M, params)
self.fac = norm
Expand Down Expand Up @@ -1506,14 +1505,7 @@ def mtcm_mtcy_mtcmplain(self):

# compute covariance matrices
if self.full_cov:
cov = combine_covariance_matrix(
[
CovarianceMatrixMaker("toa", u.s)(self.fitter.toas, self.model),
CovarianceMatrixMaker("dm", u.pc / u.cm**3)(
self.fitter.toas, self.model
),
]
).matrix
cov = self.model.wideband_covariance_matrix(self.fitter.toas)
cf = scipy.linalg.cho_factor(cov)
cm = scipy.linalg.cho_solve(cf, self.M)
mtcm = np.dot(self.M.T, cm)
Expand Down Expand Up @@ -1568,44 +1560,6 @@ def step(self):
# compute absolute estimates, normalized errors, covariance matrix
return self.xhat / self.norm

@cached_property
def step1(self):
residuals = self.resids.calc_wideband_resids()

# compute covariance matrices
if self.full_cov:
M, params, units, _ = self.model.wideband_designmatrix(self.fitter.toas)
M, norm = normalize_designmatrix(M, params)
cov = self.model.wideband_covariance_matrix(self.fitter.toas)
mtcm, mtcy = get_gls_mtcm_mtcy_fullcov(cov, M, residuals)
else:
M, params, units, _ = self.model.full_wideband_designmatrix(
self.fitter.toas
)
M, norm = normalize_designmatrix(M, params)
phiinv = 1 / self.model.full_basis_weight(self.fitter.toas) / norm**2
self.phiinv = phiinv
Nvec = self.model.scaled_wideband_uncertainty(self.fitter.toas) ** 2
mtcm, mtcy = get_gls_mtcm_mtcy(phiinv, Nvec, M, residuals)

self.params = params
self.units = units
self.M = M
self.fac = norm

# TODO: seems like doing this on every iteration is wasteful, and we should just do it once and then update the matrix
covariance_matrix_labels = {
param: (i, i + 1, unit)
for i, (param, unit) in enumerate(zip(params, units))
}
# covariance matrix is 2D and symmetric
self.parameter_covariance_matrix_labels = [covariance_matrix_labels] * 2

self.xvar, self.xhat = _solve_svd(mtcm, mtcy, self.threshold, params)
self.norm = norm

return self.xhat / norm

def take_step(self, step, lambda_=1):
return WidebandState(
self.fitter, self.take_step_model(step, lambda_), threshold=self.threshold
Expand Down

0 comments on commit aa07a51

Please sign in to comment.