From 90cb785181fd82b3b3c347355af39a580ef191db Mon Sep 17 00:00:00 2001 From: Xun Deng Date: Tue, 28 Jul 2020 12:06:21 -0400 Subject: [PATCH] move nn/distribution to nn/probability/distribution --- mindspore/nn/__init__.py | 6 ++--- mindspore/nn/probability/__init__.py | 24 +++++++++++++++++++ .../distribution/__init__.py | 0 .../distribution/_utils/__init__.py | 0 .../distribution/_utils/utils.py | 6 ++--- .../distribution/bernoulli.py | 2 +- .../distribution/distribution.py | 2 +- .../distribution/exponential.py | 2 +- .../distribution/geometric.py | 2 +- .../{ => probability}/distribution/normal.py | 5 ++-- .../{ => probability}/distribution/uniform.py | 2 +- 11 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 mindspore/nn/probability/__init__.py rename mindspore/nn/{ => probability}/distribution/__init__.py (100%) rename mindspore/nn/{ => probability}/distribution/_utils/__init__.py (100%) rename mindspore/nn/{ => probability}/distribution/_utils/utils.py (97%) rename mindspore/nn/{ => probability}/distribution/bernoulli.py (99%) rename mindspore/nn/{ => probability}/distribution/distribution.py (99%) rename mindspore/nn/{ => probability}/distribution/exponential.py (99%) rename mindspore/nn/{ => probability}/distribution/geometric.py (99%) rename mindspore/nn/{ => probability}/distribution/normal.py (99%) rename mindspore/nn/{ => probability}/distribution/uniform.py (99%) diff --git a/mindspore/nn/__init__.py b/mindspore/nn/__init__.py index e5c133a9a..87ff3814a 100644 --- a/mindspore/nn/__init__.py +++ b/mindspore/nn/__init__.py @@ -17,14 +17,14 @@ Neural Networks Cells. Pre-defined building blocks or computing units to construct Neural Networks. """ -from . import layer, loss, optim, metrics, wrap, distribution +from . import layer, loss, optim, metrics, wrap, probability from .cell import Cell, GraphKernel from .layer import * from .loss import * from .optim import * from .metrics import * from .wrap import * -from .distribution import * +from .probability import * __all__ = ["Cell", "GraphKernel"] @@ -33,7 +33,7 @@ __all__.extend(loss.__all__) __all__.extend(optim.__all__) __all__.extend(metrics.__all__) __all__.extend(wrap.__all__) -__all__.extend(distribution.__all__) +__all__.extend(probability.__all__) __all__.sort() diff --git a/mindspore/nn/probability/__init__.py b/mindspore/nn/probability/__init__.py new file mode 100644 index 000000000..7a7d3f226 --- /dev/null +++ b/mindspore/nn/probability/__init__.py @@ -0,0 +1,24 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +""" +Probability. + +The high-level components(Distributions) used to construct the probabilistic network. +""" + +from .distribution import * + +__all__ = [] +__all__.extend(distribution.__all__) diff --git a/mindspore/nn/distribution/__init__.py b/mindspore/nn/probability/distribution/__init__.py similarity index 100% rename from mindspore/nn/distribution/__init__.py rename to mindspore/nn/probability/distribution/__init__.py diff --git a/mindspore/nn/distribution/_utils/__init__.py b/mindspore/nn/probability/distribution/_utils/__init__.py similarity index 100% rename from mindspore/nn/distribution/_utils/__init__.py rename to mindspore/nn/probability/distribution/_utils/__init__.py diff --git a/mindspore/nn/distribution/_utils/utils.py b/mindspore/nn/probability/distribution/_utils/utils.py similarity index 97% rename from mindspore/nn/distribution/_utils/utils.py rename to mindspore/nn/probability/distribution/_utils/utils.py index e37f9d632..3f7a92a31 100644 --- a/mindspore/nn/distribution/_utils/utils.py +++ b/mindspore/nn/probability/distribution/_utils/utils.py @@ -16,9 +16,9 @@ """Utitly functions to help distribution class.""" import numpy as np from mindspore.ops import _utils as utils -from ....common.tensor import Tensor -from ....common.parameter import Parameter -from ....common import dtype as mstype +from mindspore.common.tensor import Tensor +from mindspore.common.parameter import Parameter +from mindspore.common import dtype as mstype def cast_to_tensor(t, dtype=mstype.float32): """ diff --git a/mindspore/nn/distribution/bernoulli.py b/mindspore/nn/probability/distribution/bernoulli.py similarity index 99% rename from mindspore/nn/distribution/bernoulli.py rename to mindspore/nn/probability/distribution/bernoulli.py index f04732679..cab74f97f 100644 --- a/mindspore/nn/distribution/bernoulli.py +++ b/mindspore/nn/probability/distribution/bernoulli.py @@ -13,10 +13,10 @@ # limitations under the License. # ============================================================================ """Bernoulli Distribution""" +from mindspore.common import dtype as mstype from mindspore.ops import operations as P from .distribution import Distribution from ._utils.utils import cast_to_tensor, check_prob -from ...common import dtype as mstype class Bernoulli(Distribution): """ diff --git a/mindspore/nn/distribution/distribution.py b/mindspore/nn/probability/distribution/distribution.py similarity index 99% rename from mindspore/nn/distribution/distribution.py rename to mindspore/nn/probability/distribution/distribution.py index 52e23f0e9..9f1e1a120 100644 --- a/mindspore/nn/distribution/distribution.py +++ b/mindspore/nn/probability/distribution/distribution.py @@ -13,7 +13,7 @@ # limitations under the License. # ============================================================================ """basic""" -from ..cell import Cell +from mindspore.nn.cell import Cell from ._utils.utils import calc_broadcast_shape_from_param, check_scalar_from_param class Distribution(Cell): diff --git a/mindspore/nn/distribution/exponential.py b/mindspore/nn/probability/distribution/exponential.py similarity index 99% rename from mindspore/nn/distribution/exponential.py rename to mindspore/nn/probability/distribution/exponential.py index 9816369e0..4f37ca776 100644 --- a/mindspore/nn/distribution/exponential.py +++ b/mindspore/nn/probability/distribution/exponential.py @@ -15,8 +15,8 @@ """Exponential Distribution""" import numpy as np from mindspore.ops import operations as P +from mindspore.common import dtype as mstype from .distribution import Distribution -from ...common import dtype as mstype from ._utils.utils import cast_to_tensor, check_greater_zero class Exponential(Distribution): diff --git a/mindspore/nn/distribution/geometric.py b/mindspore/nn/probability/distribution/geometric.py similarity index 99% rename from mindspore/nn/distribution/geometric.py rename to mindspore/nn/probability/distribution/geometric.py index 0a9da3b24..cac194e11 100644 --- a/mindspore/nn/distribution/geometric.py +++ b/mindspore/nn/probability/distribution/geometric.py @@ -15,9 +15,9 @@ """Geometric Distribution""" import numpy as np from mindspore.ops import operations as P +from mindspore.common import dtype as mstype from .distribution import Distribution from ._utils.utils import cast_to_tensor, check_prob -from ...common import dtype as mstype class Geometric(Distribution): """ diff --git a/mindspore/nn/distribution/normal.py b/mindspore/nn/probability/distribution/normal.py similarity index 99% rename from mindspore/nn/distribution/normal.py rename to mindspore/nn/probability/distribution/normal.py index 7bfea6c7e..aae9b3963 100644 --- a/mindspore/nn/distribution/normal.py +++ b/mindspore/nn/probability/distribution/normal.py @@ -16,10 +16,11 @@ import numpy as np from mindspore.ops import operations as P from mindspore.ops import composite as C +from mindspore.common import dtype as mstype +from mindspore.context import get_context from .distribution import Distribution from ._utils.utils import convert_to_batch, check_greater_equal_zero -from ...common import dtype as mstype -from ...context import get_context + class Normal(Distribution): """ diff --git a/mindspore/nn/distribution/uniform.py b/mindspore/nn/probability/distribution/uniform.py similarity index 99% rename from mindspore/nn/distribution/uniform.py rename to mindspore/nn/probability/distribution/uniform.py index 3b90bbe73..0c0d73f3e 100644 --- a/mindspore/nn/distribution/uniform.py +++ b/mindspore/nn/probability/distribution/uniform.py @@ -14,8 +14,8 @@ # ============================================================================ """Uniform Distribution""" from mindspore.ops import operations as P +from mindspore.common import dtype as mstype from .distribution import Distribution -from ...common import dtype as mstype from ._utils.utils import convert_to_batch, check_greater class Uniform(Distribution): -- GitLab