chronostar.component package#
Submodules#
chronostar.component.spacecomponent module#
- class chronostar.component.spacecomponent.SpaceComponent(params=None)#
Bases:
BaseComponentA 6D phase-space Gaussian component
Capable of fitting itself to a set of samples and responsibilities (membership probabilities)
- Parameters:
params (ndarray of shape (42), optional) – Model parameters, the mean and covariance of a 6D Gaussian, flattened into a 1D array like so:
np.hstack((mean, covariance.flatten()))
- reg_covar#
A regularisation constant added to the diagonals of the covariance matrix, configurable
- Type:
float, default 1.e-6
- nthreads#
Number of OMP threads used by numpy matrix operations
- Type:
int, default None
- property covariance: ndarray[Any, dtype[float64]]#
Get the covariance, as encoded in internal parameters
- Returns:
The central covariance of the parameterised 6D Gaussian
- Return type:
NDArray[float64] of shape(6, 6)
- estimate_log_prob(X)#
Calculate the log probability of each sample given this component
- Parameters:
X (ndarray of shape (n_samples, n_features)) – Input data
- Returns:
The multivariate normal defined by self.mean and self.covariance evaluated at each point in X
- Return type:
NDArray[float64] of shape (n_samples)
- get_parameters()#
Get the internal parameters of the model
- Returns:
mean, covariance
- Return type:
(n_features), (n_features, n_features)
- maximize(X, resp)#
Find the best model parameters for the data and stores them in
self.parameters.You may access the parameters via the properties
meanandcovariance.- Parameters:
X (ndarray of shape (n_samples, n_features)) – Input data
resp (ndarray of shape (n_samples)) – component responsibilities (membership probabilities)
Notes
This method relies heavily on functions written by scikit-learn.
- Return type:
None
- property mean: ndarray[Any, dtype[float64]]#
Get the mean, as encoded in internal parameters
- Returns:
The central mean of the parameterised 6D Gaussian
- Return type:
NDArray[float64] of shape(6)
- property n_params: int#
Return the number of parameters required to define this model
- Returns:
The number of parameters required to define this model
- Return type:
int
- set_parameters(params)#
Set the internal parameters of the model.
- Parameters:
params ((n_features), (n_features, n_features)) – mean, covariance
- Return type:
None
- split()#
Split this component into two new comps along the largest phase-space dimension
This method finds the primary axis (i.e. largest eigen vector) and generates two components with means offset in either direction of the primary axis.
The two new covariances are shrunk in the direction of the primary axis such that the two new ellipsoids formed by one standard deviation span the original ellipsoid formed by one standard deviation.
- Returns:
Two new components with offset mean and shrunken covariance
- Return type:
tuple[SpaceComponent, SpaceComponent]
chronostar.component.spherespacetimecomponent module#
- class chronostar.component.spherespacetimecomponent.SphereSpaceTimeComponent(params=None)#
Bases:
BaseComponentA 6D phase-space Gaussian component with age.
Capable of fitting itself to a set of samples and responsibilities (membership probabilities)
- Parameters:
params (ndarray of shape (9), optional) – Model parameters parameterising the modeled spherical birth site of the component and its age flattened into a 1D array like so:
np.hstack((mean, dxyz, duvw, age))
- reg_covar#
A regularisation constant added to the diagonals of the covariance matrix, configurable
- Type:
float, default 1.e-6
- minimize_method#
The method used by
scipy.optimize.minimize. Must be one of‘Nelder-Mead’ (recommended)
‘Powell’ (not receommended)
- Type:
str, default ‘Nelder-Mead’
- nthreads#
Manually restrict how many threads openMP tries to use when executing optimized numpy functions, configurable
- Type:
int, optional
- trace_orbit_func#
A function that traces a position by time Myr. Positive time traces forward, negative time backwards, configurable
- Type:
Callable f(start_loc, time), default
trace_epicyclic_orbit()
- age_offset_interval#
After how many calls to
maximize()age offsets should be explored- Type:
int, default 20
- stellar_uncertainties#
Whether data covariance matrices are encoded in final 36 columns of input data X
- Type:
bool, default True
- resp_tol#
Only samples with a responsibility (membership probability) greater than
resp_tolwill be included in the evaluation of the loss function- Type:
float, default 1e-6
- parameters#
The model parameters, either as set by initialization, or as determined by
maximize(). For this component this parameters are: [x, y, z, u, v, w, dxyz, duvw, age] with position in pc, velocity in km/s and age in Myr- Type:
ndarray of shape (9)
- max_age#
The upper bound on the age when maximising the component parameters
- Type:
float, default 200
- property age: float#
Get the age of the component
- Returns:
The age of the component
- Return type:
float
- classmethod configure(**kwargs)#
Set any configurable class attributes
- cov_lnpriors(cov_params)#
Apply priors to covariance parameters
For now, just a simple hard edge for negative standard deviations.
Currently this should rarely be reached since the optimize routine should respect the bounds as set by
get_parameter_bounds()- Parameters:
cov_params (NDArray of shape (2)) – The spherical standard deviations of position and velocity
- Returns:
If standard deviations are negative, returns -np.inf, otherwise 0.
- Return type:
float
- property covariance: ndarray[Any, dtype[float64]]#
Get the current day covariance of the component
- Returns:
The covariance of the component
- Return type:
ndarray of shape(6, 6)
- estimate_log_prob(X)#
Calculate the log probability of each sample given this component
- Parameters:
X (ndarray of shape (n_samples, n_features)) – Input data
- Returns:
The multivariate normal defined by self.mean and self.covariance evaluated at each point in X
- Return type:
NDArray[float64] of shape (n_samples)
- get_parameter_bounds()#
Generate a set of parameter bounds for scipy.optimize
- Returns:
A set of bounds to be used in
scipy.optimize.minimize()- Return type:
optimize.Bounds
- get_parameters()#
Get the internal parameters of the model
- Returns:
mean, covariance, age
- Return type:
(n_features), (n_features, n_features), float
- loss(model_params, X, resp)#
Calculate the loss (i.e. -log likelihood) of the data.
- Parameters:
model_params (ndarray of shape (9)) – Values that parameterise the birth mean, birth covariance matrix and age
X (ndarray of shape (n_samples, n_features)) – Input data
resp (ndarray of shape (n_samples)) – component responsibilities (membership probabilities)
- Returns:
Negative log likelihood of data given age and derived model parameters.
- Return type:
float
- maximize(X, resp)#
Find the best model parameters for the data
Performs a minimization on
loss()to find the best parameters. To account for local minima caused by the Z-W phase / age degeneracy, every self.age_offset_interval calls we perform 5 minimizations with age offset by -20., +0., +20., +40. and +80. These offsets appear to guarantee successful fits up to 200 Myr.- Parameters:
X (ndarray of shape (n_samples, n_features)) – Input data
resp (ndarray of shape (n_samples)) – component responsibilities (membership probabilities)
Note
We achieve a significant performance boost by beginning a minimiztion at the location of the component’s current best fitting parameters.
- Return type:
None
- property mean: ndarray[Any, dtype[float64]]#
Get the current day mean of the component
- Returns:
The central mean of the component
- Return type:
ndarray of shape(6)
- property n_params: int#
Return the number of parameters required to define this model
- Returns:
The number of parameters required to define this model
- Return type:
int
- set_parameters(params)#
Set the internal parameters of the model.
- Parameters:
params ((n_features), (n_features, n_features), float) – mean, covariance, age
- Return type:
None
- split()#
Split the component along its primary phase-space axis
Similar to
SpaceComponent.split(), however it is non-trivial to adjust covariance matrices which were transformed from birth-sites, so we don’t bother.- Returns:
Two components with identical parameters as self but with current-day means offset in either direction of the primary axis
- Return type:
- static trace_orbit_func(xyzuvw_start, time=None, sA=0.89, sB=1.15, sR=1.21, ro=8.0, vo=220.0)#
- Noindex:
- chronostar.component.spherespacetimecomponent.construct_cov_from_params(cov_params)#
Construct a covariance matrix from given parameters
This implementation is a spherical covariance, with a uniform standard deviation in position, and a uniform standard devaition in velocity
- Parameters:
cov_params (NDArray[float64] of shape(2)) – The standard deviations in position and velocity: (dxyz, duvw)
- Returns:
A spherical covariance matrix
- Return type:
NDArray[float64] of shape(6, 6)
- chronostar.component.spherespacetimecomponent.construct_params_from_cov(covariance)#
Derives spherical parameters from an arbitrary covariance matrix
This implementation takes the volume of the covariance matrix in position (an ellipsoid whose axes’ half-lengths are the square root of the matrix’s eigen values) and finds the equivalent radius of a sphere with equal volume.
An identical approach is taken for velocity.
- Parameters:
covariance (NDArray[float64] of shape(6, 6)) – A covariance matrix (can be full)
- Returns:
The standard deviations in space and velocity: (dxyz, duvw)
- Return type:
NDArray[float64] of shape(2)