General extrapolation/interpolation models (models)#
Classes:
|
Base class to define a sympy function for user defined derivatives. |
|
Create list-like of python functions from list-like of expressions. |
|
Base class for working with recursive derivatives in expansions. |
Class to compute derivatives of Y = -log(<X>). |
|
|
Class to wrap functions calculating derivatives to specified order. |
|
Apply taylor series extrapolation. |
|
Sequence of models. |
|
Provide methods for Piecewise state collection. |
|
Weighted extrapolation model. |
|
Interpolation model. |
|
Apposed to the multiple model InterpModel, perform a piecewise interpolation. |
|
Perturbation model. |
|
Sadly, this doesn't work as beautifully. |
Functions:
Create lambdified version of |
|
|
|
|
Minkowski weights DataArray. |
- class thermoextrap.models.SymFuncBase(beta)[source]#
Bases:
FunctionBase class to define a sympy function for user defined derivatives.
See also
Methods:
Symbol arguments of function.
fdiff([argindex])Derivative of function.
doit([deep])Generic
doitmethod (Seedoit()).eval(beta)Evaluate function.
tcall(beta)Typed interface to cls(...)
- classmethod deriv_args()[source]#
Symbol arguments of function.
This is used by Data class to create a ‘lambdfied’ callable function.
See also
- fdiff(argindex=1)[source]#
Derivative of function. This will be used by
thermoextrap.models.SymDerivBase.
- class thermoextrap.models.Lambdify(exprs, args, *, lambdify_kws=NOTHING)[source]#
Bases:
objectCreate list-like of python functions from list-like of expressions.
- Parameters:
See also
- class thermoextrap.models.SymDerivBase(func, args=None, expand=True, post_func=None, beta=None)[source]#
Bases:
objectBase class for working with recursive derivatives in expansions.
- Parameters:
func (
Function) – Function to differentiate. This should (most likely) be an instance ofthermoextrap.models.SymFuncBasepost_func (
strorcallable()) – Transformation of base function. For example, post_fuc = -sympy.log is equivalent to passing minus_log=True If a string, then apply the following standard functionsminus_log : post_func = -sympy.log
pow_i : post_func = lambda f: pow(f, i). E.g., pow_2 => pow(f, 2)
Methods:
- class thermoextrap.models.SymMinusLog[source]#
Bases:
objectClass to compute derivatives of Y = -log(<X>).
- thermoextrap.models.factory_minus_log()[source]#
Create lambdified version of
SymMinusLog
- class thermoextrap.models.Derivatives(funcs, *, exprs=None, args=None)[source]#
Bases:
MyAttrsMixinClass to wrap functions calculating derivatives to specified order.
- Parameters:
funcs (sequence of
callable()) –funcs[i](*args)gives the ith derivativeexprs (sequence of
Expr, optional) – expressions corresponding to the funcs Mostly for debugging purposes.
Attributes:
Methods:
derivs(data, *[, order, minus_log, ...])Calculate derivatives for orders range(0, order+1).
coefs(data, *[, order, minus_log, order_dim])Alias to self.derivs(..., norm=True).
from_sympy(exprs, args)Create object from list of sympy functions.
- funcs#
Sequence of callable functions
- exprs#
Sequence of sympy expressions, optional
- args#
Arguments
- derivs(data, *, order=None, minus_log=False, order_dim='order', concat_kws=None, norm=False)[source]#
Calculate derivatives for orders range(0, order+1).
- Parameters:
data (
object) – Data object. If passed, use args=data.deriv_argsorder (
int, optional) – If pass data and order is None, then order=data.order Otherwise, must mass orderminus_log (
bool, defaultFalse) – If True, apply transform for Y = -log(<X>)order_dim (
str, default'order') – If None, output will be a list If order_dim is a string, then apply xarray.concat to output To yield a single DataArrayconcat_kws (
dict, optional) – extra arguments to xarray.concatnorm (
bool, defaultFalse) – If true, then normalize derivatives by 1/n!, where n is the order of the derivative. That is, transform derivatives to taylor series coefficients See also taylor_series_norm
- Returns:
output (
listofxarray.DataArray) – See above for nature of output
- thermoextrap.models.taylor_series_norm(order, order_dim='order')[source]#
taylor_series_coefficients = derivs * taylor_series_norm.
- class thermoextrap.models.ExtrapModel(alpha0, data, derivatives, order=None, *, minus_log=False, alpha_name='alpha')[source]#
Bases:
MyAttrsMixin,Generic[DataT]Apply taylor series extrapolation.
Attributes:
Data object
Derivatives object
Whether to apply X <- -log(X).
Name of alpha
Methods:
__call__(*args, **kwargs)Call self as a function.
predict(alpha, *[, order, order_dim, ...])Calculate taylor series at values "alpha".
resample(sampler, **kws)Create new object with resampled data.
- data#
Data object
- derivatives#
Derivatives object
- minus_log#
Whether to apply X <- -log(X).
- alpha_name#
Name of alpha
- predict(alpha, *, order=None, order_dim='order', cumsum=False, no_sum=False, minus_log=None, alpha_name=None, dalpha_coords='dalpha', alpha0_coords=True)[source]#
Calculate taylor series at values “alpha”.
- Parameters:
alpha (
floator sequence ofDataArray) – Value of alpha to evaluate expansion at.order (
int, optional) – Optional order to perform expansion to.order_dim (
str, default"order") – Name of dimension for new order dimension, if created.cumsum (
bool, defaultFalse) – If True, perform a cumsum on output for all orders. Otherwise, to total sum.no_sum (
bool, defaultFalse) – If True, do not sum the results. Useful if manually performing any math with series.minus_log (
bool, defaultFalse) – If True, transform expansion toY = - log(X).alpha_name (
str, optional) – Name to apply to created alpha dimension.dalpha_coords (
str, default"dalpha") – Name of coordinatedalpha = alpha - alpha0.alpha0_coords (
strorbool, defaultTrue) – If True, addalpha_name+ “0” to the coordinates of the results. Ifstr, use this as the alpha0 coordinate names.
- Returns:
- class thermoextrap.models.StateCollection(states, *, kws=NOTHING)[source]#
Bases:
MyAttrsMixin,Sequence[SupportsModelDataT_co],Generic[DataT,SupportsModelDataT_co]Sequence of models.
- Parameters:
states (
list) – list of states to consider Note that some subclasses require this list to be sortedkws (
Mapping, optional) – additional key word arguments to keep internally in self.kws
Methods:
predict(alpha, **kwargs)Prediction routine.
coefs([order])Coefficients.
resample(sampler, **kws)Resample underlying models.
map(func, *args, **kwargs)Apply a function to elements self.
map_concat(func, *args[, concat_dim, concat_kws])Apply function and concat output.
append(states[, sort, key])Create new object with states appended to self.states.
- resample(sampler, **kws)[source]#
Resample underlying models.
If pass in a single sampler, use it for all states. For example, to resample all states with some
nrep, use.resample(sampler={"nrep": nrep}). Note that the if you pass a single mapping, the mapping will be passed to each stateresamplemethod, which will in turn create unique sample for each state. To specify a different sampler for each state, pass in a sequence of sampler.
- map(func, *args, **kwargs)[source]#
Apply a function to elements self.
out = [func(s, *args, **kwargs) for s in self].
- map_concat(func, *args, concat_dim=None, concat_kws=None, **kwargs)[source]#
Apply function and concat output.
defaults to concat with dim=pd.Index(self.alpha0, name=self.alpha_name)
- append(states, sort=True, key=None, **kws)[source]#
Create new object with states appended to self.states.
- Parameters:
states (
list) – states to append to self.statessort (
bool, defaultTrue) – if true, sort states by key alpha0key (
callable(), optional) – callable function to use as key ifsort=True. Default is lambda x: x.alpha0 see sorted functionkws (
dict) – extra arguments to sorted
- Returns:
out (
object) – same type as self with new states added to states list
- thermoextrap.models.xr_weights_minkowski(deltas, m=20, dim='state')[source]#
Minkowski weights DataArray.
- class thermoextrap.models.PiecewiseStateCollection(states, *, kws=NOTHING)[source]#
Bases:
StateCollection[DataT,SupportsModelDataT]Provide methods for Piecewise state collection.
- class thermoextrap.models.ExtrapWeightedModel(states, *, kws=NOTHING)[source]#
Bases:
PiecewiseStateCollection[DataT,ExtrapModel[DataT]],Generic[DataT]Weighted extrapolation model.
- Parameters:
states (sequence of
ExtrapModel) – Extrap models to consider.kws (
Mapping, optional) – additional key word arguments to keep internally in self.kws
Methods:
predict(alpha, *[, order, order_dim, ...])- predict(alpha, *, order=None, order_dim='order', cumsum=False, minus_log=None, alpha_name=None, method=None, bounded=False, **kwargs)[source]#
- Parameters:
method (
{None, 'between', 'nearest'}) – method to select which models are chosen to predict value for given value of alpha.None or between: use states such that state[i].alpha0 <= alpha < states[i+1] if alpha < state[0].alpha0 use first two states if alpha > states[-1].alpha0 use last two states
nearest: use two states with minimum abs(state[k].alpha0 - alpha)
Notes
This requires that states are ordered in ascending alpha0 order
- class thermoextrap.models.InterpModel(states, *, kws=NOTHING)[source]#
Bases:
StateCollection[DataT,SupportsModelDerivsDataT]Interpolation model.
- Parameters:
states (
list) – list of states to consider Note that some subclasses require this list to be sortedkws (
Mapping, optional) – additional key word arguments to keep internally in self.kws
Methods:
coefs([order, order_dim, minus_log])Coefficients.
predict(alpha, *[, order, order_dim, ...])Prediction routine.
- class thermoextrap.models.InterpModelPiecewise(states, *, kws=NOTHING)[source]#
Bases:
PiecewiseStateCollection[DataT,SupportsModelDerivsDataT]Apposed to the multiple model InterpModel, perform a piecewise interpolation.
- Parameters:
states (
list) – list of states to consider Note that some subclasses require this list to be sortedkws (
Mapping, optional) – additional key word arguments to keep internally in self.kws
Methods:
predict(alpha, *[, order, order_dim, ...])
- class thermoextrap.models.PerturbModel(alpha0, data, alpha_name='alpha')[source]#
Bases:
MyAttrsMixin,Generic[DataT]Perturbation model.
- class thermoextrap.models.MBARModel(states, *, kws=NOTHING)[source]#
Bases:
StateCollection[DataArray,Any]Sadly, this doesn’t work as beautifully.
- Parameters:
states (
list) – list of states to consider Note that some subclasses require this list to be sortedkws (
Mapping, optional) – additional key word arguments to keep internally in self.kws
Methods:
predict(alpha, *[, alpha_name])Prediction routine.
resample(*args, **kwargs)Resample underlying models.
- predict(alpha, *, alpha_name=None, **kwargs)[source]#
Prediction routine.
To be implemented by subclasses.
- resample(*args, **kwargs)[source]#
Resample underlying models.
If pass in a single sampler, use it for all states. For example, to resample all states with some
nrep, use.resample(sampler={"nrep": nrep}). Note that the if you pass a single mapping, the mapping will be passed to each stateresamplemethod, which will in turn create unique sample for each state. To specify a different sampler for each state, pass in a sequence of sampler.