use crate::Neural;
pub type BoxedResponsive<N> = Box<dyn Responsive<N> + Send>;
pub trait Responsive<N>
where
N: Neural,
{
fn get_best_matching(&self, neurons: &N, pattern: &ArrayView1<f64>) -> usize;
fn clone_dyn(&self) -> BoxedResponsive<N>;
}
impl<N> Responsive<N> for BoxedResponsive<N>
where
N: Neural,
{
fn get_best_matching(&self, neurons: &N, pattern: &ArrayView1<f64>) -> usize {
(**self).get_best_matching(neurons, pattern)
}
fn clone_dyn(&self) -> BoxedResponsive<N> {
panic!()
}
}
impl<N> Clone for BoxedResponsive<N>
where
N: Neural,
{
fn clone(&self) -> Self {
(**self).clone_dyn()
}
}
#[derive(Clone)]
pub struct CartesianResponsiveness {
}
use crate::nd_tools::{
argmin,
point_set::{row_norm_l2, PointSet},
};
use ndarray::{prelude::*, Data};
impl<N> Responsive<N> for CartesianResponsiveness
where
N: Neural,
{
fn get_best_matching(&self, neurons: &N, pattern: &ArrayView1<f64>) -> usize {
argmin(&row_norm_l2(
&neurons.get_patterns().get_differences(&pattern),
))
}
fn clone_dyn(&self) -> BoxedResponsive<N> {
Box::new(self.clone()) }
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}