General extrapolation/interpolation models (models)

Contents

General extrapolation/interpolation models (models)#

Classes:

Derivatives(funcs, *[, exprs, args])

Class to wrap functions calculating derivatives to specified order.

ExtrapModel(alpha0, data, derivatives[, ...])

Apply taylor series extrapolation.

ExtrapWeightedModel(states, *[, kws])

Weighted extrapolation model.

InterpModel(states, *[, kws])

Interpolation model.

InterpModelPiecewise(states, *[, kws])

Apposed to the multiple model InterpModel, perform a piecewise interpolation.

MBARModel(states, *[, kws])

Sadly, this doesn't work as beautifully.

PerturbModel(alpha0, data[, alpha_name])

Perturbation model.

StateCollection(states, *[, kws])

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 derivative

  • exprs (sequence of Expr, optional) – expressions corresponding to the funcs Mostly for debugging purposes.

Attributes:

funcs

Sequence of callable functions

exprs

Sequence of sympy expressions, optional

args

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_args

  • order (int, optional) – If pass data and order is None, then order=data.order Otherwise, must mass order

  • args (tuple) – arguments passed to self.funcs[i](*args)

  • minus_log (bool, default False) – 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 DataArray

  • concat_kws (dict, optional) – extra arguments to xarray.concat

  • norm (bool, default False) – 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 of xarray.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

derivs

classmethod from_sympy(exprs, args)[source]#

Create object from list of sympy functions.

Parameters:
Returns:

output (object)

asdict()[source]#

Convert object to dictionary.

assign(**kws)[source]#

Alias to new_like().

new_like(**kws)[source]#

Create a new object with optional parameters.

Parameters:

**kwsattribute, value pairs.

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).

class thermoextrap.models.ExtrapModel(alpha0, data, derivatives, order=_Nothing.NOTHING, *, minus_log=False, alpha_name='alpha')[source]#

Bases: MyAttrsMixin

Apply taylor series extrapolation.

Attributes:

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

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

__call__(*args, **kwargs)[source]#

Call self as a function.

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 of DataArray) – 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, default False) – If True, perform a cumsum on output for all orders. Otherwise, to total sum.

  • no_sum (bool, default False) – If True, do not sum the results. Useful if manually performing any math with series.

  • minus_log (bool, default False) – If True, transform expansion to Y = - log(X).

  • alpha_name (str, optional) – Name to apply to created alpha dimension.

  • dalpha_coords (str, default "dalpha") – Name of coordinate dalpha = alpha - alpha0.

  • alpha0_coords (bool, default True) – If True, add alpha0 to the coordinates of the results.

Returns:

output (DataArray or Dataset)

resample(indices=None, nrep=None, **kws)[source]#

Create new object with resampled data.

asdict()[source]#

Convert object to dictionary.

assign(**kws)[source]#

Alias to new_like().

new_like(**kws)[source]#

Create a new object with optional parameters.

Parameters:

**kwsattribute, value pairs.

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).

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

__call__(*args, **kwargs)[source]#

Call self as a function.

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.states

  • sort (bool, default True) – if true, sort states by key alpha0

  • key (callable(), optional) – callable function to use as key. Default is lambda x: x.alpha0 see sorted function

  • kws (dict) – extra arguments to sorted

Returns:

out (object) – same type as self with new states added to states list

asdict()[source]#

Convert object to dictionary.

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)

new_like(**kws)[source]#

Create a new object with optional parameters.

Parameters:

**kwsattribute, value pairs.

resample(indices=None, nrep=None, **kws)[source]#

Resample underlying models.

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).

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 sorted

  • kws (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).

__call__(*args, **kwargs)[source]#

Call self as a function.

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.states

  • sort (bool, default True) – if true, sort states by key alpha0

  • key (callable(), optional) – callable function to use as key. Default is lambda x: x.alpha0 see sorted function

  • kws (dict) – extra arguments to sorted

Returns:

out (object) – same type as self with new states added to states list

asdict()[source]#

Convert object to dictionary.

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)

new_like(**kws)[source]#

Create a new object with optional parameters.

Parameters:

**kwsattribute, value pairs.

resample(indices=None, nrep=None, **kws)[source]#

Resample underlying models.

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).

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 sorted

  • kws (Mapping, optional) – additional key word arguments to keep internally in self.kws

Methods:

predict(alpha[, order, order_dim, ...])

Parameters:

alpha (float or sequence of float)

__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]#
Parameters:

alpha (float or sequence of float)

__call__(*args, **kwargs)[source]#

Call self as a function.

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.states

  • sort (bool, default True) – if true, sort states by key alpha0

  • key (callable(), optional) – callable function to use as key. Default is lambda x: x.alpha0 see sorted function

  • kws (dict) – extra arguments to sorted

Returns:

out (object) – same type as self with new states added to states list

asdict()[source]#

Convert object to dictionary.

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)

new_like(**kws)[source]#

Create a new object with optional parameters.

Parameters:

**kwsattribute, value pairs.

resample(indices=None, nrep=None, **kws)[source]#

Resample underlying models.

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).

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 sorted

  • kws (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).

resample(*args, **kwargs)[source]#

Resample underlying models.

__call__(*args, **kwargs)[source]#

Call self as a function.

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.states

  • sort (bool, default True) – if true, sort states by key alpha0

  • key (callable(), optional) – callable function to use as key. Default is lambda x: x.alpha0 see sorted function

  • kws (dict) – extra arguments to sorted

Returns:

out (object) – same type as self with new states added to states list

asdict()[source]#

Convert object to dictionary.

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)

new_like(**kws)[source]#

Create a new object with optional parameters.

Parameters:

**kwsattribute, value pairs.

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).

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).

asdict()[source]#

Convert object to dictionary.

assign(**kws)[source]#

Alias to new_like().

new_like(**kws)[source]#

Create a new object with optional parameters.

Parameters:

**kwsattribute, value pairs.

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).

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 sorted

  • kws (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).

__call__(*args, **kwargs)[source]#

Call self as a function.

resample(indices=None, nrep=None, **kws)[source]#

Resample underlying models.

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.states

  • sort (bool, default True) – if true, sort states by key alpha0

  • key (callable(), optional) – callable function to use as key. Default is lambda x: x.alpha0 see sorted function

  • kws (dict) – extra arguments to sorted

Returns:

out (object) – same type as self with new states added to states list

asdict()[source]#

Convert object to dictionary.

assign(**kws)[source]#

Alias to new_like().

new_like(**kws)[source]#

Create a new object with optional parameters.

Parameters:

**kwsattribute, value pairs.

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).