Skip to content

Commit

Permalink
renaming models to be less verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
tfm000 committed Nov 4, 2023
1 parent 1544070 commit 413cd6d
Show file tree
Hide file tree
Showing 21 changed files with 253 additions and 288 deletions.
4 changes: 2 additions & 2 deletions examples/copula_examples/copula_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
my_params = (my_chi, my_psi, my_loc, my_shape, my_gamma)

# generating multivariate hyperbolic random variables
from sklarpy.multivariate import multivariate_hyperbolic
from sklarpy.multivariate import mvt_hyperbolic

num_generate: int = 1000
rvs: np.ndarray = multivariate_hyperbolic.rvs(num_generate, my_params)
rvs: np.ndarray = mvt_hyperbolic.rvs(num_generate, my_params)
rvs_df: pd.DataFrame = pd.DataFrame(rvs, columns=['Process A', 'Process B'],
dtype=float)

Expand Down
13 changes: 6 additions & 7 deletions examples/multivariate_examples/multivariate_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
my_mvn_params: tuple = (my_mu, my_cov)

# generating multivariate random normal variables
from sklarpy.multivariate import multivariate_normal
from sklarpy.multivariate import mvt_normal

rvs: np.ndarray = multivariate_normal.rvs(1000, my_mvn_params)
rvs: np.ndarray = mvt_normal.rvs(1000, my_mvn_params)
rvs_df: pd.DataFrame = pd.DataFrame(rvs, columns=['Wife Age', 'Husband Age'],
dtype=float)

# fitting a symmetric hyperbolic dist to our generated data using
# Maximum Likelihood Estimation
from sklarpy.multivariate import multivariate_sym_hyperbolic
from sklarpy.multivariate import mvt_shyperbolic

fitted_msh = multivariate_sym_hyperbolic.fit(rvs_df, method='mle',
show_progress=True)
fitted_msh = mvt_shyperbolic.fit(rvs_df, method='mle', show_progress=True)

# printing our fitted parameters
print(fitted_msh.params.to_dict)
Expand All @@ -48,7 +47,7 @@
# distribution of the same type
from sklarpy import load

loaded_msh_params = load('multivariate_sym_hyperbolic.pickle')
param_fitted_msh = multivariate_sym_hyperbolic.fit(params=loaded_msh_params)
loaded_msh_params = load('mvt_shyperbolic.pickle')
param_fitted_msh = mvt_shyperbolic.fit(params=loaded_msh_params)
print(param_fitted_msh.params.to_dict)
param_fitted_msh.pdf_plot(axes_names=rvs_df.columns)
34 changes: 17 additions & 17 deletions sklarpy/copulas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ Examples of how to use these models can be found in the `examples` folder.

## <u> SklarPy Copula Models </u>

| Family | Name | Dimensions | SklarPy Model |
|----------------|-----------------------------------|--------------|--------------------------------|
| Normal Mixture | Normal / Gaussian | Multivariate | gaussian_copula |
| Normal Mixture | Student-T | Multivariate | student_t_copula |
| Normal Mixture | Skewed-T | Multivariate | skewed_t_copula |
| Normal Mixture | Generalized Hyperbolic | Multivariate | gen_hyperbolic_copula |
| Normal Mixture | Symmetric Generalized Hyperbolic | Multivariate | sym_gen_hyperbolic_copula |
| Normal Mixture | Hyperbolic | Multivariate | hyperbolic_copula |
| Normal Mixture | Symmetric Hyperbolic | Multivariate | sym_hyperbolic_copula |
| Normal Mixture | Normal-Inverse Gaussian (NIG) | Multivariate | nig_copula |
| Normal Mixture | Symmetric Normal-Inverse Gaussian | Multivariate | sym_nig_copula |
| Normal Mixture | Marginal Hyperbolic | Multivariate | marginal_hyperbolic_copula |
| Normal Mixture | Symmetric Marginal Hyperbolic | Multivariate | sym_marginal_hyperbolic_copula |
| Archimedean | Clayton | Multivariate | clayton_copula |
| Archimedean | Gumbel | Multivariate | gumbel_copula |
| Archimedean | Frank | Bivariate | frank_copula |
| Numerical | Gaussian KDE | Multivariate | gaussian_kde_copula |
| Family | Name | Dimensions | SklarPy Model |
|----------------|-----------------------------------|--------------|---------------------|
| Normal Mixture | Normal / Gaussian | Multivariate | gaussian_copula |
| Normal Mixture | Student-T | Multivariate | student_t_copula |
| Normal Mixture | Skewed-T | Multivariate | skewed_t_copula |
| Normal Mixture | Generalized Hyperbolic | Multivariate | gh_copula |
| Normal Mixture | Symmetric Generalized Hyperbolic | Multivariate | sgh_copula |
| Normal Mixture | Hyperbolic | Multivariate | hyperbolic_copula |
| Normal Mixture | Symmetric Hyperbolic | Multivariate | shyperbolic_copula |
| Normal Mixture | Normal-Inverse Gaussian (NIG) | Multivariate | nig_copula |
| Normal Mixture | Symmetric Normal-Inverse Gaussian | Multivariate | snig_copula |
| Normal Mixture | Marginal Hyperbolic | Multivariate | mh_copula |
| Normal Mixture | Symmetric Marginal Hyperbolic | Multivariate | smh_copula |
| Archimedean | Clayton | Multivariate | clayton_copula |
| Archimedean | Gumbel | Multivariate | gumbel_copula |
| Archimedean | Frank | Bivariate | frank_copula |
| Numerical | Gaussian KDE | Multivariate | gaussian_kde_copula |

