Routines to calculate measures of pair potentials (analphipy.measures)#

Classes:

Measures(phi, segments[, quad_kws])

Convenience class for calculating measures.

Functions:

secondvirial(phi, beta, segments[, err, ...])

Calculate the second virial coefficient.

secondvirial_dbeta(phi, beta, segments[, ...])

beta derivative of second virial coefficient.

secondvirial_sw(beta, sig, eps, lam)

Second virial coefficient for a square well (SW) fluid.

diverg_kl_cont(p, q, segments[, segments_q, ...])

Calculate continuous Kullback–Leibler divergence for continuous pdf.

diverg_js_cont(p, q, segments[, segments_q, ...])

Continuous Jensen–Shannon divergence.

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. For n = 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:
Returns:

  • B2 (float) – Value of second virial coefficient.

  • error (float, optional) – Total integration error. Returned if err or full_output are True.

  • outputs (object) – Output(s) from scipy.integrate.quad(). Returned if full_output is True.

See also

secondvirial

secondvirial_dbeta(beta, err=False, full_output=False, **kws)[source]#

Calculate beta derivative of second virial coefficient.

Parameters:
  • beta (float) – Inverse temperature.

  • 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 if err or full_output are True.

  • outputs (object) – Output(s) from scipy.integrate.quad(). Returned if full_output is True.

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 or callable(), optional) – Volume element in integration. For example, use volume = 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

diverg_js_cont

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

diverg_js_cont

References

See here for more info <https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence#Symmetrised_divergence>

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. For n = 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 if err or full_output are True.

  • outputs (object) – Output(s) from scipy.integrate.quad(). Returned if full_output is True.

See also

quad_segments

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. For n = 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 if err or full_output are True.

  • outputs (object) – Output(s) from scipy.integrate.quad(). Returned if full_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}\]
Parameters:
  • beta (float) – Inverse temperature.

  • sig (float) – Length parameter \(\sigma\).

  • eps (float) – Energy parameter \(\epsilon\).

  • lam (float) – Well width parameter \(\lambda\).

Returns:

B2 (float) – Value of second virial coefficient.

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 consider

  • volume (str or callable(), optional) – Volume element in integration. For example, use volume = 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. For n = 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_q

  • err (bool, optional) – If True, return error.

  • full_output (bool, optional) – If True, return extra information.

Returns:

  • result (float or ndarray) – value of divergence

  • error (float, optional) – Total integration error. Returned if err or full_output are True.

  • outputs (object) – Output(s) from scipy.integrate.quad(). Returned if full_output is True.

References

See here for more info on Kullback & Leibeler 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 consider

  • volume (str or callable(), optional) – Volume element in integration. For example, use volume = 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. For n = 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_q

  • err (bool, optional) – If True, return error.

  • full_output (bool, optional) – If True, return extra information.

Returns:

  • result (float or ndarray) – value of divergence

  • error (float, optional) – Total integration error. Returned if err or full_output are True.

  • outputs (object) – Output(s) from scipy.integrate.quad(). Returned if full_output is True.

References

See here for more info on Kullback & Leibeler divergence