Skip to content

Commit

Permalink
Renamed ZeroIntercept to Origin
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoutanov committed Nov 1, 2023
1 parent cc9e849 commit 178fd03
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions config/greyhound.cf.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
3
]
},
"ZeroIntercept"
"Origin"
],
"coefficients": [
1.3556904676344945,
Expand Down Expand Up @@ -91,7 +91,7 @@
3
]
},
"ZeroIntercept"
"Origin"
],
"coefficients": [
0.9802565411251424,
Expand Down Expand Up @@ -143,7 +143,7 @@
3
]
},
"ZeroIntercept"
"Origin"
],
"coefficients": [
0.9789334447029333,
Expand Down
6 changes: 3 additions & 3 deletions config/greyhound.r.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{ "Ordinal": "ActiveRunners" },
{ "Exp": [{ "Ordinal": "ActiveRunners" }, 2]},
{ "Exp": [{ "Ordinal": "ActiveRunners" }, 3]},
"ZeroIntercept"
"Origin"
],
"w2": [
{ "Ordinal": "Weight0" },
Expand All @@ -15,7 +15,7 @@
{ "Ordinal": "ActiveRunners" },
{ "Exp": [{ "Ordinal": "ActiveRunners" }, 2]},
{ "Exp": [{ "Ordinal": "ActiveRunners" }, 3]},
"ZeroIntercept"
"Origin"
],
"w3": [
{ "Ordinal": "Weight0" },
Expand All @@ -24,6 +24,6 @@
{ "Ordinal": "ActiveRunners" },
{ "Exp": [{ "Ordinal": "ActiveRunners" }, 2]},
{ "Exp": [{ "Ordinal": "ActiveRunners" }, 3]},
"ZeroIntercept"
"Origin"
]
}
6 changes: 3 additions & 3 deletions config/thoroughbred.cf.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
3
]
},
"ZeroIntercept"
"Origin"
],
"coefficients": [
1.4714802210953573,
Expand Down Expand Up @@ -91,7 +91,7 @@
3
]
},
"ZeroIntercept"
"Origin"
],
"coefficients": [
1.2069350824699938,
Expand Down Expand Up @@ -143,7 +143,7 @@
3
]
},
"ZeroIntercept"
"Origin"
],
"coefficients": [
1.2428287117834143,
Expand Down
6 changes: 3 additions & 3 deletions config/thoroughbred.r.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{ "Ordinal": "ActiveRunners" },
{ "Exp": [{ "Ordinal": "ActiveRunners" }, 2]},
{ "Exp": [{ "Ordinal": "ActiveRunners" }, 3]},
"ZeroIntercept"
"Origin"
],
"w2": [
{ "Ordinal": "Weight0" },
Expand All @@ -15,7 +15,7 @@
{ "Ordinal": "ActiveRunners" },
{ "Exp": [{ "Ordinal": "ActiveRunners" }, 2]},
{ "Exp": [{ "Ordinal": "ActiveRunners" }, 3]},
"ZeroIntercept"
"Origin"
],
"w3": [
{ "Ordinal": "Weight0" },
Expand All @@ -24,6 +24,6 @@
{ "Ordinal": "ActiveRunners" },
{ "Exp": [{ "Ordinal": "ActiveRunners" }, 2]},
{ "Exp": [{ "Ordinal": "ActiveRunners" }, 3]},
"ZeroIntercept"
"Origin"
]
}
10 changes: 5 additions & 5 deletions src/linear/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum Regressor<O: AsIndex> {
Exp(Box<Regressor<O>>, i32),
Product(Vec<Regressor<O>>),
Intercept,
ZeroIntercept,
Origin,
}
impl<O: AsIndex> Regressor<O> {
pub fn resolve(&self, input: &[f64]) -> f64 {
Expand All @@ -36,12 +36,12 @@ impl<O: AsIndex> Regressor<O> {
.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)
}
}

Expand Down Expand Up @@ -102,7 +102,7 @@ impl<O: AsIndex> Predictor<O> {
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;
Expand Down Expand Up @@ -150,7 +150,7 @@ pub(crate) fn validate_regressors<O: AsIndex>(
bail!(
"must specify exactly one {} or {} regressor",
Regressor::<DummyOrdinal>::Intercept.to_string(),
Regressor::<DummyOrdinal>::ZeroIntercept.to_string()
Regressor::<DummyOrdinal>::Origin.to_string()
);
}
Ok(())
Expand Down
16 changes: 8 additions & 8 deletions src/linear/regression/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 178fd03

Please sign in to comment.