From 792ecd5ff5b6254a2f53e0a05c7b080ed14aac50 Mon Sep 17 00:00:00 2001 From: hageldave Date: Fri, 13 Sep 2024 14:27:50 +0200 Subject: [PATCH] CamelCase convention for class names: distribution -> Distribution --- examples/ownData.ipynb | 2 +- tests/api_consistency_test.py | 2 +- tests/test_distrib.py | 6 +++--- uadapy/__init__.py | 4 ++-- uadapy/data/data.py | 6 +++--- uadapy/distribution.py | 2 +- uadapy/dr/uamds.py | 4 ++-- uadapy/dr/uapca.py | 4 ++-- uadapy/plotting/plots1D.py | 4 ++-- uadapy/plotting/plots2D.py | 8 ++++---- uadapy/plotting/plotsND.py | 8 ++++---- 11 files changed, 25 insertions(+), 25 deletions(-) diff --git a/examples/ownData.ipynb b/examples/ownData.ipynb index ef69cae..c5a3ec1 100644 --- a/examples/ownData.ipynb +++ b/examples/ownData.ipynb @@ -53,7 +53,7 @@ "wine = datasets.load_wine()\n", "dist = []\n", "for c in np.unique(wine.target):\n", - " dist.append(ua.distribution(np.array(wine.data[wine.target == c]), \"Normal\"))" + " dist.append(ua.Distribution(np.array(wine.data[wine.target == c]), \"Normal\"))" ] }, { diff --git a/tests/api_consistency_test.py b/tests/api_consistency_test.py index b897a57..d25162f 100644 --- a/tests/api_consistency_test.py +++ b/tests/api_consistency_test.py @@ -20,7 +20,7 @@ def test_dr_module(): import uadapy.distribution import numpy as np # list of distributions (normal distributions estimated from random data - distribs = [uadapy.distribution(np.random.rand(10, 3), name='Normal') for _ in range(4)] + distribs = [uadapy.Distribution(np.random.rand(10, 3), name='Normal') for _ in range(4)] uadapy.dr.uapca(distributions=distribs, n_dims=2) uadapy.dr.uamds(distributions=distribs, n_dims=2) diff --git a/tests/test_distrib.py b/tests/test_distrib.py index 1046b1c..601135d 100644 --- a/tests/test_distrib.py +++ b/tests/test_distrib.py @@ -3,7 +3,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import traceback -from uadapy import distribution +from uadapy import Distribution import numpy as np import scipy as sp import scipy.stats as st @@ -71,11 +71,11 @@ def test_distrib_class(): # initialize distribution object for each of the scipy distribs (univariate) for scipi_distrib in model_1D: - distrib = distribution(scipi_distrib) + distrib = Distribution(scipi_distrib) # initialize distribution object for each of the scipy distribs (multivariate) for scipi_distrib in model_nD: try: - distrib = distribution(scipi_distrib) + distrib = Distribution(scipi_distrib) cov = distrib.cov() if cov.shape[0] != n or cov.shape[1] != n: raise RuntimeError(f"shape expected to be {n} x {n}, but was {cov.shape}") diff --git a/uadapy/__init__.py b/uadapy/__init__.py index 19fb358..224430f 100644 --- a/uadapy/__init__.py +++ b/uadapy/__init__.py @@ -1,3 +1,3 @@ -from .distribution import distribution +from .distribution import Distribution -__all__ = ['distribution'] +__all__ = ['Distribution'] diff --git a/uadapy/data/data.py b/uadapy/data/data.py index 59948c4..91f7d4e 100644 --- a/uadapy/data/data.py +++ b/uadapy/data/data.py @@ -1,6 +1,6 @@ from sklearn import datasets import numpy as np -from uadapy import distribution +from uadapy import Distribution def load_iris_normal(): """ @@ -10,7 +10,7 @@ def load_iris_normal(): iris = datasets.load_iris() dist = [] for c in np.unique(iris.target): - dist.append(distribution(np.array(iris.data[iris.target == c]), "Normal")) + dist.append(Distribution(np.array(iris.data[iris.target == c]), "Normal")) return dist def load_iris(): @@ -21,5 +21,5 @@ def load_iris(): iris = datasets.load_iris() dist = [] for c in np.unique(iris.target): - dist.append(distribution(np.array(iris.data[iris.target == c]))) + dist.append(Distribution(np.array(iris.data[iris.target == c]))) return dist diff --git a/uadapy/distribution.py b/uadapy/distribution.py index 46dd174..1491a9d 100644 --- a/uadapy/distribution.py +++ b/uadapy/distribution.py @@ -4,7 +4,7 @@ from scipy.stats import _multivariate as mv -class distribution: +class Distribution: def __init__(self, model, name="", n_dims=1): """ diff --git a/uadapy/dr/uamds.py b/uadapy/dr/uamds.py index dc9cc98..2e48039 100644 --- a/uadapy/dr/uamds.py +++ b/uadapy/dr/uamds.py @@ -13,7 +13,7 @@ from scipy.spatial import distance_matrix from scipy.optimize import minimize from scipy.stats import multivariate_normal -from uadapy import distribution +from uadapy import Distribution def precalculate_constants(normal_distr_spec: np.ndarray) -> tuple: @@ -549,7 +549,7 @@ def uamds(distributions: list, n_dims: int = 2, seed: int = 0): result = apply_uamds(means, covs, n_dims) distribs_lo = [] for (m, c) in zip(result['means'], result['covs']): - distribs_lo.append(distribution(multivariate_normal(m, c))) + distribs_lo.append(Distribution(multivariate_normal(m, c))) return distribs_lo except Exception as e: raise Exception(f'Something went wrong. Did you input normal distributions? Exception:{e}') diff --git a/uadapy/dr/uapca.py b/uadapy/dr/uapca.py index 423bd2c..66c1ee2 100644 --- a/uadapy/dr/uapca.py +++ b/uadapy/dr/uapca.py @@ -1,5 +1,5 @@ import numpy as np -from uadapy import distribution +from uadapy import Distribution from scipy.stats import multivariate_normal def uapca(distributions, n_dims: int = 2): @@ -18,7 +18,7 @@ def uapca(distributions, n_dims: int = 2): means_pca, covs_pca = transform_uapca(means, covs, n_dims) dist_pca = [] for (m, c) in zip(means_pca, covs_pca): - dist_pca.append(distribution(multivariate_normal(m, c))) + dist_pca.append(Distribution(multivariate_normal(m, c))) return dist_pca except Exception as e: raise Exception(f'Something went wrong. Did you input normal distributions? Exception:{e}') diff --git a/uadapy/plotting/plots1D.py b/uadapy/plotting/plots1D.py index 333ad0b..90be583 100644 --- a/uadapy/plotting/plots1D.py +++ b/uadapy/plotting/plots1D.py @@ -1,5 +1,5 @@ import numpy as np -from uadapy import distribution +from uadapy import Distribution import matplotlib.pyplot as plt from math import ceil, sqrt import glasbey as gb @@ -67,7 +67,7 @@ def setup_plot(distributions, num_samples, seed, fig=None, axs=None, colors=None samples = [] - if isinstance(distributions, distribution): + if isinstance(distributions, Distribution): distributions = [distributions] # Calculate the layout of subplots diff --git a/uadapy/plotting/plots2D.py b/uadapy/plotting/plots2D.py index 221aba5..7a38088 100644 --- a/uadapy/plotting/plots2D.py +++ b/uadapy/plotting/plots2D.py @@ -1,6 +1,6 @@ import matplotlib.pyplot as plt import numpy as np -from uadapy import distribution +from uadapy import Distribution from numpy import ma from matplotlib import ticker @@ -35,7 +35,7 @@ def plot_samples(distributions, num_samples, seed=55, **kwargs): List of Axes objects used for plotting. """ - if isinstance(distributions, distribution): + if isinstance(distributions, Distribution): distributions = [distributions] for d in distributions: samples = d.sample(num_samples, seed) @@ -93,7 +93,7 @@ def plot_contour(distributions, resolution=128, ranges=None, quantiles:list=None If a quantile is not between 0 and 100 (exclusive), or if a quantile results in an index that is out of bounds. """ - if isinstance(distributions, distribution): + if isinstance(distributions, Distribution): distributions = [distributions] contour_colors = generate_spectrum_colors(len(distributions)) @@ -188,7 +188,7 @@ def plot_contour_bands(distributions, num_samples, resolution=128, ranges=None, If a quantile is not between 0 and 100 (exclusive), or if a quantile results in an index that is out of bounds. """ - if isinstance(distributions, distribution): + if isinstance(distributions, Distribution): distributions = [distributions] # Sequential and perceptually uniform colormaps diff --git a/uadapy/plotting/plotsND.py b/uadapy/plotting/plotsND.py index acc5a1f..073300a 100644 --- a/uadapy/plotting/plotsND.py +++ b/uadapy/plotting/plotsND.py @@ -1,6 +1,6 @@ import matplotlib.pyplot as plt import numpy as np -from uadapy import distribution +from uadapy import Distribution import uadapy.plotting.utils as utils def plot_samples(distributions, num_samples, seed=55, **kwargs): @@ -29,7 +29,7 @@ def plot_samples(distributions, num_samples, seed=55, **kwargs): List of Axes objects used for plotting. """ - if isinstance(distributions, distribution): + if isinstance(distributions, Distribution): distributions = [distributions] # Create matrix numvars = distributions[0].n_dims @@ -110,7 +110,7 @@ def plot_contour(distributions, num_samples, resolution=128, ranges=None, quanti If the dimension of the distribution is less than 2. """ - if isinstance(distributions, distribution): + if isinstance(distributions, Distribution): distributions = [distributions] contour_colors = utils.generate_spectrum_colors(len(distributions)) # Create matrix @@ -239,7 +239,7 @@ def plot_contour_samples(distributions, num_samples, resolution=128, ranges=None If the dimension of the distribution is less than 2. """ - if isinstance(distributions, distribution): + if isinstance(distributions, Distribution): distributions = [distributions] contour_colors = utils.generate_spectrum_colors(len(distributions)) # Create matrix