41 lines
1.4 KiB
Rust
41 lines
1.4 KiB
Rust
// Simple test to verify the NMF algorithm works correctly
|
|
use rtx_nmf::{Device, NMFConfig, NMFDecomposer, Tensor};
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
println!("🧪 Simple NMF Algorithm Test");
|
|
println!("============================");
|
|
|
|
// Test with CPU device and basic configuration
|
|
let device = Device::cpu();
|
|
println!("📱 Using device: {:?}", device);
|
|
|
|
// Create simple test matrix (4x3)
|
|
let test_data = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 2.0, 4.0, 6.0];
|
|
let matrix = Tensor::from_data(test_data, [4, 3], &device)?;
|
|
println!("✅ Created test matrix: 4x3");
|
|
|
|
// Create NMF decomposer with minimal components
|
|
let config = NMFConfig::new()
|
|
.with_components(2)
|
|
.with_max_iterations(5)
|
|
.with_tolerance(1e-4);
|
|
|
|
let mut decomposer = NMFDecomposer::new(config);
|
|
println!("✅ NMF decomposer created successfully");
|
|
|
|
// Run decomposition
|
|
println!("\n⚡ Running NMF decomposition...");
|
|
let result = decomposer.fit_transform_detailed(&matrix)?;
|
|
|
|
println!("✅ NMF decomposition completed!");
|
|
println!(" Components: 2");
|
|
println!(" Iterations: {}", result.iterations);
|
|
println!(" Error: {:.6}", result.reconstruction_error);
|
|
println!(" Time: {:.3}s", result.computation_time);
|
|
println!(" Converged: {}", result.converged);
|
|
|
|
println!("\n🎉 Simple test passed! Core NMF algorithm is working.");
|
|
|
|
Ok(())
|
|
}
|