### Implementation Status
- [x] Normal Mixture
Expand Down
11 changes: 5 additions & 6 deletions sklarpy/copulas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from sklarpy.copulas.marginal_fitter import MarginalFitter
from sklarpy.copulas.distributions import gaussian_copula, \
gaussian_kde_copula, gen_hyperbolic_copula, marginal_hyperbolic_copula, \
hyperbolic_copula, nig_copula, skewed_t_copula, student_t_copula, \
sym_gen_hyperbolic_copula, sym_marginal_hyperbolic_copula, \
sym_hyperbolic_copula, sym_nig_copula, clayton_copula, gumbel_copula, \
frank_copula
from sklarpy.copulas.distributions import (
gaussian_copula, gaussian_kde_copula, gh_copula, mh_copula,
hyperbolic_copula, nig_copula, skewed_t_copula, student_t_copula,
sgh_copula, smh_copula, shyperbolic_copula, snig_copula, clayton_copula,
gumbel_copula, frank_copula)
from sklarpy.copulas.distributions_map import distributions_map
116 changes: 51 additions & 65 deletions sklarpy/copulas/distributions.py
Original file line number Diff line number Diff line change
@@ -1,95 +1,81 @@
# Contains code for building copula models
from sklarpy.copulas._distributions._gaussian import \
gaussian_copula_gen
from sklarpy.copulas._distributions._gaussian_kde import \
gaussian_kde_copula_gen
from sklarpy.copulas._distributions._generalized_hyperbolic import \
gen_hyperbolic_copula_gen
from sklarpy.copulas._distributions._hyperbolics import \
marginal_hyperbolic_copula_gen, hyperbolic_copula_gen, nig_copula_gen
from sklarpy.copulas._distributions._gaussian import gaussian_copula_gen
from sklarpy.copulas._distributions._gaussian_kde import (
gaussian_kde_copula_gen)
from sklarpy.copulas._distributions._generalized_hyperbolic import (
gen_hyperbolic_copula_gen)
from sklarpy.copulas._distributions._hyperbolics import (
marginal_hyperbolic_copula_gen, hyperbolic_copula_gen, nig_copula_gen)
from sklarpy.copulas._distributions._skewed_t import skewed_t_copula_gen
from sklarpy.copulas._distributions._student_t import student_t_copula_gen
from sklarpy.copulas._distributions._symmetric_generalized_hyperbolic import \
sym_gen_hyperbolic_copula_gen
from sklarpy.copulas._distributions._symmetric_hyperbolics import \
sym_marginal_hyperbolic_copula_gen, sym_hyperbolic_copula_gen, \
sym_nig_copula_gen
from sklarpy.copulas._distributions._archimedean import clayton_copula_gen, \
gumbel_copula_gen, frank_copula_gen

from sklarpy.multivariate import multivariate_normal, \
multivariate_gaussian_kde, multivariate_gen_hyperbolic, \
multivariate_marginal_hyperbolic, multivariate_hyperbolic, \
multivariate_nig, multivariate_student_t, multivariate_skewed_t,\
multivariate_sym_gen_hyperbolic, multivariate_sym_marginal_hyperbolic, \
multivariate_sym_hyperbolic, multivariate_sym_nig

