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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#![no_std]
pub trait Stateless<'a, I, O> {
fn process(&'a self, input: I) -> O;
}
pub trait Stateful<'a, I, O> {
fn process(&'a mut self, input: I) -> O;
}
pub trait Instruction<I, O> {
fn process(self, input: I) -> O;
}
impl<'a, I, O> Stateful<'a, I, O> for Stateless<'a, I, O> {
fn process(&'a mut self, input: I) -> O {
Stateless::process(self, input)
}
}
pub trait Online<S> {
fn train_online(&mut self, set: S);
}
pub trait OnlineRand<S, R> {
fn train_online_rng(&mut self, set: S, rng: &mut R);
}
impl<S, R, O> OnlineRand<S, R> for O
where O: Online<S>
{
fn train_online_rng(&mut self, set: S, _: &mut R) {
O::train_online(self, set)
}
}
pub trait Offline<S> {
fn train_offline(set: S) -> Self;
}
pub trait OfflineRand<S, R> {
fn train_offline_rng(set: S, rng: &mut R) -> Self;
}
impl<S, R, O> OfflineRand<S, R> for O
where O: Offline<S>
{
fn train_offline_rng(set: S, _: &mut R) -> Self {
O::train_offline(set)
}
}
pub trait Mate {
fn mate(&self, rhs: &Self) -> Self;
}
pub trait MateRand<R> {
fn mate(&self, rhs: &Self, rng: &mut R) -> Self;
}
impl<R, M> MateRand<R> for M
where M: Mate
{
fn mate(&self, rhs: &Self, _: &mut R) -> Self {
M::mate(self, rhs)
}
}
pub trait Mutate<R> {
fn mutate(&mut self, rng: &mut R);
}