Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow creating a Box-Cox or Yeo-Johnson transform with either lambda or data #212

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

sd2k
Copy link
Collaborator

@sd2k sd2k commented Dec 20, 2024

This makes the Transform::box_cox and Transform::yeo_johnson constructors more flexible; users can either pass lambda directly or pass some data which will be used to find the optimal lambda.

Summary by CodeRabbit

  • New Features

    • Enhanced flexibility for Box-Cox and Yeo-Johnson transformations to accept both single values and slices.
    • Introduced new traits for obtaining lambda parameters, improving input versatility for transformation methods.
  • Bug Fixes

    • Improved error handling for transformation methods to manage potential optimization failures.

…ambda or data

This makes the Transform::box_cox and Transform::yeo_johnson constructors
more flexible; users can either pass lambda directly or pass some data which
will be used to find the optimal lambda.
Copy link
Contributor

coderabbitai bot commented Dec 20, 2024

Walkthrough

The pull request introduces significant enhancements to power transformation methods in the Augurs Forecaster library. The changes focus on improving the flexibility and error handling of Box-Cox and Yeo-Johnson transformations by adding new traits IntoBoxCoxLambda and IntoYeoJohnsonLambda. These traits allow the transformation methods to accept either single numeric values or slices of data for lambda parameter calculation, with improved error management through Result return types.

Changes

File Changes
crates/augurs-forecaster/src/transforms.rs - Updated box_cox method signature to accept generic lambda type with error handling
- Updated yeo_johnson method signature to accept generic lambda type with error handling
- Modified power_transform to return Result<Self, Error>
crates/augurs-forecaster/src/transforms/power.rs - Added IntoBoxCoxLambda trait with implementations for f64 and &[f64]
- Added IntoYeoJohnsonLambda trait with implementations for f64 and &[f64]

Sequence Diagram

sequenceDiagram
    participant User
    participant Transform
    participant Lambda Trait
    participant Optimizer

    User->>Transform: Call box_cox/yeo_johnson
    Transform->>Lambda Trait: Convert input to lambda
    Lambda Trait-->>Optimizer: Compute optimal lambda if slice provided
    Optimizer-->>Lambda Trait: Return lambda value
    Lambda Trait-->>Transform: Return lambda
    Transform->>Transform: Apply transformation
    Transform-->>User: Return transformed data or error
Loading

Possibly related PRs

Poem

🐰 Lambdas dancing, transformations bright,
Flexible methods taking flight!
From single values to data's array,
Errors caught in a graceful ballet
Power transforms with rabbit's might! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
crates/augurs-forecaster/src/transforms.rs (2)

170-170: Potentially wrap conversion errors with more specific context.
You are returning a generic error from trait conversion, which is perfectly valid. However, consider wrapping it with a context string like “Failed to convert lambda from user input” to aid troubleshooting.

Example diff for adding context:

-let lambda = lambda.into_box_cox_lambda()?;
+let lambda = lambda.into_box_cox_lambda().map_err(|e| Error::msg(format!("Box-Cox lambda conversion failed: {}", e)))?;

196-197: Mirror the same context for Yeo-Johnson conversion errors.
Similar to the Box-Cox transformation, adding context to the error handling here would give users improved clarity on why the conversion failed.

Example diff:

-let lambda = lambda.into_yeo_johnson_lambda()?;
+let lambda = lambda.into_yeo_johnson_lambda().map_err(|e| Error::msg(format!("Yeo-Johnson lambda conversion failed: {}", e)))?;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8058f3d and b871dd5.

📒 Files selected for processing (2)
  • crates/augurs-forecaster/src/transforms.rs (3 hunks)
  • crates/augurs-forecaster/src/transforms/power.rs (1 hunks)
🔇 Additional comments (4)
crates/augurs-forecaster/src/transforms.rs (3)

26-27: Imports for new transformation traits appear consistent.
No obvious issues are found here. Importing the newly added traits and functions follows a logical approach to keep the code modular and maintainable.


159-169: Documentation clarifies the new flexibility for Box-Cox transformations.
The block comment and parameter details do an excellent job explaining the acceptance of either a f64 or a &[f64]. This clarity is beneficial for library users.


185-195: Accurate explanation of Yeo-Johnson’s flexibility.
You’ve documented how negative and zero values are handled. This is essential for users. The method signature is consistent with the Box-Cox approach, which keeps the API uniform.

crates/augurs-forecaster/src/transforms/power.rs (1)

355-394: New traits elegantly abstract lambda determination.

  1. Implementation for f64 allows a direct pass-through of the parameter.
  2. Implementation for &[f64] leverages MLE to compute the optimal parameter, which is consistent with the broader logic in this PR.
    Overall, these traits reduce code duplication and provide a clean interface.

@sd2k sd2k merged commit e6cc399 into main Dec 20, 2024
24 checks passed
@sd2k sd2k deleted the more-flexible-box-cox-yeo-johnson branch December 20, 2024 08:53
@sd2k sd2k mentioned this pull request Dec 20, 2024
This was referenced Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant