BAMT icon indicating copy to clipboard operation
BAMT copied to clipboard

Wrapper for GMM

Open kmetra1910 opened this issue 9 months ago • 4 comments

Drop-in replacement for GMM from gmr

Implements:

.from_samples(...)

.sample(...)

.predict(...)

.to_responsibilities(...)

.condition(...)

Carefully replicates gmr behavior, including:

Manual initialization when n_samples < 2

Safe handling of degenerate weights (e.g., nan or negative)

Adds warnings instead of exceptions for better debug experience

image

This pull request includes several changes across multiple files to improve code readability and consistency. The most important changes involve adding missing imports, reformatting code for better readability, and updating string formatting.

Code Readability Improvements:

  • bamt/networks/base.py: Reformatted import statements and long lines to improve readability. [1] [2] [3] [4] [5]
  • bamt/nodes/conditional_mixture_gaussian_node.py: Reformatted long lines and updated the choose and predict methods for better readability. [1] [2] [3] [4]

Consistency Updates:

  • bamt/external/pyitlib/DiscreteRandomVariableUtils.py: Updated string formatting to use double quotes and reformatted long lines for consistency. [1] [2] [3] [4]
  • bamt/nodes/conditional_logit_node.py: Reformatted long lines and updated string formatting for consistency.

Minor Additions:

  • Added missing author information in test files. [1] [2] [3] [4]

Bug Fixes:

  • bamt/external/pyitlib/DiscreteRandomVariableUtils.py: Fixed assertion statements and improved error handling in _estimate_probabilities function. [1] [2] [3]

Import Updates:

  • bamt/nodes/conditional_mixture_gaussian_node.py: Replaced import from gmr to bamt.utils.gmm_wrapper for GMM.

kmetra1910 avatar Apr 14 '25 11:04 kmetra1910

Обновил исходя из PR review, добавил комменты, докстринги и остальное

kmetra1910 avatar Apr 14 '25 17:04 kmetra1910

Разве что надо убрать gmr теперь из requirements и pyproject.toml

jrzkaminski avatar Apr 18 '25 11:04 jrzkaminski

@jrzkaminski убирать тогда надо аккуратно -- перенести например в группу тестирования

Roman223 avatar Apr 18 '25 12:04 Roman223

Removed redundant validation from from_samples() method and cleaned up outdated comments. Confirmed that sklearn.GaussianMixture already handles insufficient data with its internal validation logic (as @Roman223 suggested).

All tests pass Suggest moving gmr removal and behavioral test redesign into the next PR, along with a cleaner initialization approach (as suggested by Roman) using sklearn subclassing or controlled parameter setup.

This will allow us to fully drop dependency on gmr and transition to robust behavioral testing (log-likelihood checks, cluster validation).

kmetra1910 avatar Apr 19 '25 17:04 kmetra1910