-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jaimerzp
committed
Jun 13, 2024
1 parent
231779a
commit 3543563
Showing
5 changed files
with
172 additions
and
94 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .projector_base import ProjectorBase | ||
from .projector_shifts import ProjectorShifts | ||
from .projector_shifts_widths import ProjectorShiftsWidths | ||
from .projector_moments import ProjectorMoments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
import numpy as np | ||
from ..ensemble import Ensemble | ||
from multipledispatch import dispatch | ||
from .projector_base import ProjectorBase | ||
from scipy.interpolate import interp1d | ||
from scipy.stats import multivariate_normal | ||
from scipy.stats import multivariate_normal as mvn | ||
|
||
|
||
class ProjectorShifts(ProjectorBase): | ||
@dispatch() | ||
def __init__(self): | ||
self._project_base() | ||
self._project() | ||
|
||
@dispatch(np.ndarray, np.ndarray) | ||
def __init__(self, zs, pzs): | ||
self._project_base(zs, pzs) | ||
self._project() | ||
|
||
@dispatch(Ensemble) | ||
""" | ||
Projector for the shifts model. | ||
The shift model assumes that all the variation in the measured | ||
photometric distributions can be described by a single shift in | ||
the position of the mean of a fiducial n(z) distribution. | ||
This shift is calibrated by computing the standard deviations | ||
of the measured photometric distributions over redshift. | ||
The shift prior is then given by a Gaussian distribution with | ||
mean 0 and variance equal to the ratio of the standard deviation | ||
of the standard deviations to the mean of the standard deviations. | ||
""" | ||
def __init__(self, ens): | ||
self._project_base(ens) | ||
self._project() | ||
|
||
def _project(self): | ||
self.shift = self._find_shift() | ||
|
||
def evaluate_model(self, pz, shift): | ||
def evaluate_model(self, nz, shift): | ||
""" | ||
Aplies a shift to the given p(z) distribution. | ||
This is done by interpolating the p(z) distribution | ||
at the shifted z values and then evaluating it at the | ||
original z values. | ||
""" | ||
z = pz[0] | ||
pz = pz[1] | ||
z = nz[0] | ||
nz = nz[1] | ||
z_shift = z + shift | ||
pz_shift = interp1d(z_shift, pz, | ||
pz_shift = interp1d(z_shift, nz, | ||
kind='linear', | ||
fill_value='extrapolate')(z) | ||
return [z, pz_shift] | ||
|
||
def _find_shift(self): | ||
stds = np.std(self.pzs, axis=1) # std of each pz | ||
stds = np.std(self.nzs, axis=1) # std of each pz | ||
s_stds = np.std(stds) # std of the z-std | ||
m_stds = np.mean(stds) # mean of the z-std | ||
return s_stds / m_stds | ||
|
||
def _get_prior(self): | ||
return multivariate_normal([0], [self.shift**2]) | ||
return mvn([0], [self.shift**2]) |