sHDP icon indicating copy to clipboard operation
sHDP copied to clipboard

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Open Noxius888 opened this issue 6 years ago • 2 comments

Running the code brings a Value error:

0.8 -mbsize 10 -dataset nips {'infSeed': 1, 'alpha': 1.0, 'gamma': 2.0, 'Nmax': 40, 'kappa_sgd': 0.6, 'tau': 0.8, 'mbsize': 10.0, 'dataset': 'nips'} Loading the glove dict file.... Main runner ... num_docs: 1566 Traceback (most recent call last): File "./runner.py", line 225, in HDPRunner(args) File "./runner.py", line 121, in HDPRunner components=[vonMisesFisherLogNormal(**obs_hypparams) for itr in range(K)] File "./runner.py", line 121, in components=[vonMisesFisherLogNormal(**obs_hypparams) for itr in range(K)] File "/home/noxius/Git/sHDP/core/core_distributions.py", line 242, in init if (mu,kappa) == (None,None) and None not in (mu_0,C_0,m_0,sigma_0): ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I tried different methods, including changing the boolean check in core_distributions.py, line 243:

if ((mu,kappa) == (None,None)) and any(x != None for x in (mu_0, C_0, m_0, sigma_0)): or if ((mu,kappa) == (None,None)) and not any(x == None for x in (mu_0, C_0, m_0, sigma_0)):

However it doesn't change anything and the error stays. Have you any solution?

Noxius888 avatar Mar 19 '19 15:03 Noxius888

I had the same problem and I solved it with downgrading numpy to version 1.11.3

My environment:

Ubuntu 18.04 LTS
python 3.6

IvanAntipov avatar Jul 17 '19 07:07 IvanAntipov

I replaced

        if (mu,kappa) == (None,None) and None not in (mu_0,C_0,m_0,sigma_0):

with

        if (mu,kappa) == (None,None) and mu_0 is not None and C_0 is not None and m_0 is not None and sigma_0 is not None:

And it seems to have made forward progress.

I also needed to replace

            logISweights = log_f - sc.misc.logsumexp(log_f)

with

            logISweights = log_f - sc.special.logsumexp(log_f)

ajbouh avatar Jan 27 '20 22:01 ajbouh