From 479d730676b41388df3d457e1e42ca4ef824bbfb Mon Sep 17 00:00:00 2001 From: Marvin Pfoertner Date: Wed, 26 Aug 2020 10:31:54 +0200 Subject: [PATCH] Move modules in probnum.core to top level --- benchmarks/random_variables.py | 2 +- src/__init__.py | 0 src/probnum/__init__.py | 4 +-- src/probnum/{core => }/_randomvariablelist.py | 0 src/probnum/core/__init__.py | 31 ------------------- src/probnum/core/random_variables/__init__.py | 19 ------------ .../diffeq/odefiltsmooth/ivp2filter.py | 2 +- .../diffeq/odefiltsmooth/ivpfiltsmooth.py | 2 +- src/probnum/diffeq/odefiltsmooth/prior.py | 2 +- src/probnum/diffeq/odesolution.py | 4 +-- .../gaussfiltsmooth/extendedkalman.py | 2 +- .../gaussfiltsmooth/gaussfiltsmooth.py | 2 +- .../filtsmooth/gaussfiltsmooth/kalman.py | 2 +- .../gaussfiltsmooth/kalmanposterior.py | 2 +- .../gaussfiltsmooth/unscentedkalman.py | 2 +- .../statespace/continuous/linearsdemodel.py | 2 +- .../discrete/discretegaussianmodel.py | 2 +- .../linalg/linearsolvers/matrixbased.py | 2 +- src/probnum/random_variables/__init__.py | 21 +++++++++++++ .../random_variables/_arithmetic.py | 2 +- .../{core => }/random_variables/_dirac.py | 2 +- .../{core => }/random_variables/_normal.py | 2 +- .../random_variables/_random_variable.py | 4 +-- tests/test_diffeq/test_ode/test_ivp.py | 2 +- .../test_odefiltsmooth/test_ivp2filter.py | 2 +- .../test_odefiltsmooth/test_odefiltsmooth.py | 2 +- .../test_odefiltsmooth/test_prior.py | 2 +- tests/test_diffeq/test_odesolution.py | 4 +-- .../filtsmooth_testcases.py | 2 +- .../test_kalmanposterior.py | 2 +- .../test_continuous/test_continuousmodel.py | 2 +- .../test_continuous/test_linearsdemodel.py | 2 +- 32 files changed, 52 insertions(+), 81 deletions(-) delete mode 100644 src/__init__.py rename src/probnum/{core => }/_randomvariablelist.py (100%) delete mode 100644 src/probnum/core/__init__.py delete mode 100644 src/probnum/core/random_variables/__init__.py create mode 100644 src/probnum/random_variables/__init__.py rename src/probnum/{core => }/random_variables/_arithmetic.py (97%) rename src/probnum/{core => }/random_variables/_dirac.py (98%) rename src/probnum/{core => }/random_variables/_normal.py (99%) rename src/probnum/{core => }/random_variables/_random_variable.py (99%) diff --git a/benchmarks/random_variables.py b/benchmarks/random_variables.py index 9674cef3b0..4e00242214 100644 --- a/benchmarks/random_variables.py +++ b/benchmarks/random_variables.py @@ -4,7 +4,7 @@ import numpy as np -from probnum.core import random_variable as rvs +from probnum import random_variables as rvs import probnum.linalg.linops as linops # Module level variables diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/probnum/__init__.py b/src/probnum/__init__.py index 564056ffee..043458e09b 100644 --- a/src/probnum/__init__.py +++ b/src/probnum/__init__.py @@ -28,10 +28,10 @@ from . import filtsmooth from . import linalg from . import quad +from . import random_variables from . import utils -from .core import * - +from .random_variables import asrandvar, RandomVariable # -*- coding: utf-8 -*- from pkg_resources import get_distribution, DistributionNotFound diff --git a/src/probnum/core/_randomvariablelist.py b/src/probnum/_randomvariablelist.py similarity index 100% rename from src/probnum/core/_randomvariablelist.py rename to src/probnum/_randomvariablelist.py diff --git a/src/probnum/core/__init__.py b/src/probnum/core/__init__.py deleted file mode 100644 index daf776bd66..0000000000 --- a/src/probnum/core/__init__.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -Probability and statistics. - -This package implements functionality related to probability theory and statistics such -as random variables and distributions. Random variables are the primary in- and outputs -of probabilistic numerical methods. A generic signature of such methods looks like this: - -.. highlight:: python -.. code-block:: python - - randvar_out, info = probnum_method(problem, randvar_in, **kwargs) - -""" - -from . import random_variables - -from .random_variables import ( - asrandvar, - RandomVariable, - DiscreteRandomVariable, - ContinuousRandomVariable, -) - -# Public classes and functions. Order is reflected in documentation. -__all__ = [ - "random_variables", - "asrandvar", - "RandomVariable", - "DiscreteRandomVariable", - "ContinuousRandomVariable", -] diff --git a/src/probnum/core/random_variables/__init__.py b/src/probnum/core/random_variables/__init__.py deleted file mode 100644 index a38cf7a4e5..0000000000 --- a/src/probnum/core/random_variables/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -from ._random_variable import ( - asrandvar, - RandomVariable, - DiscreteRandomVariable, - ContinuousRandomVariable, -) - -from ._dirac import Dirac -from ._normal import Normal - -# Set correct module paths. Corrects links and module paths in documentation. -asrandvar.__module__ = "probnum.random_variables" - -RandomVariable.__module__ = "probnum.random_variables" -DiscreteRandomVariable.__module__ = "probnum.random_variables" -ContinuousRandomVariable.__module__ = "probnum.random_variables" - -Dirac.__module__ = "probnum.random_variables" -Normal.__module__ = "probnum.random_variables" diff --git a/src/probnum/diffeq/odefiltsmooth/ivp2filter.py b/src/probnum/diffeq/odefiltsmooth/ivp2filter.py index d25a864b5f..5efedc70bd 100644 --- a/src/probnum/diffeq/odefiltsmooth/ivp2filter.py +++ b/src/probnum/diffeq/odefiltsmooth/ivp2filter.py @@ -7,7 +7,7 @@ from probnum.filtsmooth import ExtendedKalman, UnscentedKalman from probnum.filtsmooth.statespace.discrete import DiscreteGaussianModel -from probnum.core import random_variables as rvs +from probnum import random_variables as rvs def ivp2ekf0(ivp, prior, evlvar): diff --git a/src/probnum/diffeq/odefiltsmooth/ivpfiltsmooth.py b/src/probnum/diffeq/odefiltsmooth/ivpfiltsmooth.py index e7fd509420..a18fb17f5d 100644 --- a/src/probnum/diffeq/odefiltsmooth/ivpfiltsmooth.py +++ b/src/probnum/diffeq/odefiltsmooth/ivpfiltsmooth.py @@ -1,7 +1,7 @@ import warnings import numpy as np -from probnum.core.random_variables import Normal +from probnum.random_variables import Normal from probnum.diffeq import odesolver from probnum.diffeq.odefiltsmooth.prior import ODEPrior from probnum.diffeq.odesolution import ODESolution diff --git a/src/probnum/diffeq/odefiltsmooth/prior.py b/src/probnum/diffeq/odefiltsmooth/prior.py index 9be4c7e337..3e610bb5af 100644 --- a/src/probnum/diffeq/odefiltsmooth/prior.py +++ b/src/probnum/diffeq/odefiltsmooth/prior.py @@ -14,7 +14,7 @@ from scipy.special import factorial # vectorised factorial for IBM-Q(h) from probnum.filtsmooth.statespace.continuous import LTISDEModel -from probnum.core.random_variables import Normal +from probnum.random_variables import Normal class ODEPrior(LTISDEModel): diff --git a/src/probnum/diffeq/odesolution.py b/src/probnum/diffeq/odesolution.py index 483c7a4394..b1fa5c63a1 100644 --- a/src/probnum/diffeq/odesolution.py +++ b/src/probnum/diffeq/odesolution.py @@ -5,8 +5,8 @@ Provides dense output by being callable. Can function values can also be accessed by indexing. """ -from probnum.core.random_variables import Normal -from probnum.core._randomvariablelist import _RandomVariableList +from probnum.random_variables import Normal +from probnum._randomvariablelist import _RandomVariableList from probnum.filtsmooth.filtsmoothposterior import FiltSmoothPosterior from probnum.filtsmooth import KalmanPosterior diff --git a/src/probnum/filtsmooth/gaussfiltsmooth/extendedkalman.py b/src/probnum/filtsmooth/gaussfiltsmooth/extendedkalman.py index 0f80fa5b21..5db29dcfab 100644 --- a/src/probnum/filtsmooth/gaussfiltsmooth/extendedkalman.py +++ b/src/probnum/filtsmooth/gaussfiltsmooth/extendedkalman.py @@ -5,7 +5,7 @@ import numpy as np from probnum.filtsmooth.gaussfiltsmooth.gaussfiltsmooth import GaussFiltSmooth -from probnum.core.random_variables import Normal +from probnum.random_variables import Normal from probnum.filtsmooth.statespace import ( ContinuousModel, DiscreteModel, diff --git a/src/probnum/filtsmooth/gaussfiltsmooth/gaussfiltsmooth.py b/src/probnum/filtsmooth/gaussfiltsmooth/gaussfiltsmooth.py index 9acc918db4..f7f3b0c5ce 100644 --- a/src/probnum/filtsmooth/gaussfiltsmooth/gaussfiltsmooth.py +++ b/src/probnum/filtsmooth/gaussfiltsmooth/gaussfiltsmooth.py @@ -5,7 +5,7 @@ import numpy as np -from probnum.core.random_variables import Normal +from probnum.random_variables import Normal from probnum.filtsmooth.bayesfiltsmooth import BayesFiltSmooth from probnum.filtsmooth.gaussfiltsmooth.kalmanposterior import KalmanPosterior diff --git a/src/probnum/filtsmooth/gaussfiltsmooth/kalman.py b/src/probnum/filtsmooth/gaussfiltsmooth/kalman.py index 1e64e266e7..cdabbab185 100644 --- a/src/probnum/filtsmooth/gaussfiltsmooth/kalman.py +++ b/src/probnum/filtsmooth/gaussfiltsmooth/kalman.py @@ -5,7 +5,7 @@ import numpy as np from probnum.filtsmooth.gaussfiltsmooth.gaussfiltsmooth import GaussFiltSmooth -from probnum.core.random_variables import Normal +from probnum.random_variables import Normal from probnum.filtsmooth.statespace import ( ContinuousModel, DiscreteModel, diff --git a/src/probnum/filtsmooth/gaussfiltsmooth/kalmanposterior.py b/src/probnum/filtsmooth/gaussfiltsmooth/kalmanposterior.py index d16d0f208e..a63f0931fa 100644 --- a/src/probnum/filtsmooth/gaussfiltsmooth/kalmanposterior.py +++ b/src/probnum/filtsmooth/gaussfiltsmooth/kalmanposterior.py @@ -9,7 +9,7 @@ import numpy as np -from probnum.core._randomvariablelist import _RandomVariableList +from probnum._randomvariablelist import _RandomVariableList from probnum.filtsmooth.filtsmoothposterior import FiltSmoothPosterior diff --git a/src/probnum/filtsmooth/gaussfiltsmooth/unscentedkalman.py b/src/probnum/filtsmooth/gaussfiltsmooth/unscentedkalman.py index ff9e3d581a..1c1721bff0 100644 --- a/src/probnum/filtsmooth/gaussfiltsmooth/unscentedkalman.py +++ b/src/probnum/filtsmooth/gaussfiltsmooth/unscentedkalman.py @@ -8,7 +8,7 @@ import numpy as np from probnum.filtsmooth.gaussfiltsmooth.gaussfiltsmooth import GaussFiltSmooth -from probnum.core.random_variables import Normal +from probnum.random_variables import Normal from probnum.filtsmooth.gaussfiltsmooth.unscentedtransform import UnscentedTransform from probnum.filtsmooth.statespace import ( ContinuousModel, diff --git a/src/probnum/filtsmooth/statespace/continuous/linearsdemodel.py b/src/probnum/filtsmooth/statespace/continuous/linearsdemodel.py index 1cd261c31e..4b7c97a6e2 100644 --- a/src/probnum/filtsmooth/statespace/continuous/linearsdemodel.py +++ b/src/probnum/filtsmooth/statespace/continuous/linearsdemodel.py @@ -10,7 +10,7 @@ import numpy as np import scipy.linalg from probnum.filtsmooth.statespace.continuous import continuousmodel -from probnum.core.random_variables import Normal +from probnum.random_variables import Normal __all__ = ["LinearSDEModel", "LTISDEModel"] diff --git a/src/probnum/filtsmooth/statespace/discrete/discretegaussianmodel.py b/src/probnum/filtsmooth/statespace/discrete/discretegaussianmodel.py index 39caf3e27a..74211be000 100644 --- a/src/probnum/filtsmooth/statespace/discrete/discretegaussianmodel.py +++ b/src/probnum/filtsmooth/statespace/discrete/discretegaussianmodel.py @@ -3,7 +3,7 @@ x_{i+1} = N(g(i, x_i), S(i)) """ -from probnum.core.random_variables import Normal +from probnum.random_variables import Normal from probnum.filtsmooth.statespace.discrete import discretemodel diff --git a/src/probnum/linalg/linearsolvers/matrixbased.py b/src/probnum/linalg/linearsolvers/matrixbased.py index 0de2093d67..daefda313b 100644 --- a/src/probnum/linalg/linearsolvers/matrixbased.py +++ b/src/probnum/linalg/linearsolvers/matrixbased.py @@ -11,7 +11,7 @@ import GPy import probnum -from probnum.core import random_variables as rvs +from probnum import random_variables as rvs from probnum.linalg import linops diff --git a/src/probnum/random_variables/__init__.py b/src/probnum/random_variables/__init__.py new file mode 100644 index 0000000000..deb3f4ec6a --- /dev/null +++ b/src/probnum/random_variables/__init__.py @@ -0,0 +1,21 @@ +""" +This package implements random variables. Random variables are the primary in- and +outputs of probabilistic numerical methods. A generic signature of such methods looks +like this: + +.. highlight:: python +.. code-block:: python + + randvar_out, info = probnum_method(problem, randvar_in, **kwargs) + +""" + +from ._random_variable import ( + asrandvar, + RandomVariable, + DiscreteRandomVariable, + ContinuousRandomVariable, +) + +from ._dirac import Dirac +from ._normal import Normal diff --git a/src/probnum/core/random_variables/_arithmetic.py b/src/probnum/random_variables/_arithmetic.py similarity index 97% rename from src/probnum/core/random_variables/_arithmetic.py rename to src/probnum/random_variables/_arithmetic.py index 7ae9d6d7f9..4762d1b2f7 100644 --- a/src/probnum/core/random_variables/_arithmetic.py +++ b/src/probnum/random_variables/_arithmetic.py @@ -2,7 +2,7 @@ from typing import Any, Callable, Dict, Tuple, Union from ._random_variable import RandomVariable as _RandomVariable -from probnum.core.random_variables import Dirac as _Dirac, Normal as _Normal +from probnum.random_variables import Dirac as _Dirac, Normal as _Normal def add(rv1: _RandomVariable, rv2: _RandomVariable) -> _RandomVariable: diff --git a/src/probnum/core/random_variables/_dirac.py b/src/probnum/random_variables/_dirac.py similarity index 98% rename from src/probnum/core/random_variables/_dirac.py rename to src/probnum/random_variables/_dirac.py index 7a710ba2ff..d440aee3ec 100644 --- a/src/probnum/core/random_variables/_dirac.py +++ b/src/probnum/random_variables/_dirac.py @@ -148,7 +148,7 @@ def _binary_operator_factory( ) -> Callable[["Dirac", "Dirac"], "Dirac"]: def _dirac_binary_operator(dirac_rv1: Dirac, dirac_rv2: Dirac) -> Dirac: return Dirac( - support=operator(dirac_rv1, dirac_rv2), + support=operator(dirac_rv1.support, dirac_rv2.support), random_state=_utils.derive_random_seed( dirac_rv1.random_state, dirac_rv2.random_state, ), diff --git a/src/probnum/core/random_variables/_normal.py b/src/probnum/random_variables/_normal.py similarity index 99% rename from src/probnum/core/random_variables/_normal.py rename to src/probnum/random_variables/_normal.py index f6cebf3047..51a68f6bfd 100644 --- a/src/probnum/core/random_variables/_normal.py +++ b/src/probnum/random_variables/_normal.py @@ -477,7 +477,7 @@ def _scale(self, scalar, other_random_state=None): ) if scalar == 0: - from probnum.core import random_variables as rvs + from probnum import random_variables as rvs return rvs.Dirac( support=np.zeros_like(self._mean), random_state=derived_random_seed, diff --git a/src/probnum/core/random_variables/_random_variable.py b/src/probnum/random_variables/_random_variable.py similarity index 99% rename from src/probnum/core/random_variables/_random_variable.py rename to src/probnum/random_variables/_random_variable.py index e17f91c9dc..de1b95bbb2 100644 --- a/src/probnum/core/random_variables/_random_variable.py +++ b/src/probnum/random_variables/_random_variable.py @@ -818,7 +818,7 @@ def asrandvar(obj) -> RandomVariable: """ # pylint: disable=import-outside-toplevel - from probnum.core import random_variables as rvs + from probnum import random_variables as rvs # RandomVariable if isinstance(obj, RandomVariable): @@ -868,7 +868,7 @@ def _scipystats_to_rv( """ # pylint: disable=import-outside-toplevel - from probnum.core import random_variables as rvs + from probnum import random_variables as rvs # Univariate distributions (implemented in this package) if isinstance(scipyrv, scipy.stats._distn_infrastructure.rv_frozen): diff --git a/tests/test_diffeq/test_ode/test_ivp.py b/tests/test_diffeq/test_ode/test_ivp.py index ffe72b258c..70939bb680 100644 --- a/tests/test_diffeq/test_ode/test_ivp.py +++ b/tests/test_diffeq/test_ode/test_ivp.py @@ -1,7 +1,7 @@ import unittest import numpy as np from probnum.diffeq.ode import ivp -from probnum.core.random_variables import Dirac +from probnum.random_variables import Dirac from tests.testing import NumpyAssertions TEST_NDIM = 3 diff --git a/tests/test_diffeq/test_odefiltsmooth/test_ivp2filter.py b/tests/test_diffeq/test_odefiltsmooth/test_ivp2filter.py index 07111b81cc..ce22beb583 100644 --- a/tests/test_diffeq/test_odefiltsmooth/test_ivp2filter.py +++ b/tests/test_diffeq/test_odefiltsmooth/test_ivp2filter.py @@ -12,7 +12,7 @@ from probnum.diffeq import IBM, ivp2filter, lotkavolterra from probnum.filtsmooth import ExtendedKalman, UnscentedKalman -from probnum.core.random_variables import Dirac +from probnum.random_variables import Dirac from tests.testing import NumpyAssertions diff --git a/tests/test_diffeq/test_odefiltsmooth/test_odefiltsmooth.py b/tests/test_diffeq/test_odefiltsmooth/test_odefiltsmooth.py index bf88d56a54..77689f8531 100644 --- a/tests/test_diffeq/test_odefiltsmooth/test_odefiltsmooth.py +++ b/tests/test_diffeq/test_odefiltsmooth/test_odefiltsmooth.py @@ -16,7 +16,7 @@ from probnum.diffeq.odefiltsmooth import probsolve_ivp from probnum.diffeq import ode -from probnum.core.random_variables import Dirac +from probnum.random_variables import Dirac from tests.testing import NumpyAssertions diff --git a/tests/test_diffeq/test_odefiltsmooth/test_prior.py b/tests/test_diffeq/test_odefiltsmooth/test_prior.py index eeab2f29c2..55f43c3e72 100644 --- a/tests/test_diffeq/test_odefiltsmooth/test_prior.py +++ b/tests/test_diffeq/test_odefiltsmooth/test_prior.py @@ -10,7 +10,7 @@ import numpy as np -from probnum.core.random_variables import Normal +from probnum.random_variables import Normal from probnum.diffeq.odefiltsmooth import prior from tests.testing import NumpyAssertions diff --git a/tests/test_diffeq/test_odesolution.py b/tests/test_diffeq/test_odesolution.py index 1a2ba0909a..75b8bcdf0c 100644 --- a/tests/test_diffeq/test_odesolution.py +++ b/tests/test_diffeq/test_odesolution.py @@ -1,8 +1,8 @@ import unittest import numpy as np -from probnum.core.random_variables import Dirac -from probnum.core._randomvariablelist import _RandomVariableList +from probnum.random_variables import Dirac +from probnum._randomvariablelist import _RandomVariableList from probnum.diffeq import probsolve_ivp from probnum.diffeq.ode import lotkavolterra, logistic diff --git a/tests/test_filtsmooth/test_gaussfiltsmooth/filtsmooth_testcases.py b/tests/test_filtsmooth/test_gaussfiltsmooth/filtsmooth_testcases.py index 70c788cc22..93b69ad549 100644 --- a/tests/test_filtsmooth/test_gaussfiltsmooth/filtsmooth_testcases.py +++ b/tests/test_filtsmooth/test_gaussfiltsmooth/filtsmooth_testcases.py @@ -12,7 +12,7 @@ generate_cd, DiscreteGaussianModel, ) -from probnum.core.random_variables import Normal +from probnum.random_variables import Normal from tests.testing import NumpyAssertions __all__ = [ diff --git a/tests/test_filtsmooth/test_gaussfiltsmooth/test_kalmanposterior.py b/tests/test_filtsmooth/test_gaussfiltsmooth/test_kalmanposterior.py index 268724cc15..948ea611a6 100644 --- a/tests/test_filtsmooth/test_gaussfiltsmooth/test_kalmanposterior.py +++ b/tests/test_filtsmooth/test_gaussfiltsmooth/test_kalmanposterior.py @@ -1,7 +1,7 @@ import numpy as np from probnum.filtsmooth.gaussfiltsmooth import Kalman -from probnum.core._randomvariablelist import _RandomVariableList +from probnum._randomvariablelist import _RandomVariableList from tests.testing import NumpyAssertions from .filtsmooth_testcases import CarTrackingDDTestCase diff --git a/tests/test_filtsmooth/test_statespace/test_continuous/test_continuousmodel.py b/tests/test_filtsmooth/test_statespace/test_continuous/test_continuousmodel.py index aa08c83f94..5a5a424bb7 100644 --- a/tests/test_filtsmooth/test_statespace/test_continuous/test_continuousmodel.py +++ b/tests/test_filtsmooth/test_statespace/test_continuous/test_continuousmodel.py @@ -2,7 +2,7 @@ import numpy as np -from probnum.core.random_variables import Normal, Dirac +from probnum.random_variables import Normal, Dirac from probnum.filtsmooth.statespace.continuous import continuousmodel VISUALISE = False diff --git a/tests/test_filtsmooth/test_statespace/test_continuous/test_linearsdemodel.py b/tests/test_filtsmooth/test_statespace/test_continuous/test_linearsdemodel.py index 4d19793882..926304aa18 100644 --- a/tests/test_filtsmooth/test_statespace/test_continuous/test_linearsdemodel.py +++ b/tests/test_filtsmooth/test_statespace/test_continuous/test_linearsdemodel.py @@ -2,7 +2,7 @@ import numpy as np -from probnum.core.random_variables import Normal +from probnum.random_variables import Normal from probnum.filtsmooth.statespace.continuous import linearsdemodel TEST_NDIM = 2