feat: add batch support for mixture evaluations#43
Closed
Conversation
- Extended `moment`, `pdf`, `cdf`, and `logpdf` methods to support both single values and lists of inputs for batch computation. - Improved usability and performance for vectorized mixture evaluations. - Fixed type annotation issues to resolve mypy errors and ensure compliance with abstract base class method signatures. This enhancement improves usability and performance for batch evaluations.
Collaborator
|
Instead of having in each class two methods: class NMMixture:
compute_pdf(self, ...):
...
compute_pdfs(self, ...):
...It is much preferable to make "public" and "private" variants, where "public" variant defined in base class and handles inputs, and "private" variant defined in child class: class AbstractMixture:
@abstractmethod
# "private" variant that containts computation logic for one input
def _compute_pdf(x: float, ...) -> float:
...
# "public" variant that handles input type
def compute_pdf(x: List[float] | float | NDArray[np.float64], ...) -> List[float] | float | NDArray[np.float64]
# handle input type
if isinstance(x, np.NDArray[float]):
return np.array([self._compute_pdf(xp) for xp in x])
if isinstance(x, list):
return [self._compute_pdf(xp) for xp in x]
if isinstance(x, float):
return self._compute_pdf(x)Closing, because waiting for #40 to be merged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
moment,pdf,cdf, andlogpdfmethods to support both single values and lists of inputs for batch computation.This enhancement improves usability and performance for batch evaluations.