Routines to calculate measures of pair potentials (analphipy.measures
)#
Classes:
|
Convenience class for calculating measures. |
Functions:
|
Continuous Jensen-Shannon divergence. |
|
Calculate continuous Kullback-Leibler divergence for continuous pdf. |
|
Calculate the second virial coefficient. |
|
|
|
Second virial coefficient for a square well (SW) fluid. |
- class analphipy.measures.Measures(phi, segments, quad_kws=None)[source]#
Bases:
object
Convenience class for calculating measures.
- Parameters:
phi (
callable()
) – Potential function.segments (sequence of
int
) – Integration limits. Forn = len(segments)
integration will be performed over ranges(segments[0], segments[1]), (segments[1], segments[2]), ..., (segments[n-2], segments[n-]])
quad_kws (mapping, optional) – Extra arguments to
analphipy.utils.quad_segments()
Methods:
secondvirial
(beta[, err, full_output])Calculate second virial coefficient.
secondvirial_dbeta
(beta[, err, full_output])Calculate
beta
derivative of second virial coefficient.boltz_diverg_js
(other, beta[, beta_other, ...])Jensen-Shannon divergence of the Boltzmann factors of two potentials.
mayer_diverg_js
(other, beta[, beta_other, ...])Jensen-Shannon divergence of the Mayer f-functions of two potentials.
- secondvirial(beta, err=False, full_output=False, **kws)[source]#
Calculate second virial coefficient.
- Parameters:
beta (
float
) – Inverse temperature.err (
bool
, optional) – If True, return error.full_output (
bool
, optional) – If True, return extra information.**kws – Extra arguments to
analphipy.utils.quad_segments()
- Returns:
B2 (
float
) – Value of second virial coefficient.error (
float
, optional) – Total integration error. Returned iferr
orfull_output
are True.outputs (
object
) – Output(s) fromscipy.integrate.quad()
. Returned iffull_output
is True.
See also
- secondvirial_dbeta(beta, err=False, full_output=False, **kws)[source]#
Calculate
beta
derivative of second virial coefficient.- Parameters:
- Returns:
dB2dbeta (
float
) – Value of derivative.error (
float
, optional) – Total integration error. Returned iferr
orfull_output
are True.outputs (
object
) – Output(s) fromscipy.integrate.quad()
. Returned iffull_output
is True.
See also
- boltz_diverg_js(other, beta, beta_other=None, volume='3d', err=False, full_output=False, **kws)[source]#
Jensen-Shannon divergence of the Boltzmann factors of two potentials.
The Boltzmann factors are defined as:
\[B(r; \beta, \phi) = \exp(-\beta \phi(r))\]- Parameters:
other (
analphipy.base_potential.PhiAbstract
) – Class wrapping other potential to compare self to.beta (
float
) – Inverse temperature.beta_other (
float
, optional) – beta value to evaluate other Boltzmann factor at.volume (
str
orcallable()
, optional) – Volume element in integration. For example, usevolume = lambda x: 4 * np.pi * x ** 2
for spherically symmetric 3d integration. Can also pass string value of {‘1d’, ‘2d’, ‘3d’}. If passed None, then assume ‘1d’ integration.
See also
References
See here for more info <https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence#Symmetrised_divergence>
- mayer_diverg_js(other, beta, beta_other=None, volume='3d', err=False, full_output=False, **kws)[source]#
Jensen-Shannon divergence of the Mayer f-functions of two potentials.
The Mayer f-function is defined as:
\[f(r; \beta, \phi) = \exp(-beta \phi(r)) - 1\]- Parameters:
other (
analphipy.base_potential.PhiAbstract
) – Class wrapping other potential to compare self to.{beta}
beta_other (
float
, optional) – beta value to evaluate other Boltzmann factor at.{volume_int_func}
See also
References
See here for more info <https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence#Symmetrised_divergence>
- analphipy.measures.diverg_js_cont(p, q, segments, segments_q=None, volume=None, err=False, full_output=False, **kws)[source]#
Continuous Jensen-Shannon divergence.
- Parameters:
p, q (
callable()
) – Probabilities to considervolume (
str
orcallable()
, optional) – Volume element in integration. For example, usevolume = lambda x: 4 * np.pi * x ** 2
for spherically symmetric 3d integration. Can also pass string value of {‘1d’, ‘2d’, ‘3d’}. If passed None, then assume ‘1d’ integration.segments (sequence of
int
) – Integration limits. Forn = len(segments)
integration will be performed over ranges(segments[0], segments[1]), (segments[1], segments[2]), ..., (segments[n-2], segments[n-]])
segments_q (
list
, optional) – if supplied, build total segments by combining segments and segments_qerr (
bool
, optional) – If True, return error.full_output (
bool
, optional) – If True, return extra information.
- Returns:
error (
float
, optional) – Total integration error. Returned iferr
orfull_output
are True.outputs (
object
) – Output(s) fromscipy.integrate.quad()
. Returned iffull_output
is True.
References
See here for more info on Kullback & Leibeler divergence
Calculate Jensen-Shannon divergence for continuous functions.
- analphipy.measures.diverg_kl_cont(p, q, segments, segments_q=None, volume=None, err=False, full_output=False, **kws)[source]#
Calculate continuous Kullback-Leibler divergence for continuous pdf.
- Parameters:
p, q (
callable()
) – Probabilities to considervolume (
str
orcallable()
, optional) – Volume element in integration. For example, usevolume = lambda x: 4 * np.pi * x ** 2
for spherically symmetric 3d integration. Can also pass string value of {‘1d’, ‘2d’, ‘3d’}. If passed None, then assume ‘1d’ integration.segments (sequence of
int
) – Integration limits. Forn = len(segments)
integration will be performed over ranges(segments[0], segments[1]), (segments[1], segments[2]), ..., (segments[n-2], segments[n-]])
segments_q (
list
, optional) – if supplied, build total segments by combining segments and segments_qerr (
bool
, optional) – If True, return error.full_output (
bool
, optional) – If True, return extra information.
- Returns:
error (
float
, optional) – Total integration error. Returned iferr
orfull_output
are True.outputs (
object
) – Output(s) fromscipy.integrate.quad()
. Returned iffull_output
is True.
References
- analphipy.measures.secondvirial(phi, beta, segments, err=False, full_output=False, **kws)[source]#
Calculate the second virial coefficient.
\[B_2(\beta) = -\int 2\pi r^2 dr \left(\exp(-\beta \phi(r)) - 1\right)\]- Parameters:
phi (
callable()
) – Potential function.beta (
float
) – Inverse temperature.segments (sequence of
int
) – Integration limits. Forn = len(segments)
integration will be performed over ranges(segments[0], segments[1]), (segments[1], segments[2]), ..., (segments[n-2], segments[n-]])
err (
bool
, optional) – If True, return error.full_output (
bool
, optional) – If True, return extra information.**kws – Extra arguments to
analphipy.utils.quad_segments()
- Returns:
B2 (
float
) – Value of second virial coefficient.error (
float
, optional) – Total integration error. Returned iferr
orfull_output
are True.outputs (
object
) – Output(s) fromscipy.integrate.quad()
. Returned iffull_output
is True.
See also
- analphipy.measures.secondvirial_dbeta(phi, beta, segments, err=False, full_output=False, **kws)[source]#
beta
derivative of second virial coefficient.\[\frac{d B_2}{d \beta} = \int 2\pi r^2 dr \phi(r) \exp(-\beta \phi(r))\]- Parameters:
phi (
callable()
) – Potential function.beta (
float
) – Inverse temperature.segments (sequence of
int
) – Integration limits. Forn = len(segments)
integration will be performed over ranges(segments[0], segments[1]), (segments[1], segments[2]), ..., (segments[n-2], segments[n-]])
err (
bool
, optional) – If True, return error.full_output (
bool
, optional) – If True, return extra information.
- Returns:
dB2dbeta (
float
) – Value of derivative.error (
float
, optional) – Total integration error. Returned iferr
orfull_output
are True.outputs (
object
) – Output(s) fromscipy.integrate.quad()
. Returned iffull_output
is True.
- analphipy.measures.secondvirial_sw(beta, sig, eps, lam)[source]#
Second virial coefficient for a square well (SW) fluid. Note that this assumes that the SW fluid is defined by the potential:
\[\begin{split}\phi(r) = \begin{cases} \infty & r \leq \sigma \\ \epsilon & \sigma < r \leq \lambda \sigma \\ 0 & \lambda \sigma < r \end{cases}\end{split}\]