Skip to content

[ENH] Weibull distribution#242

Merged
fkiraly merged 10 commits into
sktime:mainfrom
malikrafsan:weibull-dist
Apr 17, 2024
Merged

[ENH] Weibull distribution#242
fkiraly merged 10 commits into
sktime:mainfrom
malikrafsan:weibull-dist

Conversation

@malikrafsan

@malikrafsan malikrafsan commented Apr 6, 2024

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

#22

What does this implement/fix? Explain your changes.

Weibull probability distribution

Does your contribution introduce a new dependency? If yes, which one?

no

What should a reviewer concentrate their feedback on?

  • Energy formula for weibull distribution

Did you add any tests for the change?

  • Yes, I try to install this library locally using pip install --editable .[dev,test] and create a simple driver program to use this new distribution

Any other comments?

  • I use the formula from Wikipedia, which can be accessed here

PR checklist

For all contributions
  • I've added myself to the list of contributors with any new badges I've earned :-)
    How to: add yourself to the all-contributors file in the skpro root directory (not the CONTRIBUTORS.md). Common badges: code - fixing a bug, or adding code logic. doc - writing or improving documentation or docstrings. bug - reporting or diagnosing a bug (get this plus code if you also fixed the bug in the PR).maintenance - CI, test framework, release.
    See here for full badge reference
  • The PR title starts with either [ENH], [MNT], [DOC], or [BUG]. [BUG] - bugfix, [MNT] - CI, test framework, [ENH] - adding or improving code, [DOC] - writing or improving documentation or docstrings.
For new estimators
  • I've added the estimator to the API reference - in docs/source/api_reference/taskname.rst, follow the pattern.
  • I've added one or more illustrative usage examples to the docstring, in a pydocstyle compliant Examples section.
  • If the estimator relies on a soft dependency, I've set the python_dependencies tag and ensured
    dependency isolation, see the estimator dependencies guide.

@malikrafsan malikrafsan marked this pull request as ready for review April 7, 2024 05:59
@fkiraly fkiraly added enhancement module:probability&simulation probability distributions and simulators labels Apr 7, 2024

@fkiraly fkiraly left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! Looks great!

  • I'd name the parameters differently. The "lambda" or rate parameter is typically called the scale parameter, and identical with your current scale parameter. Your current lambda_val is the power or shape parameter, I would not call this "lambda" because that's typically the other parameter (your current scale).
  • we should probably deal with negative x. Everthing is either 0 or na there.
  • some further remarks on explicit forms below

Comment thread skpro/distributions/weibull.py Outdated
def log_pdf(self, x):
"""Logarithmic probability density function."""
d = self.loc[x.index, x.columns]
lpdf_arr = np.log(d.lambda_val / d.scale) + (d.lambda_val - 1) * np.log(x.values / d.scale) - (x.values / d.scale) ** d.lambda_val

@fkiraly fkiraly Apr 7, 2024

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think you can cancel some of the logs here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there any log that we can cancel? I can only think of storing division calculation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ahh I think I got it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am not really sure which one is simpler

$ln(k) + (k-1) \times ln(x) - k \times ln(\lambda)$

or

$ln( \frac{k}{\lambda^k} ) + (k-1) \times ln(x)$

I think it is the first option as it offers a simpler equation(?)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think the first option is numerically more stable, becaues over the course of the calculation your numbers stay in a narrower range.

@malikrafsan

Copy link
Copy Markdown
Contributor Author

I'd name the parameters differently. The "lambda" or rate parameter is typically called the scale parameter, and identical with your current scale parameter. Your current lambda_val is the power or shape parameter, I would not call this "lambda" because that's typically the other parameter (your current scale).

Ahh yes, thank you so much for pointing this out!! I think previously I read the formula description reversed. I have adjusted this. Once again, thank you so much for pointing this out!

@fkiraly

fkiraly commented Apr 10, 2024

Copy link
Copy Markdown
Collaborator

Great! Let us know when you would like a review.

@fkiraly fkiraly left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks

@fkiraly fkiraly merged commit ea7ce6d into sktime:main Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement module:probability&simulation probability distributions and simulators

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants