MagT64

class rfbp.MagT64.MagT64(x, mInf=30.0)[source]

Bases: ReplicatedFocusingBeliefPropagation.rfbp.Mag.BaseMag

__mod__(m)[source]

In this case the mod operation corresponds to a sum of mags

Parameters:m (MagT64) – The input value
Returns:m – The MagT64 of the operation between the two mags. The mod operation corresponds to self.mag + m.mag
Return type:MagT64

Example

>>> import numpy as np
>>> from ReplicatedFocusingBeliefPropagation import MagT64
>>>
>>> x = np.random.uniform(low=0., high=10)
>>> y = np.random.uniform(low=0., high=1)
>>> m1 = MagT64(x)
>>> m2 = MagT64(y)
>>>
>>> mx = m1 % m2
>>> my = m2 % m1
>>> assert np.isclose(mx.mag, my.mag)
>>> assert np.isclose(mx.value, my.value)
>>>
>>> null = MagT64(0.)
>>> mx = m1 % null
>>> assert np.isclose(mx.mag, m1.mag)
>>> assert np.isclose(mx.value, m1.value)
__xor__(m)[source]

Mag product

Parameters:m (MagT64) – The input value
Returns:m – The product of mags
Return type:MagT64

Example

>>> import numpy as np
>>> from ReplicatedFocusingBeliefPropagation import MagT64
>>>
>>> x = np.random.uniform(low=0., high=10)
>>> y = np.random.uniform(low=0., high=1)
>>> m1 = MagT64(x)
>>> m2 = MagT64(y)
>>>
>>>
>>> mx = m1 ^ m2
>>> my = m2 ^ m1
>>> assert np.isclose(mx.mag, my.mag)
>>> assert np.isclose(mx.value, my.value)
>>>
>>> mx = (-m1) ^ (-m2)
>>> my = (-m2) ^ (-m1)
>>> assert not np.isclose(mx.mag, my.mag)
>>> assert not np.isclose(mx.value, my.value)
>>>
>>> null = MagT64(0.)
>>> mx = m1 ^ null
>>> assert np.isclose(mx.mag, 0.)
>>> assert np.isclose(mx.value, 0.)
>>>
>>> mx = m1 ^ MagT64(float('inf'))
>>> assert np.isclose(mx.mag, m1.mag)
>>> assert np.isclose(mx.value, m1.value)
static convert(x)[source]

Convert a float to a mag value (as a constructor)

Parameters:x (float) – The number to convert
Returns:m – Convert any-number to a MagT64 type
Return type:MagT64

Example

>>> import numpy as np
>>> from ReplicatedFocusingBeliefPropagation import MagT64
>>>
>>> x = np.random.uniform(low=0., high=10)
>>> mx = MagT64.convert(x)
>>> assert -30. <= mx.mag <= 30.
>>> assert np.isclose(mx.mag, np.arctanh(x))
>>> assert np.isclose(mx.value, x)
static couple(x1, x2)[source]

Combine two mags

Parameters:
  • x1 (float) – The first element of the operation
  • x2 (float) – The second element of the operation
Returns:

x – Mags combination as np.log(x1 / x2) * .5

Return type:

float

Example

>>> import numpy as np
>>> from ReplicatedFocusingBeliefPropagation import MagT64
>>>
>>> x = np.random.uniform(low=0., high=10)
>>> y = np.random.uniform(low=0., high=10)
>>> mx = MagT64.couple(x, y)
>>> my = MagT64.couple(y, x)
>>> assert np.isclose(abs(mx.mag), abs(my.mag))
>>> assert np.isclose(abs(mx.value), abs(my.value))
magformat

Return the mag description

Returns:tanh – The MagT64 type corresponds to a tanh operation
Return type:str

Example

>>> from ReplicatedFocusingBeliefPropagation import MagT64
>>> m = MagT64(3.14)
>>> m.magformat
  'tanh'
static merf(x)[source]

Perform erf on magnetization value (MagT64(erf(x)) in this case)

Parameters:x (float) – The input value
Returns:m – The MagT64 version of the erf(x)
Return type:MagT64

Example

>>> import numpy as np
>>> from scipy.special import erf
>>> from ReplicatedFocusingBeliefPropagation import MagT64
>>>
>>> x = np.random.uniform(low=0., high=10)
>>> mx = MagT64.merf(x)
>>> assert np.isclose(mx.mag, np.arctanh(erf(x)))
static mtanh(x)[source]

Perform tanh on magnetization value (MagT64(x) in this case)

Parameters:x (float) – The input value
Returns:m – The MagT64 version of the tanh(x)
Return type:MagT64

Example

>>> import numpy as np
>>> from ReplicatedFocusingBeliefPropagation import MagT64
>>>
>>> x = np.random.uniform(low=0., high=10)
>>> mx = MagT64.mtanh(x)
>>> assert np.isclose(mx.mag, x)
>>> assert np.isclose(mx.value, np.tanh(x))
value

Return the mag value

Returns:x – In MagT64 the value is equal to the tanh(x)
Return type:float

Example

>>> from ReplicatedFocusingBeliefPropagation import MagT64
>>> x = np.random.uniform(low=0, high=1.)
>>> m = MagT64(x)
>>> assert np.isclose(m.mag, x)
>>> assert np.isclose(m.value, np.tanh(x))