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
40
41
42
43
44
45
46
47
48
49
use error::*;
use geometry::Matrix;
use projectors::{IndexSet, IndexT};
use std::collections::HashMap;
pub trait Approximator<I: ?Sized> {
type Value;
fn evaluate(&self, input: &I) -> EvaluationResult<Self::Value>;
fn update(&mut self, input: &I, update: Self::Value) -> UpdateResult<()>;
#[allow(unused_variables)]
fn adapt(&mut self, new_features: &HashMap<IndexT, IndexSet>) -> AdaptResult<usize> {
Err(AdaptError::NotImplemented)
}
}
impl<I: ?Sized, T: Approximator<I>> Approximator<I> for Box<T> {
type Value = T::Value;
fn evaluate(&self, input: &I) -> EvaluationResult<Self::Value> {
(**self).evaluate(input)
}
fn update(&mut self, input: &I, update: Self::Value) -> UpdateResult<()> {
(**self).update(input, update)
}
fn adapt(&mut self, new_features: &HashMap<IndexT, IndexSet>) -> AdaptResult<usize> {
(**self).adapt(new_features)
}
}
pub trait Parameterised {
fn weights(&self) -> Matrix<f64>;
}
impl<T: Parameterised> Parameterised for Box<T> {
fn weights(&self) -> Matrix<f64> {
(**self).weights()
}
}