Magnetization functions

namespace mag

Functions

double clamp(const double &x, const double &low, const double &high)

Clamp value between boundaries.

Return
value clamped between boudaries
Parameters
  • x: double value as argument of clamp
  • low: lower boundary
  • high: higher boundary

double lr(const double &x)

log1p for magnetizations.

Return
value computed as log1p(exp(-2*abs(x)))
Parameters
  • x: double value

long int sign0(const double &x)

Sign operation valid also for magnetizations.

Return
sign evaluated as 1 - 2*signbit(x)
Parameters
  • x: double value

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>bool mag::isinf(const double & x)

Check if is infinite.

Return
result of the check
Note
The function behavior is different between MagP64 and MagT64.
  • MagP64: boolean true if is inf or -inf else false
  • MagT64: boolean true if is nan or -nan else false
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • x: double value

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>bool mag::signbit(const Mag & m)

Get the sign of magnetization.

Return
boolean sign of magnetization
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • m: Mag

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>void mag::zeros(Mag * x, const long int & n)

Fill a magnetization array with zeros.

Return
void
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • x: mag array
  • n: array size

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>void mag::zero(Mag & x)

Set magnetization to zero.

Return
void
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • x: mag object

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>double mag::abs(const Mag & a)

Abs for magnetization objects.

Return
The absolute value of the input
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • a: mag object

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>Mag mag::copysign(Mag & x, const double & y)

Flip magnetization sign if necessary.

Return
The corrected mag object
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • x: mag object
  • y: value with desired sign

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>Mag mag::arrow(const Mag & m, const double & x)

Arrow operator of original code.

Return
The result of the operator.
Note
The function behavior is different between MagP64 and MagT64.
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • m: mag object
  • x: value to multiply

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>long int mag::sign0(const Mag & x)

Get magnetization sign.

Return
sign computed as 1 - 2 * sign(x)
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • x: mag object

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>double mag::logmag2p(const Mag & x)

Log operation for magnetization objects.

Return
The result of the operation
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • x: mag object

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>Mag mag::convert(const double & x)

Convert a double to a mag value (as a constructor).

Return
magnetization
Note
The function behavior is different between MagP64 and MagT64.
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • x: double value

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>double mag::convert(const Mag & x)

Convert a mag to double.

Return
extract magnetization.
Note
The function behavior is different between MagP64 and MagT64.
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • x: mag object

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>Mag mag::couple(const double & x1, const double & x2)

Combine values to magnetizations.

Return
The result of the combination.
Note
The function behavior is different between MagP64 and MagT64.
  • MagP64: (x1 - x2) / (x1 + x2)
  • MagT64: log(x1) - log(x2) * .5
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • x1: double
  • x2: double

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>Mag mag::damp(const Mag & newx, const Mag & oldx, const double & l)

Update magnetization.

Return
The result of the update computed as newx * (1 - l) + oldx * l
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • newx: mag object
  • oldx: mag object
  • l: double value

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>Mag mag::mtanh(const double & x)

Perform tanh on magnetization value.

Return
The result of tanh as Mag.
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • x: double value

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>Mag mag::merf(const double & x)

Perform erf on magnetization value.

Return
The result of atanherf(x).
Note
The function behavior is different between MagP64 and MagT64.
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • x: double value

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>Mag mag::bar(const Mag & m1, const Mag & m2)

Diff of magnetizations.

Return
The result of the diff.
Note
The function behavior is different between MagP64 and MagT64.
  • MagP64: (m1 - m2)/(1 - m1 * m2) clamped to [-1, 1]
  • MagT64: m1 - m2
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • m1: mag object
  • m2: mag object

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>double mag::log1pxy(const Mag & x, const Mag & y)

Compute the log1p for the combination of the magnetizations.

Return
The result of the operation
Note
The function behavior is different between MagP64 and MagT64.
  • MagP64: log((1. + (x.mag * y.mag)) * 0.5)
  • MagT64: computation takes care of possible number overflows
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • x: mag object
  • y: mag object

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>double mag::mcrossentropy(const Mag & x, const Mag & y)

Compute the crossentropy score for magnetization objects.

Return
The resulting crossentropy score
Note
The function behavior is different between MagP64 and MagT64.
  • MagP64: -x.mag * np.arctanh(y.mag) - np.log1p(- y.mag**2) * .5 + np.log(2)
  • MagT64: -abs(y.mag) * (sign0(y.mag) * x.value - 1.) + lr(y.mag)
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • x: mag object
  • y: mag object

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>double mag::logZ(const Mag & u0, const Mag * u, const long int & nu)
template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagT64 > ::value > ::type * = nullptr>Mag mag::auxmix(const Mag & H, const double & ap, const double & am)

Combine three MagT64 variables.

Return
combination of the input
Note
This operation is valid only for MagT64 variables up to now
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • H: mag object
  • ap: double
  • am: double

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>Mag mag::erfmix(const Mag & H, const double & mp, const double & mm)

Combine exactly three magnetizations.

Return
The result of the mix
Note
The function behavior is different between MagP64 and MagT64.
  • MagP64: H.mag * (erf(mp) - erf(mm)) / (2. + H.mag * (erf(mp) + erf(mm)))
  • MagT64: auxmix(H, atanherf(mp), atanherf(mm))
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • H: mag object
  • mp: double
  • mm: double

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>Mag mag::exactmix(const Mag & H, const Mag & pp, const Mag & pm)

Combine exactly three magnetizations.

Return
The result of the mix
Note
The function behavior is different between MagP64 and MagT64.
  • MagP64: (pp.mag - pm.mag) * H.mag / (2. + (pp.mag + pm.mag) * H.mag)
  • MagT64: auxmix(H, pp.mag, pm.mag)
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • H: mag object
  • pp: mag object
  • pm: mag object