Skip to content

Commit e0a9d6e

Browse files
committed
feat: add multivariate interface
1 parent 79fb41f commit e0a9d6e

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/stats/copulas/bivariate.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ pub mod gumbel;
1313
pub mod independence;
1414

1515
#[derive(Debug, Clone, Copy)]
16-
pub enum CopulaType {
16+
pub(super) enum CopulaType {
1717
Clayton,
1818
Frank,
1919
Gumbel,
2020
Independence,
2121
}
2222

23-
const EPSILON: f64 = 1e-12;
24-
2523
pub trait Bivariate {
2624
fn r#type(&self) -> CopulaType;
2725

@@ -128,9 +126,7 @@ pub trait Bivariate {
128126
fn pdf(&self, X: &Array2<f64>) -> Result<Array1<f64>, Box<dyn Error>>;
129127

130128
fn log_pdf(&self, X: &Array2<f64>) -> Result<Array1<f64>, Box<dyn Error>> {
131-
let pdf = self.pdf(X)?;
132-
let log_pdf = pdf.mapv(|val| (val + 1e-32).ln());
133-
Ok(log_pdf)
129+
Ok(self.pdf(X)?.ln())
134130
}
135131

136132
fn cdf(&self, X: &Array2<f64>) -> Result<Array1<f64>, Box<dyn Error>>;

src/stats/copulas/multivariate.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
use std::error::Error;
2+
3+
use ndarray::{Array1, Array2};
4+
15
pub mod gaussian;
26
pub mod tree;
37
pub mod vine;
8+
9+
pub(super) enum CopulaType {
10+
Gaussian,
11+
Tree,
12+
Vine,
13+
}
14+
15+
pub trait Multivariate {
16+
fn r#type(&self) -> CopulaType;
17+
18+
fn sample(&self, n: usize) -> Result<Array2<f64>, Box<dyn Error>>;
19+
20+
fn fit(&mut self, X: Array2<f64>) -> Result<(), Box<dyn Error>>;
21+
22+
fn check_fit(&self, X: &Array2<f64>) -> Result<(), Box<dyn Error>>;
23+
24+
fn pdf(&self, X: Array2<f64>) -> Result<Array1<f64>, Box<dyn Error>>;
25+
26+
fn log_pdf(&self, X: Array2<f64>) -> Result<Array1<f64>, Box<dyn Error>> {
27+
Ok(self.pdf(X)?.ln())
28+
}
29+
30+
fn cdf(&self, X: Array2<f64>) -> Result<Array1<f64>, Box<dyn Error>>;
31+
}

0 commit comments

Comments
 (0)