use crate::estimators::approaches::discrete::ansb::AnsbEntropy;
use crate::estimators::approaches::discrete::bayes::{AlphaParam, BayesEntropy};
use crate::estimators::approaches::discrete::bonachela::BonachelaEntropy;
use crate::estimators::approaches::discrete::chao_shen::ChaoShenEntropy;
use crate::estimators::approaches::discrete::chao_wang_jost::ChaoWangJostEntropy;
use crate::estimators::approaches::discrete::grassberger::GrassbergerEntropy;
use crate::estimators::approaches::discrete::miller_madow::MillerMadowEntropy;
use crate::estimators::approaches::discrete::mle::DiscreteEntropy;
use crate::estimators::approaches::discrete::nsb::NsbEntropy;
use crate::estimators::approaches::discrete::shrink::ShrinkEntropy;
use crate::estimators::approaches::discrete::zhang::ZhangEntropy;
use crate::estimators::approaches::expfam::kozachenko_leonenko::KozachenkoLeonenkoEntropy;
use crate::estimators::approaches::expfam::renyi::RenyiEntropy;
use crate::estimators::approaches::expfam::tsallis::TsallisEntropy;
use crate::estimators::approaches::kernel;
use crate::estimators::approaches::ordinal::ordinal_estimator::OrdinalEntropy;
pub use crate::estimators::traits::{CrossEntropy, GlobalValue, JointEntropy, LocalValues};
use ndarray::{Array1, Array2};
pub struct Entropy;
impl Entropy {
pub fn new_discrete(data: Array1<i32>) -> DiscreteEntropy {
DiscreteEntropy::new(data)
}
pub fn new_miller_madow(data: Array1<i32>) -> MillerMadowEntropy {
MillerMadowEntropy::new(data)
}
pub fn new_shrink(data: Array1<i32>) -> ShrinkEntropy {
ShrinkEntropy::new(data)
}
pub fn new_grassberger(data: Array1<i32>) -> GrassbergerEntropy {
GrassbergerEntropy::new(data)
}
pub fn new_zhang(data: Array1<i32>) -> ZhangEntropy {
ZhangEntropy::new(data)
}
pub fn new_bayes(
data: Array1<i32>,
alpha: AlphaParam,
k_override: Option<usize>,
) -> BayesEntropy {
BayesEntropy::new(data, alpha, k_override)
}
pub fn new_bonachela(data: Array1<i32>) -> BonachelaEntropy {
BonachelaEntropy::new(data)
}
pub fn new_chao_shen(data: Array1<i32>) -> ChaoShenEntropy {
ChaoShenEntropy::new(data)
}
pub fn new_chao_wang_jost(data: Array1<i32>) -> ChaoWangJostEntropy {
ChaoWangJostEntropy::new(data)
}
pub fn new_ansb(data: Array1<i32>, k_override: Option<usize>) -> AnsbEntropy {
AnsbEntropy::new(data, k_override, 0.1)
}
pub fn new_ansb_with_threshold(
data: Array1<i32>,
k_override: Option<usize>,
undersampled_threshold: f64,
) -> AnsbEntropy {
AnsbEntropy::new(data, k_override, undersampled_threshold)
}
pub fn new_nsb(data: Array1<i32>, k_override: Option<usize>) -> NsbEntropy {
NsbEntropy::new(data, k_override)
}
pub fn new_discrete_rows(data: Array2<i32>) -> Vec<DiscreteEntropy> {
DiscreteEntropy::from_rows(data)
}
pub fn new_miller_madow_rows(data: Array2<i32>) -> Vec<MillerMadowEntropy> {
MillerMadowEntropy::from_rows(data)
}
pub fn new_shrink_rows(data: Array2<i32>) -> Vec<ShrinkEntropy> {
ShrinkEntropy::from_rows(data)
}
pub fn new_grassberger_rows(data: Array2<i32>) -> Vec<GrassbergerEntropy> {
GrassbergerEntropy::from_rows(data)
}
pub fn new_zhang_rows(data: Array2<i32>) -> Vec<ZhangEntropy> {
ZhangEntropy::from_rows(data)
}
pub fn new_bonachela_rows(data: Array2<i32>) -> Vec<BonachelaEntropy> {
BonachelaEntropy::from_rows(data)
}
pub fn new_chao_shen_rows(data: Array2<i32>) -> Vec<ChaoShenEntropy> {
ChaoShenEntropy::from_rows(data)
}
pub fn new_chao_wang_jost_rows(data: Array2<i32>) -> Vec<ChaoWangJostEntropy> {
ChaoWangJostEntropy::from_rows(data)
}
pub fn new_ansb_rows(data: Array2<i32>, k_override: Option<usize>) -> Vec<AnsbEntropy> {
AnsbEntropy::from_rows(data, k_override, 0.1)
}
pub fn new_ansb_rows_with_threshold(
data: Array2<i32>,
k_override: Option<usize>,
undersampled_threshold: f64,
) -> Vec<AnsbEntropy> {
AnsbEntropy::from_rows(data, k_override, undersampled_threshold)
}
pub fn new_bayes_rows(
data: Array2<i32>,
alpha: AlphaParam,
k_override: Option<usize>,
) -> Vec<BayesEntropy> {
BayesEntropy::from_rows(data, alpha, k_override)
}
pub fn new_nsb_rows(data: Array2<i32>, k_override: Option<usize>) -> Vec<NsbEntropy> {
NsbEntropy::from_rows(data, k_override)
}
pub fn new_kernel(
data: impl Into<kernel::KernelData>,
bandwidth: f64,
) -> kernel::KernelEntropy<1> {
kernel::KernelEntropy::new(data, bandwidth)
}
pub fn new_kernel_with_type(
data: impl Into<kernel::KernelData>,
kernel_type: String,
bandwidth: f64,
) -> kernel::KernelEntropy<1> {
kernel::KernelEntropy::new_with_kernel_type(data, kernel_type, bandwidth)
}
pub fn nd_kernel<const K: usize>(
data: impl Into<kernel::KernelData>,
bandwidth: f64,
) -> kernel::KernelEntropy<K> {
kernel::KernelEntropy::new(data, bandwidth)
}
pub fn nd_kernel_with_type<const K: usize>(
data: impl Into<kernel::KernelData>,
kernel_type: String,
bandwidth: f64,
) -> kernel::KernelEntropy<K> {
kernel::KernelEntropy::new_with_kernel_type(data, kernel_type, bandwidth)
}
}
impl Entropy {
pub fn new_ordinal(data: Array1<f64>, order: usize) -> OrdinalEntropy {
OrdinalEntropy::new(data, order)
}
pub fn new_ordinal_with_step(
data: Array1<f64>,
order: usize,
step_size: usize,
) -> OrdinalEntropy {
OrdinalEntropy::new_with_step(data, order, step_size)
}
pub fn new_ordinal_with_step_and_stable(
data: Array1<f64>,
order: usize,
step_size: usize,
stable: bool,
) -> OrdinalEntropy {
OrdinalEntropy::new_with_step_and_stable(data, order, step_size, stable)
}
pub fn ordinal_joint_entropy(
series_list: &[Array1<f64>],
order: usize,
step_size: usize,
) -> f64 {
<OrdinalEntropy as JointEntropy>::joint_entropy(series_list, (order, step_size, true))
}
pub fn ordinal_joint_entropy_with_stable(
series_list: &[Array1<f64>],
order: usize,
step_size: usize,
stable: bool,
) -> f64 {
<OrdinalEntropy as JointEntropy>::joint_entropy(series_list, (order, step_size, stable))
}
pub fn ordinal_cross_entropy(
x: &Array1<f64>,
y: &Array1<f64>,
order: usize,
step_size: usize,
) -> f64 {
let ex = OrdinalEntropy::new_with_step_and_stable(x.clone(), order, step_size, true);
let ey = OrdinalEntropy::new_with_step_and_stable(y.clone(), order, step_size, true);
ex.cross_entropy(&ey)
}
pub fn ordinal_cross_entropy_with_stable(
x: &Array1<f64>,
y: &Array1<f64>,
order: usize,
step_size: usize,
stable: bool,
) -> f64 {
let ex = OrdinalEntropy::new_with_step_and_stable(x.clone(), order, step_size, stable);
let ey = OrdinalEntropy::new_with_step_and_stable(y.clone(), order, step_size, stable);
ex.cross_entropy(&ey)
}
pub fn new_renyi_1d(
data: Array1<f64>,
k: usize,
alpha: f64,
noise_level: f64,
) -> RenyiEntropy<1> {
RenyiEntropy::<1>::new_1d(data, k, alpha, noise_level)
}
pub fn renyi_nd<const K: usize>(
data: Array2<f64>,
k: usize,
alpha: f64,
noise_level: f64,
) -> RenyiEntropy<K> {
RenyiEntropy::<K>::new(data, k, alpha, noise_level)
}
pub fn new_tsallis_1d(
data: Array1<f64>,
k: usize,
q: f64,
noise_level: f64,
) -> TsallisEntropy<1> {
TsallisEntropy::<1>::new_1d(data, k, q, noise_level)
}
pub fn tsallis_nd<const K: usize>(
data: Array2<f64>,
k: usize,
q: f64,
noise_level: f64,
) -> TsallisEntropy<K> {
TsallisEntropy::<K>::new(data, k, q, noise_level)
}
pub fn new_kl_1d(
data: Array1<f64>,
k: usize,
noise_level: f64,
) -> KozachenkoLeonenkoEntropy<1> {
KozachenkoLeonenkoEntropy::<1>::new_1d(data, k, noise_level)
}
pub fn kl_nd<const K: usize>(
data: Array2<f64>,
k: usize,
noise_level: f64,
) -> KozachenkoLeonenkoEntropy<K> {
KozachenkoLeonenkoEntropy::<K>::new(data, k, noise_level)
}
}