from sklarpy.multivariate.distributions import multivariate_clayton, \
multivariate_gumbel, bivariate_frank

__all__ = ['gaussian_copula', 'gaussian_kde_copula', 'gen_hyperbolic_copula',
'marginal_hyperbolic_copula', 'hyperbolic_copula', 'nig_copula',
'skewed_t_copula', 'student_t_copula', 'sym_gen_hyperbolic_copula',
'sym_marginal_hyperbolic_copula', 'sym_hyperbolic_copula',
'sym_nig_copula','clayton_copula', 'gumbel_copula', 'frank_copula']
from sklarpy.copulas._distributions._symmetric_generalized_hyperbolic import (
sym_gen_hyperbolic_copula_gen)
from sklarpy.copulas._distributions._symmetric_hyperbolics import (
sym_marginal_hyperbolic_copula_gen, sym_hyperbolic_copula_gen,
sym_nig_copula_gen)
from sklarpy.copulas._distributions._archimedean import (
clayton_copula_gen, gumbel_copula_gen, frank_copula_gen)

from sklarpy.multivariate import (
mvt_normal, mvt_gaussian_kde, mvt_gh, mvt_mh, mvt_hyperbolic, mvt_nig,
mvt_student_t, mvt_skewed_t, mvt_sgh, mvt_smh, mvt_shyperbolic, mvt_snig)

from sklarpy.multivariate.distributions import (
mvt_clayton, mvt_gumbel, bvt_frank)

__all__ = ['gaussian_copula', 'gaussian_kde_copula', 'gh_copula', 'mh_copula',
'hyperbolic_copula', 'nig_copula', 'skewed_t_copula',
'student_t_copula', 'sgh_copula', 'smh_copula',
'shyperbolic_copula', 'snig_copula', 'clayton_copula',
'gumbel_copula', 'frank_copula']

###############################################################################
# Numerical/Non-Parametric
###############################################################################
gaussian_kde_copula: gaussian_kde_copula_gen = \
gaussian_kde_copula_gen(
name="gaussian_kde", mv_object=multivariate_gaussian_kde)
name="gaussian_kde", mv_object=mvt_gaussian_kde)

###############################################################################
# Parametric
###############################################################################
gaussian_copula: gaussian_copula_gen = \
gaussian_copula_gen(name="gaussian", mv_object=multivariate_normal)
gaussian_copula_gen(name="gaussian", mv_object=mvt_normal)

gen_hyperbolic_copula: gen_hyperbolic_copula_gen = \
gen_hyperbolic_copula_gen(
name="gen_hyperbolic", mv_object=multivariate_gen_hyperbolic)
gh_copula: gen_hyperbolic_copula_gen = gen_hyperbolic_copula_gen(
name="gh", mv_object=mvt_gh)

marginal_hyperbolic_copula: marginal_hyperbolic_copula_gen = \
marginal_hyperbolic_copula_gen(
name="marginal_hyperbolic", mv_object=multivariate_marginal_hyperbolic)
mh_copula: marginal_hyperbolic_copula_gen = marginal_hyperbolic_copula_gen(
name="mh", mv_object=mvt_mh)

hyperbolic_copula: hyperbolic_copula_gen = \
hyperbolic_copula_gen(
name="hyperbolic", mv_object=multivariate_hyperbolic)
hyperbolic_copula: hyperbolic_copula_gen = hyperbolic_copula_gen(
name="hyperbolic", mv_object=mvt_hyperbolic)

nig_copula: nig_copula_gen = \
nig_copula_gen(name="nig", mv_object=multivariate_nig)
nig_copula: nig_copula_gen = nig_copula_gen(name="nig", mv_object=mvt_nig)

skewed_t_copula: skewed_t_copula_gen = \
skewed_t_copula_gen(
name="skewed_t", mv_object=multivariate_skewed_t)
skewed_t_copula: skewed_t_copula_gen = skewed_t_copula_gen(
name="skewed_t", mv_object=mvt_skewed_t)

student_t_copula: student_t_copula_gen = \
student_t_copula_gen(
name="student_t", mv_object=multivariate_student_t)
student_t_copula: student_t_copula_gen = student_t_copula_gen(
name="student_t", mv_object=mvt_student_t)

sym_gen_hyperbolic_copula: sym_gen_hyperbolic_copula_gen = \
sym_gen_hyperbolic_copula_gen(
name="sym_gen_hyperbolic", mv_object=multivariate_sym_gen_hyperbolic)
sgh_copula: sym_gen_hyperbolic_copula_gen = sym_gen_hyperbolic_copula_gen(
name="sgh", mv_object=mvt_sgh)

