sevensense-analysis
Advanced acoustic analysis algorithms for bioacoustic pattern discovery.
sevensense-analysis provides sophisticated analysis tools for understanding bird vocalizations at scale. From clustering calls into groups, detecting recurring motifs, to modeling temporal patterns with Markov chains, it transforms raw embeddings into actionable ecological insights.
Features
- HDBSCAN Clustering: Density-based clustering for call-type discovery
- Markov Models: Temporal sequence analysis and prediction
- Motif Detection: Find recurring vocal patterns
- Statistical Analysis: Entropy, diversity indices, anomaly scores
- Temporal Patterns: Diel rhythms, seasonal trends
- Multi-scale Analysis: From milliseconds to months
Use Cases
| Use Case | Description | Key Functions |
|---|---|---|
| Call-Type Clustering | Group similar vocalizations | hdbscan_cluster() |
| Sequence Analysis | Model call sequences | MarkovChain::analyze() |
| Motif Discovery | Find repeated patterns | detect_motifs() |
| Diversity Metrics | Shannon/Simpson indices | diversity_index() |
| Periodicity | Detect rhythmic patterns | detect_periodicity() |
| Anomaly Detection | Find unusual calls | anomaly_score() |
Installation
Add to your Cargo.toml:
[]
= "0.1"
Quick Start
use ;
Basic Clustering
use ;
let config = HdbscanConfig ;
let clusterer = new;
let result = clusterer.fit?;
println!;
println!;
println!;
Cluster Analysis
use ;
let stats = cluster_statistics?;
for in stats.iter
Cluster Assignment for New Data
// Assign new embeddings to existing clusters
let new_embeddings = load_new_data?;
let assignments = clusterer.predict?;
for in new_embeddings.iter.zip
Building a Markov Model
use ;
// Sequences of cluster labels (call types)
let sequences: = vec!;
let config = MarkovConfig ;
let chain = fit?;
// Get transition probabilities
let probs = chain.transition_matrix;
println!; // Probability of 1 given 0
Sequence Prediction
// Predict next state
let current_state = 0;
let next_probs = chain.predict_next?;
println!;
for in next_probs.iter.enumerate
// Generate synthetic sequence
let generated = chain.generate?; // 10 states, starting from 0
println!;
Sequence Analysis
use MarkovAnalysis;
let analysis = new;
// Stationary distribution
let stationary = analysis.stationary_distribution?;
println!;
// Entropy rate
let entropy = analysis.entropy_rate?;
println!;
// Expected hitting times
let hitting_times = analysis.mean_hitting_times?;
println!;
Finding Repeated Patterns
use ;
let config = MotifConfig ;
let detector = new;
let motifs = detector.detect?;
for motif in &motifs
Motif Visualization
use motif_to_sequence;
for motif in motifs.iter.take
Cross-Recording Motifs
// Find motifs that appear across multiple recordings
let recordings: = load_recordings?;
let cross_motifs = detector.detect_cross_recording?;
for motif in cross_motifs
Diversity Indices
use ;
// Count species occurrences
let species_counts = count_species?;
let shannon = shannon_index;
let simpson = simpson_index;
let richness = species_richness;
println!;
println!;
println!;
Entropy Analysis
use ;
// Entropy of call sequences
let sequence: = vec!;
let entropy = sequence_entropy;
let norm_entropy = normalized_entropy;
println!;
println!; // 0-1 scale
Periodicity Detection
use ;
let config = PeriodicityConfig ;
let timestamps: = get_call_timestamps?;
let periods = detect_periodicity?;
for in periods
Diel Activity Patterns
use ;
let analyzer = new;
// Analyze activity by time of day
let pattern = analyzer.analyze?;
println!;
println!;
println!;
println!;
println!;
// Peak activity time
let peak = pattern.peak_hour;
println!;
Seasonal Trends
use ;
let analyzer = new;
let trend = analyzer.analyze?;
println!;
println!;
println!;
Time Series Analysis
use ;
let series = from_events?;
// Aggregate by hour
let hourly = series.aggregate?;
// Detect anomalies
let anomalies = series.detect_anomalies?; // 3-sigma threshold
for anomaly in anomalies
Configuration
HdbscanConfig Parameters
| Parameter | Default | Description |
|---|---|---|
min_cluster_size |
5 | Minimum cluster size |
min_samples |
3 | Core point threshold |
epsilon |
0.0 | Distance threshold (0=auto) |
metric |
Euclidean | Distance metric |
MarkovConfig Parameters
| Parameter | Default | Description |
|---|---|---|
order |
1 | Markov chain order |
smoothing |
0.01 | Laplace smoothing factor |
Algorithms
| Algorithm | Complexity | Use Case |
|---|---|---|
| HDBSCAN | O(n log n) | Clustering with noise |
| Markov Chain | O(n × s²) | Sequence modeling |
| Motif Discovery | O(n² × m) | Pattern finding |
| FFT Periodicity | O(n log n) | Rhythm detection |
Links
- Homepage: ruv.io
- Repository: github.com/ruvnet/ruvector
- Crates.io: crates.io/crates/sevensense-analysis
- Documentation: docs.rs/sevensense-analysis
License
MIT License - see LICENSE for details.
Part of the 7sense Bioacoustic Intelligence Platform by rUv