MagP64¶
-
class
rfbp.MagP64.
MagP64
(x)[source]¶ Bases:
ReplicatedFocusingBeliefPropagation.rfbp.Mag.BaseMag
-
__mod__
(m)[source]¶ Clip value in [-1, 1].
Parameters: m (MagP64) – The input value Returns: m – The MagP64 of the operation between the two mags. The clip operation is computed as np.clip( (self.mag + m.mag) / (1. + self.mag * m.mag), -1., 1.) Return type: MagP64 Example
>>> import numpy as np >>> from ReplicatedFocusingBeliefPropagation import MagP64 >>> x = np.random.uniform(low=0., high=10) >>> y = np.random.uniform(low=0., high=10) >>> m1 = MagP64(x) >>> m2 = MagP64(y) >>> mx = m1 % m2 >>> my = m2 % m1 >>> assert np.isclose(mx.mag, my.mag) >>> assert np.isclose(mx.value, my.value) >>> assert -1. <= mx.mag <= 1. >>> assert -1. <= my.mag <= 1. >>> assert -1. <= mx.value <= 1. >>> assert -1. <= my.value <= 1.
-
__xor__
(m)[source]¶ Mag product
Parameters: m (MagP64) – The input value Returns: m – The product of mags Return type: MagP64 Example
>>> import numpy as np >>> from ReplicatedFocusingBeliefPropagation import MagP64 >>> x = np.random.uniform(low=0., high=10) >>> y = np.random.uniform(low=0., high=10) >>> m1 = MagP64(x) >>> m2 = MagP64(y) >>> mx = m1 ^ m2 >>> my = m2 ^ m1 >>> assert np.isclose(mx.mag, my.mag) >>> assert np.isclose(mx.value, my.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 MagP64 type Return type: MagP64 Example
>>> import numpy as np >>> from ReplicatedFocusingBeliefPropagation import MagP64 >>> >>> x = np.random.uniform(low=0., high=10) >>> m1 = MagP64.convert(x) >>> m2 = MagP64(x) >>> assert m1.mag == m2.mag >>> assert m1.value == m2.value
-
static
couple
(x1, x2)[source]¶ Combine two mags as diff / sum
Parameters: - x1 (float) – The first element of the operation
- x2 (float) – The second element of the operation
Returns: x – In MagP64 the value is equal to the magnetization since the tanh operation is neglected
Return type: float
Example
>>> import numpy as np >>> from ReplicatedFocusingBeliefPropagation import MagP64 >>> >>> x = np.random.uniform(low=0., high=10) >>> y = np.random.uniform(low=0., high=10) >>> mx = MagP64.couple(x, y) >>> my = MagP64.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: plain – The MagP64 type corresponds to a plain operation Return type: str Example
>>> from ReplicatedFocusingBeliefPropagation import MagP64 >>> m = MagP64(3.14) >>> m.magformat 'plain'
-
static
merf
(x)[source]¶ Perform erf on magnetization value (MagP64(erf(x)) in this case)
Parameters: x (float) – The input value Returns: m – The MagP64 version of the erf(x) Return type: MagP64 Example
>>> import numpy as np >>> from scipy.special import erf >>> from ReplicatedFocusingBeliefPropagation import MagP64 >>> >>> x = np.random.uniform(low=0., high=10) >>> mx = MagP64.merf(x) >>> assert 0 <= mx.mag <= 1 >>> assert np.isclose(mx.mag, erf(x))
-
static
mtanh
(x)[source]¶ Perform tanh on magnetization value (MagP64(tanh(x)) in this case)
Parameters: x (float) – The input value Returns: m – The MagP64 version of the tanh(x) Return type: MagP64 Example
>>> import numpy as np >>> from ReplicatedFocusingBeliefPropagation import MagP64 >>> >>> x = np.random.uniform(low=0., high=10) >>> mx = MagP64.mtanh(x) >>> assert 0 <= mx.mag <= 1 >>> assert np.isclose(mx.mag, np.tanh(x))
-
value
¶ Return the mag value
Returns: x – In MagP64 the value is equal to the magnetization since the tanh operation is neglected Return type: float Example
>>> from ReplicatedFocusingBeliefPropagation import MagP64 >>> x = np.random.uniform(low=0, high=1.) >>> m = MagP64(x) >>> assert np.isclose(m.mag, x) >>> assert np.isclose(m.value, x)
-