sym_marginal_hyperbolic_copula: sym_marginal_hyperbolic_copula_gen = \
sym_marginal_hyperbolic_copula_gen(
name="sym_marginal_hyperbolic",
mv_object=multivariate_sym_marginal_hyperbolic)
smh_copula: sym_marginal_hyperbolic_copula_gen = \
sym_marginal_hyperbolic_copula_gen(name="smh", mv_object=mvt_smh)

sym_hyperbolic_copula: sym_hyperbolic_copula_gen = \
sym_hyperbolic_copula_gen(name="sym_hyperbolic",
mv_object=multivariate_sym_hyperbolic)
shyperbolic_copula: sym_hyperbolic_copula_gen = sym_hyperbolic_copula_gen(
name="shyperbolic", mv_object=mvt_shyperbolic)

sym_nig_copula: sym_nig_copula_gen = \
sym_nig_copula_gen(name="sym_nig", mv_object=multivariate_sym_nig)
snig_copula: sym_nig_copula_gen = sym_nig_copula_gen(
name="snig", mv_object=mvt_snig)

clayton_copula: clayton_copula_gen = \
clayton_copula_gen(name="clayton", mv_object=multivariate_clayton)
clayton_copula_gen(name="clayton", mv_object=mvt_clayton)

gumbel_copula: gumbel_copula_gen = \
gumbel_copula_gen(name="gumbel", mv_object=multivariate_gumbel)
gumbel_copula_gen(name="gumbel", mv_object=mvt_gumbel)

frank_copula: frank_copula_gen = \
frank_copula_gen(name="frank", mv_object=bivariate_frank)
frank_copula_gen(name="frank", mv_object=bvt_frank)
12 changes: 6 additions & 6 deletions sklarpy/copulas/distributions_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
'gumbel_copula',
'frank_copula',
'gaussian_copula',
'gen_hyperbolic_copula',
'marginal_hyperbolic_copula',
'gh_copula',
'mh_copula',
'hyperbolic_copula',
'nig_copula',
'skewed_t_copula',
'student_t_copula',
'sym_gen_hyperbolic_copula',
'sym_marginal_hyperbolic_copula',
'sym_hyperbolic_copula',
'sym_nig_copula',
'sgh_copula',
'smh_copula',
'shyperbolic_copula',
'snig_copula',
)

###############################################################################
Expand Down
28 changes: 14 additions & 14 deletions sklarpy/multivariate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ Examples of how to use these models can be found in the `examples` folder.

## <u> SklarPy Multivariate Models </u>

| Family | Name | Dimensions | SklarPy Model |
|----------------|-----------------------------------|--------------|--------------------------------------|
| Normal Mixture | Normal / Gaussian | Multivariate | multivariate_normal |
| Normal Mixture | Student-T | Multivariate | multivariate_student_t |
| Normal Mixture | Skewed-T | Multivariate | multivariate_skewed_t |
| Normal Mixture | Generalized Hyperbolic | Multivariate | multivariate_gen_hyperbolic |
| Normal Mixture | Symmetric Generalized Hyperbolic | Multivariate | multivariate_sym_gen_hyperbolic |
| Normal Mixture | Hyperbolic | Multivariate | multivariate_hyperbolic |
| Normal Mixture | Symmetric Hyperbolic | Multivariate | multivariate_sym_hyperbolic |
| Normal Mixture | Normal-Inverse Gaussian (NIG) | Multivariate | multivariate_nig |
| Normal Mixture | Symmetric Normal-Inverse Gaussian | Multivariate | multivariate_sym_nig |
| Normal Mixture | Marginal Hyperbolic | Multivariate | multivariate_marginal_hyperbolic |
| Normal Mixture | Symmetric Marginal Hyperbolic | Multivariate | multivariate_sym_marginal_hyperbolic |
| Numerical | Gaussian KDE | Multivariate | multivariate_gaussian_kde |
| Family | Name | Dimensions | SklarPy Model |
|----------------|-----------------------------------|--------------|------------------|
| Normal Mixture | Normal / Gaussian | Multivariate | mvt_normal |
| Normal Mixture | Student-T | Multivariate | mvt_student_t |
| Normal Mixture | Skewed-T | Multivariate | mvt_skewed_t |
| Normal Mixture | Generalized Hyperbolic | Multivariate | mvt_gh |
| Normal Mixture | Symmetric Generalized Hyperbolic | Multivariate | mvt_sgh |
| Normal Mixture | Hyperbolic | Multivariate | mvt_hyperbolic |
| Normal Mixture | Symmetric Hyperbolic | Multivariate | mvt_shyperbolic |
| Normal Mixture | Normal-Inverse Gaussian (NIG) | Multivariate | mvt_nig |
| Normal Mixture | Symmetric Normal-Inverse Gaussian | Multivariate | mvt_snig |
| Normal Mixture | Marginal Hyperbolic | Multivariate | mvt_mh |
| Normal Mixture | Symmetric Marginal Hyperbolic | Multivariate | mvt_smh |
| Numerical | Gaussian KDE | Multivariate | mvt_gaussian_kde |

