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

[ENH] Multivariate normal probability distribution #375

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update multivariate_normal.py
  • Loading branch information
bhavikar04 authored Jun 8, 2024
commit 628faa2e2e89a3686f4fb3334dddf0ce1f0e0202
19 changes: 12 additions & 7 deletions skpro/distributions/multivariate_normal.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# copyright: skpro developers, BSD-3-Clause License (see LICENSE file)
"""Multivariate Normal/Gaussian probability distribution."""

__author__ = ["bhavikar04","fkiraly"]
__author__ = ["bhavikar04", "fkiraly"]

import numpy as np
import pandas as pd
from scipy.special import erf, erfinv
from scipy.stats import multivariate_normal

from skpro.distributions.base import BaseDistribution
class Multivariate_Normal(BaseDistribution):
class MultivariateNormal(BaseDistribution):
r"""Multivariate Normal distribution (skpro native).

This distribution is multivariate, without correlation between dimensions
Expand Down Expand Up @@ -130,7 +130,9 @@ def _pdf(self, x):
"""
mu = self._bc_params["mu"]
cov = self._bc_params["cov"]
pdf_arr = (1 / ((np.linalg.det(cov))**(1/2) * (2*np.pi)**(len(x)/2))) * np.exp(-0.5 * (x - mu).T @ np.linalg.inv(cov) @ (x - mu).cov())
pdf_arr = (
1 / ((np.linalg.det(cov))**(1/2) * (2*np.pi)**(len(x)/2))
) * np.exp(-0.5 * (x - mu).T @ np.linalg.inv(cov) @ (x - mu).cov())

return pdf_arr

Expand All @@ -150,7 +152,11 @@ def _log_pdf(self, x):
mu = self._bc_params["mu"]
cov = self._bc_params["cov"]

lpdf_arr = -0.5 * [np.log(np.linalg.det(cov))+(x - mu).T @ np.linalg.inv(cov) @ (x - mu)+(len(x)/2)*np.log((2*np.pi))]
lpdf_arr = -0.5 * [
np.log(np.linalg.det(cov))
+(x - mu).T @ np.linalg.inv(cov) @ (x - mu)
+(len(x)/2)*np.log(2*np.pi)
]

return lpdf_arr

Expand All @@ -170,8 +176,7 @@ def _cdf(self, x):
mu = self._bc_params["mu"]
cov = self._bc_params["cov"]

cdf_arr= multivariate_normal.cdf(x,mu,cov,allow_singular=False)

cdf_arr= multivariate_normal.cdf(x, mu, cov, allow_singular=False)

return cdf_arr

Expand All @@ -188,7 +193,7 @@ def _ppf(self, p):
2D np.ndarray, same shape as ``self``
ppf values at the given points
"""
#Does not exist since closed form of cdf does not exist
#Does not exist since closed form of cdf does not exist

@classmethod
def get_test_params(cls, parameter_set="default"):
Expand Down
Loading