regressproxy¶
Proxy model classes for regression analysis
This module contains regression proxy models with lag and finite lifetime.
regressproxy.models_cel¶
Proxy classes for regression analysis (celerite version)
Proxy model classes for regression analysis using the
celerite.modeling
modelling protocol [1].
[1] | https://celerite.readthedocs.io/en/stable/python/modeling/ |
-
class
regressproxy.models_cel.
ConstantModel
(*args, **kwargs)[source]¶ Bases:
Model
A simple concrete model with a single parameter
value
Parameters: value (float) – The value of the model.
Attributes: full_size
The total number of parameters (including frozen parameters)
parameter_vector
An array of all parameters (including frozen parameters)
vector_size
The number of active (or unfrozen) parameters
Methods
compute_gradient
(x)Compute the "gradient" of the model for the current parameters freeze_all_parameters
()Freeze all parameters of the model freeze_parameter
(name)Freeze a parameter by name get_parameter
(name)Get a parameter value by name get_parameter_bounds
([include_frozen])Get a list of the parameter bounds get_parameter_dict
([include_frozen])Get an ordered dictionary of the parameters get_parameter_names
([include_frozen])Get a list of the parameter names get_parameter_vector
([include_frozen])Get an array of the parameter values in the correct order get_value
(x)Compute the "value" of the model for the current parameters log_prior
()Compute the log prior probability of the current parameters set_parameter
(name, value)Set a parameter value by name set_parameter_vector
(vector[, include_frozen])Set the parameter values to the given vector thaw_all_parameters
()Thaw all parameters of the model thaw_parameter
(name)Thaw a parameter by name get_gradient -
compute_gradient
(x)[source]¶ Compute the “gradient” of the model for the current parameters
This method should be overloaded by subclasses to implement the actual functionality of the model. The output of this function should be an array where the first dimension is
full_size
.
-
get_value
(x)[source]¶ Compute the “value” of the model for the current parameters
This method should be overloaded by subclasses to implement the actual functionality of the model.
-
parameter_names
= ('value',)¶
-
class
regressproxy.models_cel.
HarmonicModelAmpPhase
(*args, **kwargs)[source]¶ Bases:
Model
Model for harmonic terms
Models a harmonic term using amplitude and phase of a sine. It hase the same phase as returned by
HarmonicModelCosineSine.get_phase()
.Parameters: See also
Attributes: full_size
The total number of parameters (including frozen parameters)
parameter_vector
An array of all parameters (including frozen parameters)
vector_size
The number of active (or unfrozen) parameters
Methods
compute_gradient
(t)Compute the "gradient" of the model for the current parameters freeze_all_parameters
()Freeze all parameters of the model freeze_parameter
(name)Freeze a parameter by name get_parameter
(name)Get a parameter value by name get_parameter_bounds
([include_frozen])Get a list of the parameter bounds get_parameter_dict
([include_frozen])Get an ordered dictionary of the parameters get_parameter_names
([include_frozen])Get a list of the parameter names get_parameter_vector
([include_frozen])Get an array of the parameter values in the correct order get_value
(t)Compute the "value" of the model for the current parameters log_prior
()Compute the log prior probability of the current parameters set_parameter
(name, value)Set a parameter value by name set_parameter_vector
(vector[, include_frozen])Set the parameter values to the given vector thaw_all_parameters
()Thaw all parameters of the model thaw_parameter
(name)Thaw a parameter by name get_amplitude get_gradient get_phase -
compute_gradient
(t)[source]¶ Compute the “gradient” of the model for the current parameters
This method should be overloaded by subclasses to implement the actual functionality of the model. The output of this function should be an array where the first dimension is
full_size
.
-
get_value
(t)[source]¶ Compute the “value” of the model for the current parameters
This method should be overloaded by subclasses to implement the actual functionality of the model.
-
parameter_names
= ('freq', 'amp', 'phase')¶
-
class
regressproxy.models_cel.
HarmonicModelCosineSine
(*args, **kwargs)[source]¶ Bases:
Model
Model for harmonic terms
Models a harmonic term using a cosine and sine part. The amplitude and phase returned are that for a sine function, i.e. amplitude * sin(t + phase).
Parameters: See also
Attributes: full_size
The total number of parameters (including frozen parameters)
parameter_vector
An array of all parameters (including frozen parameters)
vector_size
The number of active (or unfrozen) parameters
Methods
compute_gradient
(t)Compute the "gradient" of the model for the current parameters freeze_all_parameters
()Freeze all parameters of the model freeze_parameter
(name)Freeze a parameter by name get_parameter
(name)Get a parameter value by name get_parameter_bounds
([include_frozen])Get a list of the parameter bounds get_parameter_dict
([include_frozen])Get an ordered dictionary of the parameters get_parameter_names
([include_frozen])Get a list of the parameter names get_parameter_vector
([include_frozen])Get an array of the parameter values in the correct order get_value
(t)Compute the "value" of the model for the current parameters log_prior
()Compute the log prior probability of the current parameters set_parameter
(name, value)Set a parameter value by name set_parameter_vector
(vector[, include_frozen])Set the parameter values to the given vector thaw_all_parameters
()Thaw all parameters of the model thaw_parameter
(name)Thaw a parameter by name get_amplitude get_gradient get_phase -
compute_gradient
(t)[source]¶ Compute the “gradient” of the model for the current parameters
This method should be overloaded by subclasses to implement the actual functionality of the model. The output of this function should be an array where the first dimension is
full_size
.
-
get_value
(t)[source]¶ Compute the “value” of the model for the current parameters
This method should be overloaded by subclasses to implement the actual functionality of the model.
-
parameter_names
= ('freq', 'cos', 'sin')¶
-
class
regressproxy.models_cel.
ProxyModel
(proxy_times, proxy_vals, center=False, phi_intp=None, fit_phase=False, lifetime_prior=None, lifetime_metric=1.0, days_per_time_unit=365.25, *args, **kwargs)[source]¶ Bases:
Model
Model for proxy terms
Models proxy terms with a finite and (semi-)annually varying life time.
Parameters: - proxy_times ((N,) array_like) – The times of the proxy values according to
days_per_time_unit
. - proxy_vals ((N,) array_like) – The proxy values at proxy_times.
- amp (float) – The amplitude of the proxy term.
- lag (float) – The lag of the proxy value (in days, see
days_per_time_unit
). - tau0 (float) – The base life time of the proxy (in days, see
days_per_time_unit
). - taucos1 (float) – The amplitude of the cosine part of the annual life time variation
(in days, see
days_per_time_unit
). - tausin1 (float) – The amplitude of the sine part of the annual life time variation
(in days, see
days_per_time_unit
). - taucos2 (float) – The amplitude of the cosine part of the semi-annual life time variation
(in days, see
days_per_time_unit
). - tausin2 (float) – The amplitude of the sine part of the semi-annual life time variation
(in days, see
days_per_time_unit
). - ltscan (float) – The number of days to sum the previous proxy values. If it is negative, the value will be set to three times the maximal lifetime. No lifetime adjustemets are calculated when set to zero.
- center (bool, optional) – Centers the proxy values by subtracting the overall mean. The mean is calculated from the whole proxy_vals array and is stored in the mean attribute. Default: False
- phi_intp (scipy.interpolate.interp1d() instance, optional) – When not None, the interpolated angle phi (e.g. SZA) and cos(phi) and sin(phi) are used to model the variation of the lifetime instead of the time. Semi-annual variations are not used in this case. Default: None
- fit_phase (bool, optional) – Fit the phase shift directly instead of using sine and cosine terms for the (semi-)annual lifetime variations. If True, the fitted cosine parameter is the amplitude and the sine parameter the phase. Default: False (= fit sine and cosine terms)
- lifetime_prior (str, optional) – The prior probability density for each coefficient of the lifetime. Possible types are “flat” or None for a flat prior, “exp” for an exponential density ~ \(\text{exp}(-|\tau| / \text{metric})\), and “normal” for a normal distribution ~ \(\text{exp}(-\tau^2 / (2 * \text{metric}^2))\). Default: None (= flat prior).
- lifetime_metric (float, optional) – The metric (scale) of the lifetime priors in days, see prior. Default 1.
- days_per_time_unit (float, optional) – The number of days per time unit, used to normalize the lifetime units. Use 365.25 if the times are in fractional years, or 1 if they are in days. Default: 365.25
Attributes: full_size
The total number of parameters (including frozen parameters)
parameter_vector
An array of all parameters (including frozen parameters)
vector_size
The number of active (or unfrozen) parameters
Methods
compute_gradient
(t)Compute the "gradient" of the model for the current parameters freeze_all_parameters
()Freeze all parameters of the model freeze_parameter
(name)Freeze a parameter by name get_parameter
(name)Get a parameter value by name get_parameter_bounds
([include_frozen])Get a list of the parameter bounds get_parameter_dict
([include_frozen])Get an ordered dictionary of the parameters get_parameter_names
([include_frozen])Get a list of the parameter names get_parameter_vector
([include_frozen])Get an array of the parameter values in the correct order get_value
(t)Compute the "value" of the model for the current parameters log_prior
()Compute the log prior probability of the current parameters set_parameter
(name, value)Set a parameter value by name set_parameter_vector
(vector[, include_frozen])Set the parameter values to the given vector thaw_all_parameters
()Thaw all parameters of the model thaw_parameter
(name)Thaw a parameter by name get_gradient -
compute_gradient
(t)[source]¶ Compute the “gradient” of the model for the current parameters
This method should be overloaded by subclasses to implement the actual functionality of the model. The output of this function should be an array where the first dimension is
full_size
.
-
get_value
(t)[source]¶ Compute the “value” of the model for the current parameters
This method should be overloaded by subclasses to implement the actual functionality of the model.
-
parameter_names
= ('amp', 'lag', 'tau0', 'taucos1', 'tausin1', 'taucos2', 'tausin2', 'ltscan')¶
- proxy_times ((N,) array_like) – The times of the proxy values according to
-
class
regressproxy.models_cel.
ProxyModelSet
(models)[source]¶ Bases:
ModelSet
Combined model class for, e.g. trace gases (and probably other data)
Inherited from
celerite.ModelSet
, provides get_value() and compute_gradient() methods.Attributes: - dirty
full_size
The total number of parameters (including frozen parameters)
- parameter_bounds
- parameter_names
parameter_vector
An array of all parameters (including frozen parameters)
- unfrozen_mask
vector_size
The number of active (or unfrozen) parameters
Methods
compute_gradient
(t)Compute the "gradient" of the model for the current parameters freeze_all_parameters
()Freeze all parameters of the model freeze_parameter
(name)Freeze a parameter by name get_parameter
(name)Get a parameter value by name get_parameter_bounds
([include_frozen])Get a list of the parameter bounds get_parameter_dict
([include_frozen])Get an ordered dictionary of the parameters get_parameter_names
([include_frozen])Get a list of the parameter names get_parameter_vector
([include_frozen])Get an array of the parameter values in the correct order get_value
(t)Compute the "value" of the model for the current parameters log_prior
()Compute the log prior probability of the current parameters set_parameter
(name, value)Set a parameter value by name set_parameter_vector
(vector[, include_frozen])Set the parameter values to the given vector thaw_all_parameters
()Thaw all parameters of the model thaw_parameter
(name)Thaw a parameter by name get_gradient
-
regressproxy.models_cel.
proxy_model_set
(constant=True, freqs=None, proxy_config=None, **kwargs)[source]¶ Model set including proxies and harmonics
Sets up a proxy model for easy access. All parameters are optional, defaults to an offset, no harmonics, proxies uncentered and unscaled.
Parameters: - constant (bool, optional) – Whether or not to include a constant (offset) term, default is True.
- freqs (list, optional) – Frequencies of the harmonic terms in 1 / a^-1 (inverse years).
- proxy_config (dict, optional) – Proxy configuration if different from the standard setup.
- **kwargs (optional) –
Additional keyword arguments, all of them are also passed on to the proxy setup. For now, supported are the following which are also passed along to the proxy setup with setup_proxy_model_with_bounds():
- fit_phasebool
- fit amplitude and phase instead of sine and cosine
- scalefloat
- the factor by which the data is scaled, used to constrain the maximum and minimum amplitudes to be fitted.
- time_formatstring
- The astropy.time.Time format string to setup the time axis.
- days_per_time_unitfloat
- The number of days per time unit, used to normalize the frequencies for the harmonic terms. Use 365.25 if the times are in fractional years, 1 if they are in days. Default: 365.25
- max_ampfloat
- Maximum magnitude of the coefficients, used to constrain the parameter search.
- max_daysfloat
- Maximum magnitude of the lifetimes, used to constrain the parameter search.
Returns: model
Return type: ProxyModelSet
(extendscelerite.ModelSet
)
regressproxy.models_pymc3¶
Proxy classes for regression analysis (pymc3/theano version)
Model classes for data regression proxies using
theano
for pymc3
.
This interface is still experimental, it is available
when installing the pymc3
(or theano
) extra:
pip install "regressproxy[pymc3]"
The classes can be imported as usual, e.g. via:
from regressproxy.models_pymc3 import ProxyModel
-
class
regressproxy.models_pymc3.
HarmonicModelAmpPhase
(freq, amp, phase)[source]¶ Bases:
object
Model for harmonic terms
Models harmonic terms using amplitude and phase of a sine.
Parameters: See also
Methods
compute_gradient get_amplitude get_phase get_value
-
class
regressproxy.models_pymc3.
HarmonicModelCosineSine
(freq, cos, sin)[source]¶ Bases:
object
Model for harmonic terms
Models a harmonic term using a cosine and sine part. The amplitude and phase returned are that for a sine function, i.e. amplitude * sin(t + phase).
Parameters: See also
Methods
compute_gradient get_amplitude get_phase get_value
-
class
regressproxy.models_pymc3.
LifetimeModel
(harmonics, lower=0.0)[source]¶ Bases:
object
Model for variable lifetime
Returns the positive values of the sine/cosine.
Parameters: harmonics (HarmonicModelCosineSine or HarmonicModelAmpPhase or list) – Methods
get_value
-
class
regressproxy.models_pymc3.
ProxyModel
(ptimes, pvalues, amp, lag=0.0, tau0=0.0, tau_harm=None, tau_scan=0, days_per_time_unit=365.25)[source]¶ Bases:
object
Model for proxy terms
Models proxy terms with a finite and (semi-)annually varying life time.
Parameters: - proxy_times ((N,) array_like) – The times of the proxy values according to
days_per_time_unit
. - proxy_vals ((N,) array_like) – The proxy values at proxy_times.
- amp (float) – The amplitude of the proxy term.
- lag (float, optional) – The lag of the proxy value (in days, see
days_per_time_unit
). - tau0 (float, optional) – The base life time of the proxy (in days, see
days_per_time_unit
). - tau_harm (LifetimeModel, optional) – The lifetime harmonic model with a lower limit.
- tau_scan (float, optional) – The number of days to sum the previous proxy values. If it is negative, the value will be set to three times the maximal lifetime. No lifetime adjustemets are calculated when set to zero.
- days_per_time_unit (float, optional) – The number of days per time unit, used to normalize the lifetime units. Use 365.25 if the times are in fractional years, or 1 if they are in days. Default: 365.25
Methods
get_value - proxy_times ((N,) array_like) – The times of the proxy values according to
-
regressproxy.models_pymc3.
proxy_model_set
(constant=True, freqs=None, proxy_config=None, **kwargs)[source]¶ Model set including proxies and harmonics
Sets up a proxy model for easy access. All parameters are optional, defaults to an offset, no harmonics, proxies uncentered and unscaled.
Parameters: - constant (bool, optional) – Whether or not to include a constant (offset) term, default is True.
- freqs (list, optional) – Frequencies of the harmonic terms in 1 / a^-1 (inverse years).
- proxy_config (dict, optional) – Proxy configuration if different from the standard setup.
- **kwargs (optional) –
Additional keyword arguments, all of them are also passed on to the proxy setup. For now, supported are the following which are also passed along to the proxy setup with setup_proxy_model_with_bounds():
- fit_phasebool
- fit amplitude and phase instead of sine and cosine
- scalefloat
- the factor by which the data is scaled, used to constrain the maximum and minimum amplitudes to be fitted.
- time_formatstring
- The astropy.time.Time format string to setup the time axis.
- days_per_time_unitfloat
- The number of days per time unit, used to normalize the frequencies for the harmonic terms. Use 365.25 if the times are in fractional years, 1 if they are in days. Default: 365.25
- max_ampfloat
- Maximum magnitude of the coefficients, used to constrain the parameter search.
- max_daysfloat
- Maximum magnitude of the lifetimes, used to constrain the parameter search.
- model_kwargsdict
- Keyword arguments passed to
pymc.Model()
, e.g.name
orcoords
.
Returns: model, ModelSet, offset – The
pymc3.model.Model
containing the random variables, theModelSet
with entries of typeProxyModel
as defined byproxy_config
. The offset is included to keep it similar to thecelerite
model setup.Return type: See also
regressproxy.models_pymc4¶
Proxy classes for regression analysis (pymc4/5 version)
Model classes for data regression proxies for use with
pymc
versions 4 and 5.
This interface is still experimental, it is available
when installing either the pymc4
or pymc5
extra:
pip install "regressproxy[pymc4]"
Due to dependency reasons, versions 4 and 5 are not supported together. The classes can be imported as usual, e.g. via:
from regressproxy.models_pymc4 import ProxyModel
-
class
regressproxy.models_pymc4.
HarmonicModelAmpPhase
(freq, amp, phase)[source]¶ Bases:
object
Model for harmonic terms
Models harmonic terms using amplitude and phase of a sine.
Parameters: Methods
compute_gradient get_amplitude get_phase get_value
-
class
regressproxy.models_pymc4.
HarmonicModelCosineSine
(freq, cos, sin)[source]¶ Bases:
object
Model for harmonic terms
Models harmonic terms using a cosine and sine part. The total amplitude and phase can be inferred from that.
Parameters: Methods
compute_gradient get_amplitude get_phase get_value
-
class
regressproxy.models_pymc4.
LifetimeModel
(harmonics, lower=0.0)[source]¶ Bases:
object
Model for variable lifetime
Returns the positive values of the sine/cosine.
Parameters: harmonics (HarmonicModelCosineSine or HarmonicModelAmpPhase or list) – Methods
get_value
-
class
regressproxy.models_pymc4.
ProxyModel
(ptimes, pvalues, amp, lag=0.0, tau0=0.0, tau_harm=None, tau_scan=0, days_per_time_unit=365.25)[source]¶ Bases:
object
Model for proxy terms
Models proxy terms with a finite and (semi-)annually varying life time.
Parameters: - proxy_times ((N,) array_like) – The times of the proxy values according to
days_per_time_unit
. - proxy_vals ((N,) array_like) – The proxy values at proxy_times
- amp (float) – The amplitude of the proxy term
- lag (float, optional) – The lag of the proxy value (in days, see
days_per_time_unit
). - tau0 (float, optional) – The base life time of the proxy (in days, see
days_per_time_unit
). - tau_harm (LifetimeModel, optional) – The lifetime harmonic model with a lower limit.
- tau_scan (float, optional) – The number of days to sum the previous proxy values. If it is negative, the value will be set to three times the maximal lifetime. No lifetime adjustemets are calculated when set to zero.
- days_per_time_unit (float, optional) – The number of days per time unit, used to normalize the lifetime units. Use 365.25 if the times are in fractional years, or 1 if they are in days. Default: 365.25
Methods
get_value - proxy_times ((N,) array_like) – The times of the proxy values according to
-
regressproxy.models_pymc4.
proxy_model_set
(constant=True, freqs=None, proxy_config=None, **kwargs)[source]¶ Model set including proxies and harmonics
Sets up a proxy model for easy access. All parameters are optional, defaults to an offset, no harmonics, proxies uncentered and unscaled.
Parameters: - constant (bool, optional) – Whether or not to include a constant (offset) term, default is True.
- freqs (list, optional) – Frequencies of the harmonic terms in 1 / a^-1 (inverse years).
- proxy_config (dict, optional) – Proxy configuration if different from the standard setup.
- **kwargs (optional) –
Additional keyword arguments, all of them are also passed on to the proxy setup. For now, supported are the following which are also passed along to the proxy setup with setup_proxy_model_with_bounds():
- fit_phasebool
- fit amplitude and phase instead of sine and cosine
- scalefloat
- the factor by which the data is scaled, used to constrain the maximum and minimum amplitudes to be fitted.
- time_formatstring
- The astropy.time.Time format string to setup the time axis.
- days_per_time_unitfloat
- The number of days per time unit, used to normalize the frequencies for the harmonic terms. Use 365.25 if the times are in fractional years, 1 if they are in days. Default: 365.25
- max_ampfloat
- Maximum magnitude of the coefficients, used to constrain the parameter search.
- max_daysfloat
- Maximum magnitude of the lifetimes, used to constrain the parameter search.
- model_kwargsdict
- Keyword arguments passed to
pymc.Model()
, e.g.name
orcoords
.
Returns: model, ModelSet, offset – The
pymc.Model
containing the random variables, theModelSet
with entries of typeProxyModel
as defined byproxy_config
. The offset is included to keep it similar to thecelerite
model setup.Return type: See also