diff --git a/config/greyhound.cf.json b/config/greyhound.cf.json index 0fa7183..813a4e1 100644 --- a/config/greyhound.cf.json +++ b/config/greyhound.cf.json @@ -39,7 +39,7 @@ 3 ] }, - "ZeroIntercept" + "Origin" ], "coefficients": [ 1.3556904676344945, @@ -91,7 +91,7 @@ 3 ] }, - "ZeroIntercept" + "Origin" ], "coefficients": [ 0.9802565411251424, @@ -143,7 +143,7 @@ 3 ] }, - "ZeroIntercept" + "Origin" ], "coefficients": [ 0.9789334447029333, diff --git a/config/greyhound.r.json b/config/greyhound.r.json index 9b0aea8..51f0ee3 100644 --- a/config/greyhound.r.json +++ b/config/greyhound.r.json @@ -6,7 +6,7 @@ { "Ordinal": "ActiveRunners" }, { "Exp": [{ "Ordinal": "ActiveRunners" }, 2]}, { "Exp": [{ "Ordinal": "ActiveRunners" }, 3]}, - "ZeroIntercept" + "Origin" ], "w2": [ { "Ordinal": "Weight0" }, @@ -15,7 +15,7 @@ { "Ordinal": "ActiveRunners" }, { "Exp": [{ "Ordinal": "ActiveRunners" }, 2]}, { "Exp": [{ "Ordinal": "ActiveRunners" }, 3]}, - "ZeroIntercept" + "Origin" ], "w3": [ { "Ordinal": "Weight0" }, @@ -24,6 +24,6 @@ { "Ordinal": "ActiveRunners" }, { "Exp": [{ "Ordinal": "ActiveRunners" }, 2]}, { "Exp": [{ "Ordinal": "ActiveRunners" }, 3]}, - "ZeroIntercept" + "Origin" ] } \ No newline at end of file diff --git a/config/thoroughbred.cf.json b/config/thoroughbred.cf.json index 1abc162..585ef62 100644 --- a/config/thoroughbred.cf.json +++ b/config/thoroughbred.cf.json @@ -39,7 +39,7 @@ 3 ] }, - "ZeroIntercept" + "Origin" ], "coefficients": [ 1.4714802210953573, @@ -91,7 +91,7 @@ 3 ] }, - "ZeroIntercept" + "Origin" ], "coefficients": [ 1.2069350824699938, @@ -143,7 +143,7 @@ 3 ] }, - "ZeroIntercept" + "Origin" ], "coefficients": [ 1.2428287117834143, diff --git a/config/thoroughbred.r.json b/config/thoroughbred.r.json index 9b0aea8..51f0ee3 100644 --- a/config/thoroughbred.r.json +++ b/config/thoroughbred.r.json @@ -6,7 +6,7 @@ { "Ordinal": "ActiveRunners" }, { "Exp": [{ "Ordinal": "ActiveRunners" }, 2]}, { "Exp": [{ "Ordinal": "ActiveRunners" }, 3]}, - "ZeroIntercept" + "Origin" ], "w2": [ { "Ordinal": "Weight0" }, @@ -15,7 +15,7 @@ { "Ordinal": "ActiveRunners" }, { "Exp": [{ "Ordinal": "ActiveRunners" }, 2]}, { "Exp": [{ "Ordinal": "ActiveRunners" }, 3]}, - "ZeroIntercept" + "Origin" ], "w3": [ { "Ordinal": "Weight0" }, @@ -24,6 +24,6 @@ { "Ordinal": "ActiveRunners" }, { "Exp": [{ "Ordinal": "ActiveRunners" }, 2]}, { "Exp": [{ "Ordinal": "ActiveRunners" }, 3]}, - "ZeroIntercept" + "Origin" ] } \ No newline at end of file diff --git a/src/linear/regression.rs b/src/linear/regression.rs index aa24331..0b31a75 100644 --- a/src/linear/regression.rs +++ b/src/linear/regression.rs @@ -24,7 +24,7 @@ pub enum Regressor { Exp(Box>, i32), Product(Vec>), Intercept, - ZeroIntercept, + Origin, } impl Regressor { pub fn resolve(&self, input: &[f64]) -> f64 { @@ -36,12 +36,12 @@ impl Regressor { .map(|regressor| regressor.resolve(input)) .product(), Regressor::Intercept => 1., - Regressor::ZeroIntercept => 0., + Regressor::Origin => 0., } } pub fn is_constant(&self) -> bool { - matches!(self, Regressor::Intercept | Regressor::ZeroIntercept) + matches!(self, Regressor::Intercept | Regressor::Origin) } } @@ -102,7 +102,7 @@ impl Predictor { let has_zero_intercept = self .regressors .iter() - .any(|regressor| matches!(regressor, Regressor::ZeroIntercept)); + .any(|regressor| matches!(regressor, Regressor::Origin)); let df_residual; let df_total; @@ -150,7 +150,7 @@ pub(crate) fn validate_regressors( bail!( "must specify exactly one {} or {} regressor", Regressor::::Intercept.to_string(), - Regressor::::ZeroIntercept.to_string() + Regressor::::Origin.to_string() ); } Ok(()) diff --git a/src/linear/regression/tests.rs b/src/linear/regression/tests.rs index ac86879..01c0292 100644 --- a/src/linear/regression/tests.rs +++ b/src/linear/regression/tests.rs @@ -3,7 +3,7 @@ use ordinalizer::Ordinal; use Regressor::{Exp, Ordinal, Product}; -use crate::linear::regression::Regressor::{Intercept, ZeroIntercept}; +use crate::linear::regression::Regressor::{Intercept, Origin}; use crate::testing::assert_slice_f64_relative; use super::*; @@ -59,9 +59,9 @@ fn serde_json() { assert_eq!(r, rr); } { - let r = ZeroIntercept; + let r = Origin; let json = to_json(&r); - assert_eq!(r#""ZeroIntercept""#, json); + assert_eq!(r#""Origin""#, json); let rr = from_json(&json); assert_eq!(r, rr); } @@ -129,7 +129,7 @@ fn regression_data_1() { } { // without intercept - let model = RegressionModel::fit(Factor::Y, vec![ZeroIntercept, Ordinal(Factor::X)], &data) + let model = RegressionModel::fit(Factor::Y, vec![Origin, Ordinal(Factor::X)], &data) .unwrap(); assert_slice_f64_relative( &model.predictor.coefficients, @@ -231,7 +231,7 @@ fn regression_data_1() { // with multiple distinct regressors and no intercept let model = RegressionModel::fit( Factor::Y, - vec![ZeroIntercept, Ordinal(Factor::X), Ordinal(Factor::W)], + vec![Origin, Ordinal(Factor::X), Ordinal(Factor::W)], &data, ) .unwrap(); @@ -268,7 +268,7 @@ fn regression_data_1() { let model = RegressionModel::fit( Factor::Y, vec![ - ZeroIntercept, + Origin, Product(vec![Ordinal(Factor::X), Ordinal(Factor::W)]), ], &data, @@ -361,7 +361,7 @@ fn regression_data_2() { } { // without intercept - let model = RegressionModel::fit(Factor::Y, vec![ZeroIntercept, Ordinal(Factor::X)], &data) + let model = RegressionModel::fit(Factor::Y, vec![Origin, Ordinal(Factor::X)], &data) .unwrap(); assert_slice_f64_relative( &model.predictor.coefficients, @@ -423,7 +423,7 @@ fn regression_data_2() { // with multiple distinct regressors and no intercept let model = RegressionModel::fit( Factor::Y, - vec![ZeroIntercept, Ordinal(Factor::X), Ordinal(Factor::W)], + vec![Origin, Ordinal(Factor::X), Ordinal(Factor::W)], &data, ) .unwrap();