Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify cumulative_distribution function #220

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions copulas/univariate/gaussian_kde.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import numpy as np
import pandas as pd
from scipy.special import ndtr
from scipy.stats import gaussian_kde

Expand Down Expand Up @@ -39,10 +40,10 @@ def _get_model(self):

def _get_bounds(self):
X = self._params['dataset']
lower = np.min(X) - (5 * np.std(X))
upper = np.max(X) + (5 * np.std(X))
self._lower = np.min(X) - (5 * np.std(X))
self._upper = np.max(X) + (5 * np.std(X))

return lower, upper
return self._lower, self._upper

def probability_density(self, X):
"""Compute the probability density for each point in X.
Expand Down Expand Up @@ -101,9 +102,20 @@ def cumulative_distribution(self, X):
self.check_fit()
X = np.array(X)
stdev = np.sqrt(self._model.covariance[0, 0])
lower = ndtr((self._get_bounds()[0] - self._model.dataset) / stdev)[0]
uppers = ndtr((X[:, None] - self._model.dataset) / stdev)
return (uppers - lower).dot(self._model.weights)
# lower = ndtr((self._get_bounds()[0] - self._model.dataset) / stdev)[0]
# uppers = ndtr((X[:, None] - self._model.dataset) / stdev)
# return (uppers - lower).dot(self._model.weights)

data_flatten = pd.Series(self._model.dataset.flatten())
v_c = data_flatten.value_counts()
weights = v_c.values / data_flatten.__len__()
dataset_weighted = np.array(v_c.index).reshape(1, -1)
if '_lower' not in dir(self):
lower = ndtr((self._get_bounds()[0] - dataset_weighted) / stdev)[0]
else:
lower = ndtr((self._lower - dataset_weighted) / stdev)[0]
uppers = ndtr((X[:, None] - dataset_weighted) / stdev)
return (uppers - lower).dot(weights)

def percent_point(self, U, method="chandrupatla"):
"""Compute the inverse cumulative distribution value for each point in U.
Expand Down