bioFAM/slalom

AttributeError: 'float' object has no attribute 'exp'

deto opened this issue · 2 comments

deto commented

self.W.C[:, m,0] = 1./(1+SP.exp(-u_qm))

I'm getting an error from line 414 in core.py

AttributeError: 'float' object has no attribute 'exp'

I believe the cause is that u_qm is all 'inf' and this seems to be because logPi is all 'inf'. Do you know of any reason this would be happening? I'm running on 13k genes, 707 terms, and 4k cells.

deto commented

I think the issue may have been how I was loading the data - the cell ids were getting pushed into data['Y'].

I had saved my data as a csv using df.T.to_csv('slalom.csv.gz', compression='gzip') and this put a comma as the first character in the first row (basically the index name is empty). If I remove this comma and reload, then data['Y'] is all numeric as I suspect it should be. Re-running now, but this likely caused the issue downstream.

Hi, I have the same error- any idea how to resolve this?

Error message:

`---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
AttributeError: 'float' object has no attribute 'exp'

The above exception was the direct cause of the following exception:

TypeError Traceback (most recent call last)
Cell In[143], line 14
10 gene_ids = data['genes']
13 #initialize FA instance, here using a Gaussian noise model and fitting 3 dense hidden factors
---> 14 FA = slalom.initFA(Y, terms,I, noise='gauss', nHidden=3, nHiddenSparse=0)

File ~/anaconda3/lib/python3.10/site-packages/slalom/utils.py:947, in initFA(Y, terms, I, gene_ids, nHidden, nHiddenSparse, pruneGenes, FPR, FNR, noise, minGenes, do_preTrain, nFix, priors, covariates, dropFactors, learnPi)
944 num_terms += 1
946 if do_preTrain==True:
--> 947 Ilabel = preTrain(Y, terms, pi, noise=noise, nFix=nFix, priors=priors, covariates=covariates)
948 pi = pi[:,Ilabel]
949 terms = terms[Ilabel]

File ~/anaconda3/lib/python3.10/site-packages/slalom/utils.py:536, in preTrain(Y, terms, P_I, noise, nFix, priors, covariates)
534 FA.init(**init)
535 for j in range(50):
--> 536 FA.update()
539 #Run reverse model for 50 iterations
540 pi = pi0[:,mRangeRev]

File ~/anaconda3/lib/python3.10/site-packages/slalom/core.py:510, in CSparseFA.update(self)
508 if self.doUpdate[m]==1:
509 if self.dropFactors==False or self.iterationCount <10 or (self.Alpha.E1[m]/self.S.E1[:,m].var())<1e10:
--> 510 self.updateW(m)
512 if self.learnPi==True:
513 if m in self.iLatentSparse:#SP.hstack([self.iLatentSparse, self.iLatent]):

File ~/anaconda3/lib/python3.10/site-packages/slalom/core.py:414, in CSparseFA.updateW(self, m)
412 u_qm = logPi + 0.5SP.log(sigma2Sigmaw) - 0.5SP.log(SmTSmSig) + (0.5self.Eps.E1)((diff**2)/SmTSmSig)
413 with SP.errstate(over='ignore'):
--> 414 self.W.C[:, m,0] = 1./(1+SP.exp(-u_qm))
417 self.W.C[:,m,1] = 1-self.W.C[:,m,0]
418 self.W.E1[:, m] = (diff/SmTSmSig) #q(w_qm | s_qm=1), q=1,...,Q

File ~/anaconda3/lib/python3.10/site-packages/scipy/_lib/deprecation.py:20, in _deprecated..wrap..call(*args, **kwargs)
16 @functools.wraps(fun)
17 def call(*args, **kwargs):
18 warnings.warn(msg, category=DeprecationWarning,
19 stacklevel=stacklevel)
---> 20 return fun(*args, **kwargs)

TypeError: loop of ufunc does not support argument 0 of type float which has no callable exp method`