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
use std::convert::TryFrom;
use serde::Deserialize;
use serde::Serialize;
use crate::cc::alg::ColAssignAlg;
use crate::cc::alg::RowAssignAlg;
use crate::ParseError;
pub const DEFAULT_STATE_TRANSITIONS: [StateTransition; 5] = [
StateTransition::ColumnAssignment(ColAssignAlg::Slice),
StateTransition::StatePriorProcessParams,
StateTransition::RowAssignment(RowAssignAlg::Slice),
StateTransition::ViewPriorProcessParams,
StateTransition::FeaturePriors,
];
/// MCMC transitions in the `View`
#[derive(Deserialize, Serialize, Clone, Copy, Eq, PartialEq, Debug)]
pub enum ViewTransition {
/// Reassign rows to categories
RowAssignment(RowAssignAlg),
/// Update the alpha (discount) parameters on the CRP
PriorProcessParams,
/// Update the feature (column) prior parameters
FeaturePriors,
/// Update the parameters in the feature components. This is usually done
/// automatically during the row assignment, but if the row assignment is
/// not done (e.g. in the case of Geweke testing), then you can turn it on
/// with this transition Note: this is not a default state transition.
ComponentParams,
}
/// MCMC transitions in the `State`
#[derive(Deserialize, Serialize, Clone, Copy, Eq, PartialEq, Debug)]
pub enum StateTransition {
/// Reassign columns to views
#[serde(rename = "column_assignment")]
ColumnAssignment(ColAssignAlg),
/// Reassign rows in views to categories
#[serde(rename = "row_assignment")]
RowAssignment(RowAssignAlg),
/// Update the alpha (discount) parameter on the column-to-views CRP
#[serde(rename = "state_prior_process_params")]
StatePriorProcessParams,
/// Update the alpha (discount) parameters on the row-to-categories CRP
#[serde(rename = "view_prior_process_params")]
ViewPriorProcessParams,
/// Update the feature (column) prior parameters
#[serde(rename = "feature_priors")]
FeaturePriors,
/// Update the parameters in the feature components. This is usually done
/// automatically during the row assignment, but if the row assignment is
/// not done (e.g. in the case of Geweke testing), then you can turn it on
/// with this transition Note: this is not a default state transition.
#[serde(rename = "component_params")]
ComponentParams,
}
impl TryFrom<StateTransition> for ViewTransition {
type Error = ParseError<StateTransition>;
fn try_from(st: StateTransition) -> Result<ViewTransition, Self::Error> {
match st {
StateTransition::ViewPriorProcessParams => {
Ok(ViewTransition::PriorProcessParams)
}
StateTransition::RowAssignment(alg) => {
Ok(ViewTransition::RowAssignment(alg))
}
StateTransition::FeaturePriors => Ok(ViewTransition::FeaturePriors),
StateTransition::ComponentParams => {
Ok(ViewTransition::ComponentParams)
}
_ => Err(ParseError(st)),
}
}
}
// TODO: Conversion tests