harv.models.extensions package¶
Extension base class and built-in extensions for model components.
- class harv.models.extensions.AbstractExtension¶
Bases:
ModuleAbstract base class for model extensions (jitter, trends, offsets, GP, …).
An extension can declare extra parameters (nonlinear and/or linear), modify the design matrix (e.g., append trend or offset columns), and/or modify the data covariance matrix (e.g., add jitter or a GP kernel).
Extensions are composed onto a
AbstractComponentModelat construction time via theextensionsfield. The model calls each hook in the order the extensions are listed.All extensions receive the raw (unit-stripped) JAX arrays. Unit handling is the model’s responsibility.
Subclasses must implement
extra_params(). The design-matrix and covariance hooks have default no-op implementations that return their input unchanged.Plot-specific behavior is handled privately by plotting helpers rather than through this base extension API.
- __init__()¶
- Return type:
None
- static __new__(cls, *args, **kwargs)¶
- abstractmethod extra_params()¶
Parameters introduced by this extension.
- modify_covariance(cov, data, nl_values)¶
Optionally modify the data covariance matrix.
- Parameters:
cov (
Array) – Current covariance. Diagonal (1-d) when only measurement errors are present; full (2-d) after a GP extension adds off-diagonal structure. shape (n_obs,) or (n_obs, n_obs)data (
AbstractData|None) – Observation data.nl_values (
dict[str,Any]) – Current nonlinear parameter values (unit-stripped scalars).
- Return type:
- Returns:
Updated covariance (same or promoted shape). Return
covunchanged if not applicable.
- modify_design_matrix(X, data, nl_values)¶
Optionally append columns to the design matrix.
- Parameters:
- Return type:
- Returns:
Updated design matrix, shape
(n_obs, n_cols + n_extra). ReturnXunchanged if not applicable.
- class harv.models.extensions.GP¶
Bases:
AbstractExtensionGaussian Process covariance extension.
Adds the kernel matrix
K(t, t')to the observation covariance via themodify_covariancehook, allowing analytic marginalization of linear parameters in the presence of correlated noise.Plotting code may choose to visualize the GP contribution, but that support is handled privately on the plotting side rather than through the extension base API.
- Parameters:
kernel_builder (
Callable[[dict[str,Any]],Any]) – Receives the full nonlinear-parameter dict (unit-stripped) and returns a callable kernel object that can be called with(X, Xp)to produce the kernel matrix. For example, fromtinygp.hyperparams (
tuple[ParamInfo,...]) – Nonlinear hyperparameters declared by this extension (e.g.gp_amp,gp_length_scale). These are sampled alongside other nonlinear model parameters.time_unit (
str) – Unit to strip times to before building the coordinate array. Default""(dimensionless / already stripped).
Examples
>>> from harv.models.extensions.base import ParamInfo >>> from harv.models.extensions.gp import GP; GP( ... kernel_builder=lambda hp: hp["gp_amp"] ** 2, ... hyperparams=(ParamInfo("gp_amp", "km/s"),), ... time_unit="day", ... ).extra_params()[0].name 'gp_amp'
- __init__(kernel_builder, hyperparams, time_unit='')¶
- static __new__(cls, *args, **kwargs)¶
- conditional_mean(residuals, data_times, prediction_times, data_err, hp)¶
Conditional-mean GP prediction at
prediction_times.Conditions on observed residuals (already mean-subtracted by the deterministic model prediction) at
data_timeswith measurement noisedata_err, then returns the GP posterior mean evaluated atprediction_times. Used by the plotting layer to overlay structured noise; the same kernel and hyperparameter conventions asmodify_covariance()apply.All time arrays are assumed to be unit-stripped to the same unit (the kernel’s coordinate unit).
hpis the per-sample hyperparameter dict (e.g. from a single posterior sample).
- modify_covariance(cov, data, nl_values)¶
Add the GP kernel matrix
K(t, t')to the covariance.If the incoming covariance is diagonal (1-d), it is promoted to a full (n_obs, n_obs) matrix first.
- modify_design_matrix(X, data, nl_values)¶
Optionally append columns to the design matrix.
- Parameters:
- Return type:
- Returns:
Updated design matrix, shape
(n_obs, n_cols + n_extra). ReturnXunchanged if not applicable.
- class harv.models.extensions.Jitter¶
Bases:
AbstractExtensionAdd excess variance (jitter / white noise) to the observation covariance.
The extension declares one nonlinear parameter,
jitter, and modifies the covariance by addingjitter**2in quadrature to the diagonal variances. Thejitterunit must match the observation unit (e.g."km/s"for RV,"mas"for astrometry). Unit stripping is the model’s responsibility.- Parameters:
param_unit (
str) – Physical unit string for the jitter parameter metadata. Default""(dimensionless / observation units).
Examples
>>> from harv.models.extensions import Jitter >>> j = Jitter(param_unit="km/s") >>> j.extra_params()[0].unit 'km/s'
- static __new__(cls, *args, **kwargs)¶
- modify_covariance(cov, data, nl_values)¶
Add jitter**2 in quadrature to the diagonal variances.
Works on both 1-d (diagonal) and 2-d (full) covariance representations.
- modify_design_matrix(X, data, nl_values)¶
Optionally append columns to the design matrix.
- Parameters:
- Return type:
- Returns:
Updated design matrix, shape
(n_obs, n_cols + n_extra). ReturnXunchanged if not applicable.
- class harv.models.extensions.MonomialTrend¶
Bases:
AbstractExtensionAppend monomial trend columns to the design matrix.
Uses a standard monomial basis:
dt^1, dt^2, ..., dt^order(RV) or scan-angle-projected monomials (astrometry).- Parameters:
order (
int) – Polynomial order (number of trend terms). Must be >= 1.time_unit (
str) – Unit string for time – used inParamInfometadata.obs_unit (
str) – Unit string for the observations – used inParamInfometadata.astrometry (
bool) – IfTrue, add two columns per order (RA + Dec, projected by scan angle) with exponentsk + 1to avoid degeneracy with the base proper-motion columns. DefaultFalse(single column per order).
Examples
>>> from harv.models.extensions import MonomialTrend >>> trend = MonomialTrend(order=2) >>> [p.name for p in trend.extra_params()] ['trend_1', 'trend_2']
- __init__(order=1, time_unit='', obs_unit='', astrometry=False)¶
- static __new__(cls, *args, **kwargs)¶
- modify_covariance(cov, data, nl_values)¶
Optionally modify the data covariance matrix.
- Parameters:
cov (
Array) – Current covariance. Diagonal (1-d) when only measurement errors are present; full (2-d) after a GP extension adds off-diagonal structure. shape (n_obs,) or (n_obs, n_obs)data (
AbstractData|None) – Observation data.nl_values (
dict[str,Any]) – Current nonlinear parameter values (unit-stripped scalars).
- Return type:
- Returns:
Updated covariance (same or promoted shape). Return
covunchanged if not applicable.
- modify_design_matrix(X, data, nl_values)¶
Append trend columns to the design matrix.
- For RV (
astrometry=False): Columns are
(t - t_ref)^kfork = 1..order.- For Gaia astrometry (
astrometry=True): Two columns per order:
sin(psi) * dt^(k+1)andcos(psi) * dt^(k+1)wheredt = (t - t_ref)andpsiis the scan angle. The exponentk + 1avoids degeneracy with the base proper-motion (dt^1) columns.
The data object must have
timeandt_refattributes (andscan_anglefor astrometry mode).- For RV (
- class harv.models.extensions.MultiSurveyOffset¶
Bases:
AbstractExtensionPer-instrument additive offsets to account for instrumental systematics.
The extension stores a pre-computed indicator matrix and appends it as extra columns to the design matrix. Each column corresponds to a non-reference instrument; the reference instrument has no explicit offset (absorbed by the systemic velocity or baseline parameter).
- Parameters:
indicator_matrix (
Array) – Binary matrix:indicator_matrix[i, j] == 1iff observation i belongs to the j-th non-reference instrument.instrument_names (
tuple[str,...]) – Ordered names of the non-reference instruments (same column order asindicator_matrix). Used as parameter names.obs_unit (
str) – Physical unit string for the offset parameters (must match the observation unit of the model, e.g."km/s").
Examples
>>> import jax.numpy as jnp >>> from harv.models.extensions import MultiSurveyOffset >>> indicator = jnp.array([[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]]) >>> ext = MultiSurveyOffset(indicator, ("espresso", "keck"), "km/s") >>> [p.name for p in ext.extra_params()] ['espresso', 'keck']
- __init__(indicator_matrix, instrument_names, obs_unit='')¶
- static __new__(cls, *args, **kwargs)¶
- modify_covariance(cov, data, nl_values)¶
Optionally modify the data covariance matrix.
- Parameters:
cov (
Array) – Current covariance. Diagonal (1-d) when only measurement errors are present; full (2-d) after a GP extension adds off-diagonal structure. shape (n_obs,) or (n_obs, n_obs)data (
AbstractData|None) – Observation data.nl_values (
dict[str,Any]) – Current nonlinear parameter values (unit-stripped scalars).
- Return type:
- Returns:
Updated covariance (same or promoted shape). Return
covunchanged if not applicable.
- modify_design_matrix(X, data, nl_values)¶
Append indicator columns to the design matrix.
- class harv.models.extensions.ParamInfo¶
Bases:
ModuleImmutable descriptor for a single model parameter.
- Parameters:
name (
str) – Parameter name. Must not contain"."(reserved forJointModeltied-parameter paths).unit (
str) – Unit string (e.g."day","km/s",""for dimensionless).linear (
bool) – Whether the parameter enters the model linearly (defaultFalse).
Examples
>>> from harv.models.extensions.base import ParamInfo >>> p = ParamInfo("period", "time") >>> p.name 'period' >>> p.linear False
- __init__(name, unit, linear=False)¶
- static __new__(cls, *args, **kwargs)¶
Submodules¶
harv.models.extensions.base module¶
Parameter metadata and the abstract Extension base class.
This module defines:
ParamInfo: a frozen description of a single model parameter (name, unit / dimension (e.g., “km/s”), and role in a model (i.e., nonlinear vs linear)).AbstractExtension: the abstract base that all model extensions must subclass. Extensions can add parameters, modify the design matrix (e.g., polynomial trends, or instrumental offsets), and/or modify the data covariance (e.g., to add a Gaussian Process noise model).
- class harv.models.extensions.base.AbstractExtension¶
Bases:
ModuleAbstract base class for model extensions (jitter, trends, offsets, GP, …).
An extension can declare extra parameters (nonlinear and/or linear), modify the design matrix (e.g., append trend or offset columns), and/or modify the data covariance matrix (e.g., add jitter or a GP kernel).
Extensions are composed onto a
AbstractComponentModelat construction time via theextensionsfield. The model calls each hook in the order the extensions are listed.All extensions receive the raw (unit-stripped) JAX arrays. Unit handling is the model’s responsibility.
Subclasses must implement
extra_params(). The design-matrix and covariance hooks have default no-op implementations that return their input unchanged.Plot-specific behavior is handled privately by plotting helpers rather than through this base extension API.
- abstractmethod extra_params()¶
Parameters introduced by this extension.
- modify_design_matrix(X, data, nl_values)¶
Optionally append columns to the design matrix.
- Parameters:
- Return type:
- Returns:
Updated design matrix, shape
(n_obs, n_cols + n_extra). ReturnXunchanged if not applicable.
- modify_covariance(cov, data, nl_values)¶
Optionally modify the data covariance matrix.
- Parameters:
cov (
Array) – Current covariance. Diagonal (1-d) when only measurement errors are present; full (2-d) after a GP extension adds off-diagonal structure. shape (n_obs,) or (n_obs, n_obs)data (
AbstractData|None) – Observation data.nl_values (
dict[str,Any]) – Current nonlinear parameter values (unit-stripped scalars).
- Return type:
- Returns:
Updated covariance (same or promoted shape). Return
covunchanged if not applicable.
- __init__()¶
- Return type:
None
- class harv.models.extensions.base.ParamInfo¶
Bases:
ModuleImmutable descriptor for a single model parameter.
- Parameters:
name (
str) – Parameter name. Must not contain"."(reserved forJointModeltied-parameter paths).unit (
str) – Unit string (e.g."day","km/s",""for dimensionless).linear (
bool) – Whether the parameter enters the model linearly (defaultFalse).
Examples
>>> from harv.models.extensions.base import ParamInfo >>> p = ParamInfo("period", "time") >>> p.name 'period' >>> p.linear False
- __init__(name, unit, linear=False)¶
harv.models.extensions.gp module¶
Gaussian Processes (GP).
- final class harv.models.extensions.gp.GP¶
Bases:
AbstractExtensionGaussian Process covariance extension.
Adds the kernel matrix
K(t, t')to the observation covariance via themodify_covariancehook, allowing analytic marginalization of linear parameters in the presence of correlated noise.Plotting code may choose to visualize the GP contribution, but that support is handled privately on the plotting side rather than through the extension base API.
- Parameters:
kernel_builder (
Callable[[dict[str,Any]],Any]) – Receives the full nonlinear-parameter dict (unit-stripped) and returns a callable kernel object that can be called with(X, Xp)to produce the kernel matrix. For example, fromtinygp.hyperparams (
tuple[ParamInfo,...]) – Nonlinear hyperparameters declared by this extension (e.g.gp_amp,gp_length_scale). These are sampled alongside other nonlinear model parameters.time_unit (
str) – Unit to strip times to before building the coordinate array. Default""(dimensionless / already stripped).
Examples
>>> from harv.models.extensions.base import ParamInfo >>> from harv.models.extensions.gp import GP; GP( ... kernel_builder=lambda hp: hp["gp_amp"] ** 2, ... hyperparams=(ParamInfo("gp_amp", "km/s"),), ... time_unit="day", ... ).extra_params()[0].name 'gp_amp'
- modify_covariance(cov, data, nl_values)¶
Add the GP kernel matrix
K(t, t')to the covariance.If the incoming covariance is diagonal (1-d), it is promoted to a full (n_obs, n_obs) matrix first.
- conditional_mean(residuals, data_times, prediction_times, data_err, hp)¶
Conditional-mean GP prediction at
prediction_times.Conditions on observed residuals (already mean-subtracted by the deterministic model prediction) at
data_timeswith measurement noisedata_err, then returns the GP posterior mean evaluated atprediction_times. Used by the plotting layer to overlay structured noise; the same kernel and hyperparameter conventions asmodify_covariance()apply.All time arrays are assumed to be unit-stripped to the same unit (the kernel’s coordinate unit).
hpis the per-sample hyperparameter dict (e.g. from a single posterior sample).
- __init__(kernel_builder, hyperparams, time_unit='')¶
- static __new__(cls, *args, **kwargs)¶
- modify_design_matrix(X, data, nl_values)¶
Optionally append columns to the design matrix.
- Parameters:
- Return type:
- Returns:
Updated design matrix, shape
(n_obs, n_cols + n_extra). ReturnXunchanged if not applicable.
harv.models.extensions.jitter module¶
Jitter (excess variance).
Examples
>>> from harv.models.extensions import Jitter; [p.name for p in Jitter().extra_params()]
['jitter']
- final class harv.models.extensions.jitter.Jitter¶
Bases:
AbstractExtensionAdd excess variance (jitter / white noise) to the observation covariance.
The extension declares one nonlinear parameter,
jitter, and modifies the covariance by addingjitter**2in quadrature to the diagonal variances. Thejitterunit must match the observation unit (e.g."km/s"for RV,"mas"for astrometry). Unit stripping is the model’s responsibility.- Parameters:
param_unit (
str) – Physical unit string for the jitter parameter metadata. Default""(dimensionless / observation units).
Examples
>>> from harv.models.extensions import Jitter >>> j = Jitter(param_unit="km/s") >>> j.extra_params()[0].unit 'km/s'
- modify_covariance(cov, data, nl_values)¶
Add jitter**2 in quadrature to the diagonal variances.
Works on both 1-d (diagonal) and 2-d (full) covariance representations.
- static __new__(cls, *args, **kwargs)¶
- modify_design_matrix(X, data, nl_values)¶
Optionally append columns to the design matrix.
- Parameters:
- Return type:
- Returns:
Updated design matrix, shape
(n_obs, n_cols + n_extra). ReturnXunchanged if not applicable.
harv.models.extensions.multi_survey module¶
Multi-survey offsets.
- final class harv.models.extensions.multi_survey.MultiSurveyOffset¶
Bases:
AbstractExtensionPer-instrument additive offsets to account for instrumental systematics.
The extension stores a pre-computed indicator matrix and appends it as extra columns to the design matrix. Each column corresponds to a non-reference instrument; the reference instrument has no explicit offset (absorbed by the systemic velocity or baseline parameter).
- Parameters:
indicator_matrix (
Array) – Binary matrix:indicator_matrix[i, j] == 1iff observation i belongs to the j-th non-reference instrument.instrument_names (
tuple[str,...]) – Ordered names of the non-reference instruments (same column order asindicator_matrix). Used as parameter names.obs_unit (
str) – Physical unit string for the offset parameters (must match the observation unit of the model, e.g."km/s").
Examples
>>> import jax.numpy as jnp >>> from harv.models.extensions import MultiSurveyOffset >>> indicator = jnp.array([[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]]) >>> ext = MultiSurveyOffset(indicator, ("espresso", "keck"), "km/s") >>> [p.name for p in ext.extra_params()] ['espresso', 'keck']
- modify_design_matrix(X, data, nl_values)¶
Append indicator columns to the design matrix.
- __init__(indicator_matrix, instrument_names, obs_unit='')¶
- static __new__(cls, *args, **kwargs)¶
- modify_covariance(cov, data, nl_values)¶
Optionally modify the data covariance matrix.
- Parameters:
cov (
Array) – Current covariance. Diagonal (1-d) when only measurement errors are present; full (2-d) after a GP extension adds off-diagonal structure. shape (n_obs,) or (n_obs, n_obs)data (
AbstractData|None) – Observation data.nl_values (
dict[str,Any]) – Current nonlinear parameter values (unit-stripped scalars).
- Return type:
- Returns:
Updated covariance (same or promoted shape). Return
covunchanged if not applicable.
harv.models.extensions.trend module¶
Monomial polynomial trends.
- final class harv.models.extensions.trend.MonomialTrend¶
Bases:
AbstractExtensionAppend monomial trend columns to the design matrix.
Uses a standard monomial basis:
dt^1, dt^2, ..., dt^order(RV) or scan-angle-projected monomials (astrometry).- Parameters:
order (
int) – Polynomial order (number of trend terms). Must be >= 1.time_unit (
str) – Unit string for time – used inParamInfometadata.obs_unit (
str) – Unit string for the observations – used inParamInfometadata.astrometry (
bool) – IfTrue, add two columns per order (RA + Dec, projected by scan angle) with exponentsk + 1to avoid degeneracy with the base proper-motion columns. DefaultFalse(single column per order).
Examples
>>> from harv.models.extensions import MonomialTrend >>> trend = MonomialTrend(order=2) >>> [p.name for p in trend.extra_params()] ['trend_1', 'trend_2']
- modify_design_matrix(X, data, nl_values)¶
Append trend columns to the design matrix.
- For RV (
astrometry=False): Columns are
(t - t_ref)^kfork = 1..order.- For Gaia astrometry (
astrometry=True): Two columns per order:
sin(psi) * dt^(k+1)andcos(psi) * dt^(k+1)wheredt = (t - t_ref)andpsiis the scan angle. The exponentk + 1avoids degeneracy with the base proper-motion (dt^1) columns.
The data object must have
timeandt_refattributes (andscan_anglefor astrometry mode).- For RV (
- __init__(order=1, time_unit='', obs_unit='', astrometry=False)¶
- static __new__(cls, *args, **kwargs)¶
- modify_covariance(cov, data, nl_values)¶
Optionally modify the data covariance matrix.
- Parameters:
cov (
Array) – Current covariance. Diagonal (1-d) when only measurement errors are present; full (2-d) after a GP extension adds off-diagonal structure. shape (n_obs,) or (n_obs, n_obs)data (
AbstractData|None) – Observation data.nl_values (
dict[str,Any]) – Current nonlinear parameter values (unit-stripped scalars).
- Return type:
- Returns:
Updated covariance (same or promoted shape). Return
covunchanged if not applicable.