1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Provides customized implementation of Growing Self Organizing Map.

use std::fmt::Display;
use std::ops::RangeBounds;

mod network;
pub use self::network::*;

mod node;
pub use self::node::*;

mod state;
pub use self::state::*;

/// Represents an input for network.
pub trait Input: Send + Sync {
    /// Returns weights.
    fn weights(&self) -> &[f64];
}

/// Represents input data storage.
pub trait Storage: Display + Send + Sync {
    /// An input type.
    type Item: Input;

    /// Adds an input to the storage.
    fn add(&mut self, input: Self::Item);

    /// Removes and returns all data from the storage.
    fn drain<R>(&mut self, range: R) -> Vec<Self::Item>
    where
        R: RangeBounds<usize>;

    /// Returns a distance between two input weights.
    fn distance(&self, a: &[f64], b: &[f64]) -> f64;

    /// Returns size of the storage.
    fn size(&self) -> usize;
}