Files
ruvnet--RuView/v2/crates/ruv-neural/ruv-neural-embed/src/lib.rs
T
rUv f49c722764 chore(repo): rename rust-port/wifi-densepose-rs → v2/ (flatten to one level) (#427)
The Rust port lived two directories deep (rust-port/wifi-densepose-rs/)
without any sibling under rust-port/ that warranted the extra level.
Move the whole workspace up to v2/ to match v1/ (Python) at the same
depth and shorten every cd / build command across the repo.

git mv preserves history for all tracked files. 60 files updated for
path references (CI workflows, ADRs, docs, scripts, READMEs, internal
.claude-flow state). Two manual fixes for relative-cd paths in
CLAUDE.md and ADR-043 that became wrong after the depth change
(cd ../.. → cd ..).

Validated:
- cargo check --workspace --no-default-features → clean (after target/
  nuke; the gitignored target/ was carried by the OS rename and had
  hard-coded old paths in build scripts)
- cargo test --workspace --no-default-features → 1,539 passed, 0 failed,
  8 ignored (same totals as pre-rename)
- ESP32-S3 on COM7 → still streaming live CSI (cb #40300, RSSI -64 dBm)

After-merge follow-up: contributors should `rm -rf v2/target` once and
let cargo regenerate from the new path.
2026-04-25 21:28:13 -04:00

103 lines
3.2 KiB
Rust

//! rUv Neural Embed -- Graph embedding generation for brain connectivity states.
//!
//! This crate provides multiple embedding methods to convert brain connectivity
//! graphs (`BrainGraph`) into fixed-dimensional vector representations suitable
//! for downstream classification, clustering, and temporal analysis.
//!
//! # Embedding Methods
//!
//! - **Spectral**: Laplacian eigenvector-based positional encoding
//! - **Topology**: Hand-crafted topological feature vectors
//! - **Node2Vec**: Random-walk co-occurrence embeddings
//! - **Combined**: Weighted concatenation of multiple methods
//! - **Temporal**: Sliding-window context-enriched embeddings
//!
//! # RVF Export
//!
//! Embeddings can be serialized to the RuVector `.rvf` format for interoperability
//! with the broader RuVector ecosystem.
pub mod combined;
pub mod distance;
pub mod node2vec;
pub mod rvf_export;
pub mod spectral_embed;
pub mod temporal;
pub mod topology_embed;
// Re-export core types used throughout this crate.
pub use ruv_neural_core::embedding::{EmbeddingMetadata, EmbeddingTrajectory, NeuralEmbedding};
pub use ruv_neural_core::graph::{BrainGraph, BrainGraphSequence};
pub use ruv_neural_core::traits::EmbeddingGenerator;
/// Helper to build an `EmbeddingMetadata` with just a method name and atlas.
pub fn default_metadata(
method: &str,
atlas: ruv_neural_core::brain::Atlas,
) -> EmbeddingMetadata {
EmbeddingMetadata {
subject_id: None,
session_id: None,
cognitive_state: None,
source_atlas: atlas,
embedding_method: method.to_string(),
}
}
#[cfg(test)]
mod tests {
use super::*;
use ruv_neural_core::brain::Atlas;
#[test]
fn test_neural_embedding_new() {
let meta = default_metadata("test", Atlas::Custom(3));
let emb = NeuralEmbedding::new(vec![1.0, 2.0, 3.0], 0.0, meta).unwrap();
assert_eq!(emb.dimension, 3);
assert_eq!(emb.vector.len(), 3);
}
#[test]
fn test_neural_embedding_empty_fails() {
let meta = default_metadata("test", Atlas::Custom(1));
let result = NeuralEmbedding::new(vec![], 0.0, meta);
assert!(result.is_err());
}
#[test]
fn test_embedding_norm() {
let meta = default_metadata("test", Atlas::Custom(2));
let emb = NeuralEmbedding::new(vec![3.0, 4.0], 0.0, meta).unwrap();
assert!((emb.norm() - 5.0).abs() < 1e-10);
}
#[test]
fn test_trajectory() {
let traj = EmbeddingTrajectory {
embeddings: vec![
NeuralEmbedding::new(
vec![0.0; 4],
0.0,
default_metadata("test", Atlas::Custom(4)),
)
.unwrap(),
NeuralEmbedding::new(
vec![0.0; 4],
0.5,
default_metadata("test", Atlas::Custom(4)),
)
.unwrap(),
NeuralEmbedding::new(
vec![0.0; 4],
1.0,
default_metadata("test", Atlas::Custom(4)),
)
.unwrap(),
],
timestamps: vec![0.0, 0.5, 1.0],
};
assert_eq!(traj.len(), 3);
assert!((traj.duration_s() - 1.0).abs() < 1e-10);
}
}