-
Notifications
You must be signed in to change notification settings - Fork 15
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
refactor: statistical functions #1420
Conversation
Reviewer's Guide by SourceryThis pull request refactors the statistical functions across multiple distribution types (normal, exponential, lognormal, and Weibull) to improve maintainability, abstraction, and testing. The key changes include centralizing common statistical calculations, refining distribution-specific methods, and enhancing unit test coverage. Class diagram for refactored statistical functionsclassDiagram
class Distributions {
+calculate_hazard_rate(time: float, location: float, scale: Optional[float], shape: Optional[float], dist_type: str) float
+calculate_mtbf(shape: float, location: float, scale: float, dist_type: str) float
+calculate_survival(shape: float, time: float, location: float, scale: float, dist_type: str) float
}
class Normal {
+get_hazard_rate(location: float, scale: float, time: float) float
+get_mtbf(location: float, scale: float) float
+get_survival(location: float, scale: float, time: float) float
+do_fit(data, kwargs) Tuple[float, float]
}
class Exponential {
+get_hazard_rate(scale: float, location: float) float
+get_mtbf(rate: float, location: float) float
+get_survival(scale: float, time: float, location: float) float
+do_fit(data, kwargs) Tuple[float, float]
}
class Lognormal {
+get_hazard_rate(shape: float, location: float, scale: float, time: float) float
+get_mtbf(shape: float, location: float, scale: float) float
+get_survival(shape: float, location: float, scale: float, time: float) float
+do_fit(data, kwargs) Tuple[float, float, float]
}
class Weibull {
+get_hazard_rate(shape: float, location: float, scale: float, time: float) float
+get_mtbf(shape: float, location: float, scale: float) float
+get_survival(shape: float, location: float, scale: float, time: float) float
+do_fit(data, kwargs) Tuple[float, float, float]
}
Distributions <|-- Normal
Distributions <|-- Exponential
Distributions <|-- Lognormal
Distributions <|-- Weibull
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @weibullguy - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
_z_norm = ( | ||
stats.norm.ppf(1.0 - ((1.0 - alpha / 100.0) / 2.0)) | ||
if alpha > 1.0 | ||
else 1.0 - ((1.0 - alpha) / 2.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Potential bug in _z_norm calculation for alpha <= 1.0
The calculation for _z_norm when alpha <= 1.0 seems incorrect. It should probably use stats.norm.ppf() here as well, with appropriate scaling of alpha.
Does this pull request introduce a breaking change?
Purpose of this pull request
This pull request refactors the statistical functions across multiple distribution types (normal, exponential, lognormal, and Weibull) to improve maintainability, abstraction, and testing. The key goals include:
Benefits of the pull request
Any particular area(s) reviewers should focus on
Any other pertinent information
Pull Request Checklist
Code Style
Static Checks
this PR.
Tests
Chores
this PR. These problem areas have been decorated with an ISSUE: # comment.
Summary by Sourcery
Refactor statistical functions to centralize shared logic for hazard rate, MTBF, and survival calculations, improving maintainability and consistency across distribution types. Enhance unit test coverage by adding new test cases for edge conditions to ensure robustness.
Enhancements:
Tests: