#![allow(clippy::too_many_arguments)]
#![allow(dead_code)]
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap, HashSet};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClassMetrics {
pub precision: f64,
pub recall: f64,
pub f1_score: f64,
pub support: usize,
}
impl Default for ClassMetrics {
fn default() -> Self {
Self {
precision: 0.0,
recall: 0.0,
f1_score: 0.0,
support: 0,
}
}
}
impl ClassMetrics {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CalibrationMetrics {
pub ece: f64,
pub mce: f64,
pub brier_score: f64,
pub reliability_diagram: Vec<(f64, f64, usize)>, }
impl CalibrationMetrics {
pub fn new() -> Self {
Self {
ece: 0.0,
mce: 0.0,
brier_score: 0.0,
reliability_diagram: Vec::new(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GroupFairnessMetrics {
pub tpr: f64,
pub fpr: f64,
pub precision: f64,
pub selection_rate: f64,
}
impl Default for GroupFairnessMetrics {
fn default() -> Self {
Self {
tpr: 0.0,
fpr: 0.0,
precision: 0.0,
selection_rate: 0.0,
}
}
}
impl GroupFairnessMetrics {
pub fn new() -> Self {
Self::default()
}
}
pub type NodeId = usize;
pub type EdgeId = (NodeId, NodeId);
pub type CommunityId = usize;
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct GraphStructure {
pub num_nodes: usize,
pub num_edges: usize,
pub adjacency_list: HashMap<NodeId, HashSet<NodeId>>,
pub edge_weights: Option<HashMap<EdgeId, f64>>,
pub node_feature_dim: Option<usize>,
pub edge_feature_dim: Option<usize>,
}
impl GraphStructure {
pub fn new() -> Self {
Self::default()
}
pub fn add_edge(&mut self, from: NodeId, to: NodeId, weight: Option<f64>) {
self.adjacency_list.entry(from).or_default().insert(to);
self.adjacency_list.entry(to).or_default().insert(from);
if let Some(w) = weight {
if self.edge_weights.is_none() {
self.edge_weights = Some(HashMap::new());
}
self.edge_weights
.as_mut()
.expect("Operation failed")
.insert((from, to), w);
self.edge_weights
.as_mut()
.expect("Operation failed")
.insert((to, from), w);
}
}
pub fn degree(&self, node: NodeId) -> usize {
self.adjacency_list
.get(&node)
.map_or(0, |neighbors| neighbors.len())
}
pub fn neighbors(&self, node: NodeId) -> Vec<NodeId> {
self.adjacency_list
.get(&node)
.map_or(Vec::new(), |neighbors| neighbors.iter().cloned().collect())
}
pub fn are_connected(&self, node1: NodeId, node2: NodeId) -> bool {
self.adjacency_list
.get(&node1)
.is_some_and(|neighbors| neighbors.contains(&node2))
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Triple {
pub head: String,
pub relation: String,
pub tail: String,
}
impl Triple {
pub fn new(head: String, relation: String, tail: String) -> Self {
Self {
head,
relation,
tail,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct MolecularStructure {
pub smiles: String,
pub num_atoms: usize,
pub num_bonds: usize,
pub atom_types: Vec<String>,
pub bond_types: Vec<String>,
pub molecular_weight: Option<f64>,
pub coordinates_3d: Option<Vec<(f64, f64, f64)>>,
}
impl MolecularStructure {
pub fn new() -> Self {
Self::default()
}
pub fn from_smiles(smiles: String) -> Self {
Self {
smiles,
..Default::default()
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RankingMetrics {
pub mean_rank: f64,
pub mrr: f64,
pub hits_at_1: f64,
pub hits_at_3: f64,
pub hits_at_10: f64,
pub hits_at_k: BTreeMap<usize, f64>,
}
impl Default for RankingMetrics {
fn default() -> Self {
Self {
mean_rank: 0.0,
mrr: 0.0,
hits_at_1: 0.0,
hits_at_3: 0.0,
hits_at_10: 0.0,
hits_at_k: BTreeMap::new(),
}
}
}
impl RankingMetrics {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DistanceMetrics {
pub euclidean: f64,
pub manhattan: f64,
pub cosine: f64,
pub jaccard: f64,
pub edit_distance: Option<usize>,
}
impl Default for DistanceMetrics {
fn default() -> Self {
Self {
euclidean: 0.0,
manhattan: 0.0,
cosine: 0.0,
jaccard: 0.0,
edit_distance: None,
}
}
}
impl DistanceMetrics {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SpectralProperties {
pub largest_eigenvalue: f64,
pub second_largest_eigenvalue: f64,
pub spectral_gap: f64,
pub trace: f64,
pub num_components: usize,
}
impl Default for SpectralProperties {
fn default() -> Self {
Self {
largest_eigenvalue: 0.0,
second_largest_eigenvalue: 0.0,
spectral_gap: 0.0,
trace: 0.0,
num_components: 1,
}
}
}
impl SpectralProperties {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DistributionStatistics {
pub mean: f64,
pub std_dev: f64,
pub skewness: f64,
pub kurtosis: f64,
pub min: f64,
pub max: f64,
pub median: f64,
pub percentiles: BTreeMap<u8, f64>,
}
impl Default for DistributionStatistics {
fn default() -> Self {
Self {
mean: 0.0,
std_dev: 0.0,
skewness: 0.0,
kurtosis: 0.0,
min: 0.0,
max: 0.0,
median: 0.0,
percentiles: BTreeMap::new(),
}
}
}
impl DistributionStatistics {
pub fn new() -> Self {
Self::default()
}
}