### Implementation Status
- [x] Normal Mixture
Expand Down
9 changes: 3 additions & 6 deletions sklarpy/multivariate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from sklarpy.multivariate.distributions import multivariate_gaussian_kde, \
multivariate_gen_hyperbolic, multivariate_marginal_hyperbolic, \
multivariate_hyperbolic, multivariate_nig, multivariate_normal, \
multivariate_skewed_t, multivariate_student_t, \
multivariate_sym_gen_hyperbolic, multivariate_sym_marginal_hyperbolic, \
multivariate_sym_hyperbolic, multivariate_sym_nig
from sklarpy.multivariate.distributions import (
mvt_gaussian_kde, mvt_gh, mvt_mh, mvt_hyperbolic, mvt_nig, mvt_normal,
mvt_skewed_t, mvt_student_t, mvt_sgh, mvt_smh, mvt_shyperbolic, mvt_snig)

from sklarpy.multivariate.distributions_map import distributions_map
12 changes: 6 additions & 6 deletions sklarpy/multivariate/_params/_archimedean.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Contains code for holding Archimedean copula parameters
from sklarpy._utils import Params

__all__ = ['MultivariateClaytonParams', 'MultivariateGumbelParams',
'BivariateFrankParams']
__all__ = ['MvtClaytonParams', 'MvtGumbelParams',
'BvtFrankParams']


class MultivariateArchimedeanParamsBase(Params):
class MvtArchimedeanParamsBase(Params):
"""Base class containing the fitted parameters of an Archimedean Copula."""
@property
def theta(self) -> float:
Expand All @@ -32,13 +32,13 @@ def d(self) -> int:
return self.to_dict['d']


class MultivariateClaytonParams(MultivariateArchimedeanParamsBase):
class MvtClaytonParams(MvtArchimedeanParamsBase):
"""Contains the fitted parameters of a Clayton Copula."""


class MultivariateGumbelParams(MultivariateArchimedeanParamsBase):
class MvtGumbelParams(MvtArchimedeanParamsBase):
"""Contains the fitted parameters of a Gumbel Copula."""


class BivariateFrankParams(MultivariateArchimedeanParamsBase):
class BvtFrankParams(MvtArchimedeanParamsBase):
"""Contains the fitted parameters of a Frank Copula."""
4 changes: 2 additions & 2 deletions sklarpy/multivariate/_params/_gaussian_kde.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Contains code for holding Gaussian KDE parameters.
from sklarpy._utils import Params

__all__ = ['MultivariateGaussianKDEParams']
__all__ = ['MvtGaussianKDEParams']


class MultivariateGaussianKDEParams(Params):
class MvtGaussianKDEParams(Params):
"""Contains the fitted parameters of a Multivariate Gaussian KDE
distribution."""
@property
Expand Down
6 changes: 3 additions & 3 deletions sklarpy/multivariate/_params/_generalized_hyperbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import numpy as np

from sklarpy.multivariate._params._symmetric_generalized_hyperbolic import \
MultivariateSymGenHyperbolicParams
MvtSGHParams
from sklarpy.multivariate._distributions._generalized_hyperbolic import \
multivariate_gen_hyperbolic_gen

__all__ = ['MultivariateGenHyperbolicParams']
__all__ = ['MvtGHParams']


class MultivariateGenHyperbolicParams(MultivariateSymGenHyperbolicParams):
class MvtGHParams(MvtSGHParams):
"""Contains the fitted parameters of a Multivariate Generalized Hyperbolic
distribution."""
_DIST_GENERATOR = multivariate_gen_hyperbolic_gen
Expand Down
Loading

0 comments on commit 413cd6d

Please sign in to comment.