Skip to content

Commit

Permalink
fix format and naming
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardcqian committed Dec 6, 2024
1 parent c3a908d commit ebfd3c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
6 changes: 2 additions & 4 deletions crates/augurs-forecaster/src/power_transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ impl CostFunction for BoxCoxProblem<'_> {
}

/// Optimize the lambda parameter for the Box-Cox transformation
pub fn optimize_lambda(data: &[f64]) -> f64{
let cost = BoxCoxProblem {
data: data,
};
pub fn optimize_lambda(data: &[f64]) -> f64 {
let cost = BoxCoxProblem { data: data };
let init_param = 0.5;
let solver = BrentOpt::new(-2.0, 2.0);

Expand Down
15 changes: 9 additions & 6 deletions crates/augurs-forecaster/src/transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::power_transforms::optimize_lambda;
/// The `Transforms` struct is a collection of `Transform` instances that can be applied to a time series.
/// The `Transform` enum represents a single transformation that can be applied to a time series.
#[derive(Debug, Default)]
pub (crate) struct Transforms(Vec<Transform>);
pub(crate) struct Transforms(Vec<Transform>);

impl Transforms {
/// create a new `Transforms` instance with the given transforms.
Expand Down Expand Up @@ -56,7 +56,7 @@ pub enum Transform {
/// Log transform.
Log,
/// Box-Cox transform.
BoxCox{
BoxCox {
/// The lambda parameter for the Box-Cox transformation.
/// If lambda == 0, the transformation is equivalent to the natural logarithm.
/// Otherwise, the transformation is (x^lambda - 1) / lambda.
Expand Down Expand Up @@ -108,7 +108,7 @@ impl Transform {
}

/// Create the power transform that optimizes the lambda parameter for the Box-Cox transformation.
///
///
/// This transform applies the Power transformation to each item.
/// The Power transformation is defined as:
///
Expand All @@ -127,7 +127,7 @@ impl Transform {
Self::MinMaxScaler(params) => Box::new(input.min_max_scale(params.clone())),
Self::Logit => Box::new(input.logit()),
Self::Log => Box::new(input.log()),
Self::BoxCox{lambda} => Box::new(input.boxcox(*lambda)),
Self::BoxCox { lambda } => Box::new(input.box_cox(*lambda)),
}
}

Expand All @@ -141,7 +141,7 @@ impl Transform {
Self::MinMaxScaler(params) => Box::new(input.inverse_min_max_scale(params.clone())),
Self::Logit => Box::new(input.logistic()),
Self::Log => Box::new(input.exp()),
Self::BoxCox{lambda} => Box::new(input.inverse_boxcox(*lambda)),
Self::BoxCox { lambda } => Box::new(input.inverse_box_cox(*lambda)),
}
}

Expand Down Expand Up @@ -415,7 +415,10 @@ impl<T> ExpExt for T where T: Iterator<Item = f64> {}
/// Returns the Box-Cox transformation of the given value.
/// Assumes x > 0.
pub fn box_cox(x: f64, lambda: f64) -> f64 {
assert!(x > 0.0, "Input x must be positive for Box-Cox transformation.");
assert!(
x > 0.0,
"Input x must be positive for Box-Cox transformation."
);
if lambda == 0.0 {
x.ln()
} else {
Expand Down

0 comments on commit ebfd3c7

Please sign in to comment.