Skip to content

Error should be more explicit when diverging #65

@jaanisfehling

Description

@jaanisfehling

I am gettintg ValueError: pvals < 0, pvals > 1 or pvals contains NaNs while running this code

descriptor = {}
if len(num_cols) > 0:
    descriptor["cont_model"] = {
        "model": "gaussian_spherical_nan",
        "n_columns": len(num_cols),
    }
if len(cat_cols) > 0:
    descriptor["cat_model"] = {
        "model": "multinoulli_nan",
        "n_columns": len(cat_cols),
    }
if len(bool_cols) > 0:
    descriptor["bool_model"] = {
        "model": "bernoulli_nan",
        "n_columns": len(bool_cols),
    }
df = df[num_cols + cat_cols + bool_cols]  # reorder columns

model = StepMix(
    n_components=3,
    measurement=descriptor,
    progress_bar=0,
)
p_values = blrt_sweep(model, df, None, low=2, high=7, n_repetitions=1, verbose=False)
k = p_values.reset_index()["p"].idxmax() + 2

Full Traceback:

analyze.py:64: in main
    p_values = blrt_sweep(model, df, None, low=2, high=7, n_repetitions=1, verbose=False)
../../.cache/pypoetry/virtualenvs/clust-R4YYD0nC-py3.12/lib/python3.12/site-packages/stepmix/bootstrap.py:307: in blrt_sweep
    blrt(
../../.cache/pypoetry/virtualenvs/clust-R4YYD0nC-py3.12/lib/python3.12/site-packages/stepmix/bootstrap.py:243: in blrt
    _, stats_null = bootstrap(
../../.cache/pypoetry/virtualenvs/clust-R4YYD0nC-py3.12/lib/python3.12/site-packages/stepmix/bootstrap.py:140: in bootstrap
    X_rep, Y_rep, _ = sampler.sample(n_samples)
../../.cache/pypoetry/virtualenvs/clust-R4YYD0nC-py3.12/lib/python3.12/site-packages/stepmix/stepmix.py:1592: in sample
    [self._mm.sample(c, int(sample)) for c, sample in enumerate(n_samples_comp)]
../../.cache/pypoetry/virtualenvs/clust-R4YYD0nC-py3.12/lib/python3.12/site-packages/stepmix/emission/nested.py:100: in sample
    acc.append(m.sample(class_no, n_samples))
../../.cache/pypoetry/virtualenvs/clust-R4YYD0nC-py3.12/lib/python3.12/site-packages/stepmix/emission/categorical.py:232: in sample
    self.random_state.multinomial(1, feature_weights[k], size=n_samples)
numpy/random/mtrand.pyx:4354: in numpy.random.mtrand.RandomState.multinomial
    ???
_common.pyx:391: in numpy.random._common.check_array_constraint
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

>   ???
E   ValueError: pvals < 0, pvals > 1 or pvals contains NaNs

_common.pyx:377: ValueError

So apparently its related to the numpy random multinomial function.

Runtime warnings I also get:

lib/python3.12/site-packages/stepmix/emission/gaussian.py:360: RuntimeWarning: divide by zero encountered in divide
    precision_c = 1 / self.parameters["covariances"][c]

lib/python3.12/site-packages/stepmix/emission/gaussian.py:361: RuntimeWarning: invalid value encountered in multiply
    ll_diff = ((diff**2) * precision_c.reshape(1, -1)).sum(axis=1)

lib/python3.12/site-packages/stepmix/emission/gaussian.py:369: RuntimeWarning: divide by zero encountered in log
    log_dets = np.log(pi_cov_c).sum(axis=1

lib/python3.12/site-packages/stepmix/emission/gaussian.py:371: RuntimeWarning: invalid value encountered in add
    log_eps[:, c] = -0.5 * (log_dets + ll_diff)

lib/python3.12/site-packages/stepmix/stepmix.py:968: ConvergenceWarning: Initializations did not converge. Try different init parameters, or increase max_iter, abs_tol, rel_tol or check for degenerate data.
    warnings.warn(

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions