|
|
|
@ -12,11 +12,12 @@
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
# ============================================================================
|
|
|
|
|
"""test cases for normal distribution"""
|
|
|
|
|
"""test cases for Normal distribution"""
|
|
|
|
|
import numpy as np
|
|
|
|
|
from scipy import stats
|
|
|
|
|
import mindspore.context as context
|
|
|
|
|
import mindspore.nn as nn
|
|
|
|
|
import mindspore.nn.probability.distribution as msd
|
|
|
|
|
from mindspore import Tensor
|
|
|
|
|
from mindspore.common.api import ms_function
|
|
|
|
|
from mindspore import dtype
|
|
|
|
@ -29,7 +30,7 @@ class Prob(nn.Cell):
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(Prob, self).__init__()
|
|
|
|
|
self.n = nn.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
self.n = msd.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
|
|
|
|
|
@ms_function
|
|
|
|
|
def construct(self, x_):
|
|
|
|
@ -52,7 +53,7 @@ class LogProb(nn.Cell):
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(LogProb, self).__init__()
|
|
|
|
|
self.n = nn.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
self.n = msd.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
|
|
|
|
|
@ms_function
|
|
|
|
|
def construct(self, x_):
|
|
|
|
@ -76,7 +77,7 @@ class KL(nn.Cell):
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(KL, self).__init__()
|
|
|
|
|
self.n = nn.Normal(np.array([3.0]), np.array([4.0]), dtype=dtype.float32)
|
|
|
|
|
self.n = msd.Normal(np.array([3.0]), np.array([4.0]), dtype=dtype.float32)
|
|
|
|
|
|
|
|
|
|
@ms_function
|
|
|
|
|
def construct(self, x_, y_):
|
|
|
|
@ -110,7 +111,7 @@ class Basics(nn.Cell):
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(Basics, self).__init__()
|
|
|
|
|
self.n = nn.Normal(np.array([3.0]), np.array([2.0, 4.0]), dtype=dtype.float32)
|
|
|
|
|
self.n = msd.Normal(np.array([3.0]), np.array([2.0, 4.0]), dtype=dtype.float32)
|
|
|
|
|
|
|
|
|
|
@ms_function
|
|
|
|
|
def construct(self):
|
|
|
|
@ -135,7 +136,7 @@ class Sampling(nn.Cell):
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self, shape, seed=0):
|
|
|
|
|
super(Sampling, self).__init__()
|
|
|
|
|
self.n = nn.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), seed=seed, dtype=dtype.float32)
|
|
|
|
|
self.n = msd.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), seed=seed, dtype=dtype.float32)
|
|
|
|
|
self.shape = shape
|
|
|
|
|
|
|
|
|
|
@ms_function
|
|
|
|
@ -160,7 +161,7 @@ class CDF(nn.Cell):
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(CDF, self).__init__()
|
|
|
|
|
self.n = nn.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
self.n = msd.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
|
|
|
|
|
@ms_function
|
|
|
|
|
def construct(self, x_):
|
|
|
|
@ -184,7 +185,7 @@ class LogCDF(nn.Cell):
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(LogCDF, self).__init__()
|
|
|
|
|
self.n = nn.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
self.n = msd.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
|
|
|
|
|
@ms_function
|
|
|
|
|
def construct(self, x_):
|
|
|
|
@ -207,7 +208,7 @@ class SF(nn.Cell):
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(SF, self).__init__()
|
|
|
|
|
self.n = nn.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
self.n = msd.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
|
|
|
|
|
@ms_function
|
|
|
|
|
def construct(self, x_):
|
|
|
|
@ -230,7 +231,7 @@ class LogSF(nn.Cell):
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(LogSF, self).__init__()
|
|
|
|
|
self.n = nn.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
self.n = msd.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
|
|
|
|
|
@ms_function
|
|
|
|
|
def construct(self, x_):
|
|
|
|
@ -253,7 +254,7 @@ class EntropyH(nn.Cell):
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(EntropyH, self).__init__()
|
|
|
|
|
self.n = nn.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
self.n = msd.Normal(np.array([3.0]), np.array([[2.0], [4.0]]), dtype=dtype.float32)
|
|
|
|
|
|
|
|
|
|
@ms_function
|
|
|
|
|
def construct(self):
|
|
|
|
@ -276,7 +277,7 @@ class CrossEntropy(nn.Cell):
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(CrossEntropy, self).__init__()
|
|
|
|
|
self.n = nn.Normal(np.array([3.0]), np.array([4.0]), dtype=dtype.float32)
|
|
|
|
|
self.n = msd.Normal(np.array([3.0]), np.array([4.0]), dtype=dtype.float32)
|
|
|
|
|
|
|
|
|
|
@ms_function
|
|
|
|
|
def construct(self, x_, y_):
|
|
|
|
|