General extrapolation/interpolation models (models
)#
Classes:
|
Class to wrap functions calculating derivatives to specified order. |
|
Apply taylor series extrapolation. |
|
Weighted extrapolation model. |
|
Interpolation model. |
|
Apposed to the multiple model InterpModel, perform a piecewise interpolation. |
|
Sadly, this doesn't work as beautifully. |
|
Perturbation model. |
|
Sequence of models. |
- class thermoextrap.models.Derivatives(funcs, *, exprs=None, args=None)[source]#
Bases:
MyAttrsMixin
Class 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:
Sequence of callable functions
Sequence of sympy expressions, optional
Arguments
Methods:
derivs
([data, order, args, minus_log, ...])Calculate derivatives for orders range(0, order+1).
coefs
([data, args, order, minus_log, order_dim])Alias to self.derivs(..., norm=True).
from_sympy
(exprs, args)Create object from list of sympy functions.
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.new_like
(**kws)Create a new object with optional parameters.
set_params
(**kws)Set parameters of self, and return self (for chaining).
- funcs#
Sequence of callable functions
- exprs#
Sequence of sympy expressions, optional
- args#
Arguments
- derivs(data=None, order=None, args=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.derivs_argsorder (
int
, optional) – If pass data and order is None, then order=data.order Otherwise, must mass orderargs (
tuple
) – arguments passed toself.funcs[i](*args)
minus_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 (
list
ofxarray.DataArray
) – See above for nature of output
- coefs(data=None, args=None, order=None, minus_log=False, order_dim='order')[source]#
Alias to self.derivs(…, norm=True).
See also
- assign(**kws)[source]#
Alias to
new_like()
.
- class thermoextrap.models.ExtrapModel(alpha0, data, derivatives, order=_Nothing.NOTHING, *, minus_log=False, alpha_name='alpha')[source]#
Bases:
MyAttrsMixin
Apply taylor series extrapolation.
Attributes:
Alpha value data is evaluated at
Data object
Derivatives object
Maximum order of expansion
Whether to apply X <- -log(X).
Name of alpha
Methods:
__call__
(*args, **kwargs)Call self as a function.
predict
(alpha[, order, order_dim, cumsum, ...])Calculate taylor series at values "alpha".
resample
([indices, nrep])Create new object with resampled data.
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.new_like
(**kws)Create a new object with optional parameters.
set_params
(**kws)Set parameters of self, and return self (for chaining).
- alpha0#
Alpha value data is evaluated at
- data#
Data object
- derivatives#
Derivatives object
- order#
Maximum order of expansion
- 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 (
float
or 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 (
bool
, defaultTrue
) – If True, addalpha0
to the coordinates of the results.
- Returns:
- assign(**kws)[source]#
Alias to
new_like()
.
- class thermoextrap.models.ExtrapWeightedModel(states, *, kws=None)[source]#
Bases:
StateCollection
,PiecewiseMixin
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, cumsum, ...])- Parameters:
method (
{None, 'between', 'nearest'}
) -- method to select which models are chosen to predict value for given
__call__
(*args, **kwargs)Call self as a function.
append
(states[, sort, key])Create new object with states appended to self.states.
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.map
(func, *args, **kwargs)Apply a function to elements self.
map_concat
(func[, concat_dim, concat_kws])Apply function and concat output.
new_like
(**kws)Create a new object with optional parameters.
resample
([indices, nrep])Resample underlying models.
set_params
(**kws)Set parameters of self, and return self (for chaining).
- predict(alpha, order=None, order_dim='order', cumsum=False, minus_log=None, alpha_name=None, method=None, bounded=False)[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
- 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. 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
- assign(**kws)[source]#
Alias to
new_like()
.
- map(func, *args, **kwargs)[source]#
Apply a function to elements self.
out = [func(s, *args, **kwargs) for s in self]
.if func is a str, then
out = [getattr(s, func)(*args, **kwargs) for s in self]
- map_concat(func, concat_dim=None, concat_kws=None, *args, **kwargs)[source]#
Apply function and concat output.
defaults to concat with dim=pd.Index(self.alpha0, name=self.alpha_name)
- class thermoextrap.models.InterpModel(states, *, kws=None)[source]#
Bases:
StateCollection
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:
__call__
(*args, **kwargs)Call self as a function.
append
(states[, sort, key])Create new object with states appended to self.states.
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.map
(func, *args, **kwargs)Apply a function to elements self.
map_concat
(func[, concat_dim, concat_kws])Apply function and concat output.
new_like
(**kws)Create a new object with optional parameters.
resample
([indices, nrep])Resample underlying models.
set_params
(**kws)Set parameters of self, and return self (for chaining).
- 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. 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
- assign(**kws)[source]#
Alias to
new_like()
.
- map(func, *args, **kwargs)[source]#
Apply a function to elements self.
out = [func(s, *args, **kwargs) for s in self]
.if func is a str, then
out = [getattr(s, func)(*args, **kwargs) for s in self]
- map_concat(func, concat_dim=None, concat_kws=None, *args, **kwargs)[source]#
Apply function and concat output.
defaults to concat with dim=pd.Index(self.alpha0, name=self.alpha_name)
- class thermoextrap.models.InterpModelPiecewise(states, *, kws=None)[source]#
Bases:
StateCollection
,PiecewiseMixin
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, ...])__call__
(*args, **kwargs)Call self as a function.
append
(states[, sort, key])Create new object with states appended to self.states.
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.map
(func, *args, **kwargs)Apply a function to elements self.
map_concat
(func[, concat_dim, concat_kws])Apply function and concat output.
new_like
(**kws)Create a new object with optional parameters.
resample
([indices, nrep])Resample underlying models.
set_params
(**kws)Set parameters of self, and return self (for chaining).
- predict(alpha, order=None, order_dim='porder', minus_log=None, alpha_name=None, method=None, bounded=False)[source]#
- 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. 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
- assign(**kws)[source]#
Alias to
new_like()
.
- map(func, *args, **kwargs)[source]#
Apply a function to elements self.
out = [func(s, *args, **kwargs) for s in self]
.if func is a str, then
out = [getattr(s, func)(*args, **kwargs) for s in self]
- map_concat(func, concat_dim=None, concat_kws=None, *args, **kwargs)[source]#
Apply function and concat output.
defaults to concat with dim=pd.Index(self.alpha0, name=self.alpha_name)
- class thermoextrap.models.MBARModel(states, *, kws=None)[source]#
Bases:
StateCollection
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:
resample
(*args, **kwargs)Resample underlying models.
__call__
(*args, **kwargs)Call self as a function.
append
(states[, sort, key])Create new object with states appended to self.states.
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.map
(func, *args, **kwargs)Apply a function to elements self.
map_concat
(func[, concat_dim, concat_kws])Apply function and concat output.
new_like
(**kws)Create a new object with optional parameters.
set_params
(**kws)Set parameters of self, and return self (for chaining).
- 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. 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
- assign(**kws)[source]#
Alias to
new_like()
.
- map(func, *args, **kwargs)[source]#
Apply a function to elements self.
out = [func(s, *args, **kwargs) for s in self]
.if func is a str, then
out = [getattr(s, func)(*args, **kwargs) for s in self]
- map_concat(func, concat_dim=None, concat_kws=None, *args, **kwargs)[source]#
Apply function and concat output.
defaults to concat with dim=pd.Index(self.alpha0, name=self.alpha_name)
- class thermoextrap.models.PerturbModel(alpha0, data, alpha_name='alpha')[source]#
Bases:
MyAttrsMixin
Perturbation model.
Methods:
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.new_like
(**kws)Create a new object with optional parameters.
set_params
(**kws)Set parameters of self, and return self (for chaining).
- assign(**kws)[source]#
Alias to
new_like()
.
- class thermoextrap.models.StateCollection(states, *, kws=None)[source]#
Bases:
MyAttrsMixin
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:
__call__
(*args, **kwargs)Call self as a function.
resample
([indices, nrep])Resample underlying models.
map
(func, *args, **kwargs)Apply a function to elements self.
map_concat
(func[, concat_dim, concat_kws])Apply function and concat output.
append
(states[, sort, key])Create new object with states appended to self.states.
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.new_like
(**kws)Create a new object with optional parameters.
set_params
(**kws)Set parameters of self, and return self (for chaining).
- map(func, *args, **kwargs)[source]#
Apply a function to elements self.
out = [func(s, *args, **kwargs) for s in self]
.if func is a str, then
out = [getattr(s, func)(*args, **kwargs) for s in self]
- map_concat(func, concat_dim=None, concat_kws=None, *args, **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. 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
- assign(**kws)[source]#
Alias to
new_like()
.