|
|
@ -8,6 +8,7 @@ from numpy import pi, inf # @UnusedImport
|
|
|
|
from numpy.testing import assert_array_almost_equal
|
|
|
|
from numpy.testing import assert_array_almost_equal
|
|
|
|
from wafo.gaussian import (Rind, prbnormtndpc, prbnormndpc, prbnormnd,
|
|
|
|
from wafo.gaussian import (Rind, prbnormtndpc, prbnormndpc, prbnormnd,
|
|
|
|
cdfnorm2d, prbnorm2d)
|
|
|
|
cdfnorm2d, prbnorm2d)
|
|
|
|
|
|
|
|
from numpy.ma.testutils import assert_array_almost_equal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_rind():
|
|
|
|
def test_rind():
|
|
|
@ -79,47 +80,44 @@ def test_rind():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prbnormtndpc():
|
|
|
|
def test_prbnormtndpc():
|
|
|
|
'''
|
|
|
|
|
|
|
|
>>> rho2 = np.random.rand(2)
|
|
|
|
rho2 = np.random.rand(2)
|
|
|
|
>>> a2 = np.zeros(2)
|
|
|
|
a2 = np.zeros(2)
|
|
|
|
>>> b2 = np.repeat(np.inf,2)
|
|
|
|
b2 = np.repeat(np.inf, 2)
|
|
|
|
>>> [val2,err2, ift2] = prbnormtndpc(rho2,a2,b2)
|
|
|
|
[val2, err2, ift2] = prbnormtndpc(rho2, a2, b2)
|
|
|
|
>>> g2 = lambda x : 0.25+np.arcsin(x[0]*x[1])/(2*pi)
|
|
|
|
g2 = lambda x: 0.25 + np.arcsin(x[0] * x[1]) / (2 * pi)
|
|
|
|
>>> E2 = g2(rho2) #% exact value
|
|
|
|
E2 = g2(rho2) # % exact value
|
|
|
|
>>> np.abs(E2-val2)<err2
|
|
|
|
assert(np.abs(E2 - val2) < err2)
|
|
|
|
True
|
|
|
|
|
|
|
|
|
|
|
|
rho3 = np.random.rand(3)
|
|
|
|
>>> rho3 = np.random.rand(3)
|
|
|
|
a3 = np.zeros(3)
|
|
|
|
>>> a3 = np.zeros(3)
|
|
|
|
b3 = np.repeat(inf, 3)
|
|
|
|
>>> b3 = np.repeat(inf,3)
|
|
|
|
[val3, err3, ift3] = prbnormtndpc(rho3, a3, b3)
|
|
|
|
>>> [val3,err3, ift3] = prbnormtndpc(rho3,a3,b3)
|
|
|
|
g3 = lambda x: 0.5 - \
|
|
|
|
>>> g3 = lambda x : 0.5-sum(np.sort(np.arccos([x[0]*x[1],x[0]*x[2],x[1]*x[2]])))/(4*pi)
|
|
|
|
sum(np.sort(
|
|
|
|
>>> E3 = g3(rho3) # Exact value
|
|
|
|
np.arccos([x[0] * x[1], x[0] * x[2], x[1] * x[2]]))) / (4 * pi)
|
|
|
|
>>> np.abs(E3-val3)<err3
|
|
|
|
E3 = g3(rho3) # Exact value
|
|
|
|
True
|
|
|
|
assert(np.abs(E3 - val3) < err3)
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prbnormndpc():
|
|
|
|
def test_prbnormndpc():
|
|
|
|
'''
|
|
|
|
|
|
|
|
>>> rho2 = np.random.rand(2)
|
|
|
|
rho2 = np.random.rand(2)
|
|
|
|
>>> a2 = np.zeros(2);
|
|
|
|
a2 = np.zeros(2)
|
|
|
|
>>> b2 = np.repeat(np.inf,2)
|
|
|
|
b2 = np.repeat(np.inf, 2)
|
|
|
|
>>> [val2,err2, ift2] = prbnormndpc(rho2,a2,b2)
|
|
|
|
[val2, err2, ift2] = prbnormndpc(rho2, a2, b2)
|
|
|
|
>>> g2 = lambda x : 0.25+np.arcsin(x[0]*x[1])/(2*pi)
|
|
|
|
g2 = lambda x: 0.25 + np.arcsin(x[0] * x[1]) / (2 * pi)
|
|
|
|
>>> E2 = g2(rho2) #% exact value
|
|
|
|
E2 = g2(rho2) # % exact value
|
|
|
|
>>> np.abs(E2-val2)<err2
|
|
|
|
assert(np.abs(E2 - val2) < err2)
|
|
|
|
True
|
|
|
|
|
|
|
|
|
|
|
|
rho3 = np.random.rand(3)
|
|
|
|
>>> rho3 = np.random.rand(3)
|
|
|
|
a3 = np.zeros(3)
|
|
|
|
>>> a3 = np.zeros(3)
|
|
|
|
b3 = np.repeat(inf, 3)
|
|
|
|
>>> b3 = np.repeat(inf,3)
|
|
|
|
[val3, err3, ift3] = prbnormndpc(rho3, a3, b3)
|
|
|
|
>>> [val3,err3, ift3] = prbnormndpc(rho3,a3,b3)
|
|
|
|
g3 = lambda x: 0.5 - sum(np.sort(np.arccos([x[0] * x[1], x[0] * x[2],
|
|
|
|
>>> g3 = lambda x : 0.5-sum(np.sort(np.arccos([x[0]*x[1],x[0]*x[2],x[1]*x[2]])))/(4*pi)
|
|
|
|
x[1] * x[2]]))) / (4 * pi)
|
|
|
|
>>> E3 = g3(rho3) # Exact value
|
|
|
|
E3 = g3(rho3) # Exact value
|
|
|
|
>>> np.abs(E3-val3)<err2
|
|
|
|
assert(np.abs(E3 - val3) < err3)
|
|
|
|
True
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prbnormnd():
|
|
|
|
def test_prbnormnd():
|
|
|
@ -141,25 +139,22 @@ def test_prbnormnd():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_cdfnorm2d():
|
|
|
|
def test_cdfnorm2d():
|
|
|
|
'''
|
|
|
|
x = np.linspace(-3, 3, 3)
|
|
|
|
>>> x = np.linspace(-3,3,3)
|
|
|
|
[b1, b2] = np.meshgrid(x, x)
|
|
|
|
>>> [b1,b2] = np.meshgrid(x,x)
|
|
|
|
r = 0.3
|
|
|
|
>>> r = 0.3
|
|
|
|
truth = [[2.38515157e-05, 1.14504149e-03, 1.34987703e-03],
|
|
|
|
>>> cdfnorm2d(b1,b2,r)
|
|
|
|
|
|
|
|
array([[ 2.38515157e-05, 1.14504149e-03, 1.34987703e-03],
|
|
|
|
|
|
|
|
[1.14504149e-03, 2.98493342e-01, 4.99795143e-01],
|
|
|
|
[1.14504149e-03, 2.98493342e-01, 4.99795143e-01],
|
|
|
|
[ 1.34987703e-03, 4.99795143e-01, 9.97324055e-01]])
|
|
|
|
[1.34987703e-03, 4.99795143e-01, 9.97324055e-01]]
|
|
|
|
'''
|
|
|
|
assert_array_almost_equal(cdfnorm2d(b1, b2, r), truth)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prbnorm2d():
|
|
|
|
def test_prbnorm2d():
|
|
|
|
'''
|
|
|
|
|
|
|
|
>>> a = [-1, -2]
|
|
|
|
a = [-1, -2]
|
|
|
|
>>> b = [1, 1]
|
|
|
|
b = [1, 1]
|
|
|
|
>>> r = 0.3
|
|
|
|
r = 0.3
|
|
|
|
>>> prbnorm2d(a,b,r)
|
|
|
|
assert_array_almost_equal(prbnorm2d(a,b,r), [ 0.56659121])
|
|
|
|
array([ 0.56659121])
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import doctest
|
|
|
|
import doctest
|
|
|
|
doctest.testmod()
|
|
|
|
doctest.testmod()
|
|
|
|