Skip to content

Conversation

@plidan123
Copy link
Collaborator

  • 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.

- 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.
@Desiment
Copy link
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

@Desiment Desiment closed this May 26, 2025
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.

3 participants