Skip to content

Commit

Permalink
CamelCase convention for class names: distribution -> Distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
hageldave committed Sep 13, 2024
1 parent bec5e20 commit 792ecd5
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/ownData.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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\"))"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/api_consistency_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_distrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand Down
4 changes: 2 additions & 2 deletions uadapy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .distribution import distribution
from .distribution import Distribution

__all__ = ['distribution']
__all__ = ['Distribution']
6 changes: 3 additions & 3 deletions uadapy/data/data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sklearn import datasets
import numpy as np
from uadapy import distribution
from uadapy import Distribution

def load_iris_normal():
"""
Expand All @@ -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():
Expand All @@ -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
2 changes: 1 addition & 1 deletion uadapy/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from scipy.stats import _multivariate as mv


class distribution:
class Distribution:

def __init__(self, model, name="", n_dims=1):
"""
Expand Down
4 changes: 2 additions & 2 deletions uadapy/dr/uamds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}')
Expand Down
4 changes: 2 additions & 2 deletions uadapy/dr/uapca.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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}')
Expand Down
4 changes: 2 additions & 2 deletions uadapy/plotting/plots1D.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions uadapy/plotting/plots2D.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions uadapy/plotting/plotsND.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 792ecd5

Please sign in to comment.