persim icon indicating copy to clipboard operation
persim copied to clipboard

prism Persistent Image issue

Open aranos-tda opened this issue 4 years ago • 2 comments

I have an issue producing Persistent Images using Prism in Python. I'm generating Persistent Diagrams using Dionysus software in python. My problem is I can not generate persistent images from dionysus out. I have converted the output into a NumPy array but still give me a 'TypeError'. Below is my code and the error message:

import dionysus as d
import numpy as np
from sklearn.preprocessing import normalize
import matplotlib.pyplot as plt
from persim import PersImage
Image = plt.imread("8.png")
normed_matrix = normalize(Image, axis=1, norm='l1')
f_lower_star = d.fill_freudenthal(normed_matrix)
p = d.homology_persistence(f_lower_star)
dgms = d.init_diagrams(p, f_lower_star)
#### I do not have an issue until that point , it is the Persistent Image step that gives me error !
pim = PersImage(pixels=[20,20],spread=1,verbose=False )
img = pim.transform(dgms[1])

And the error I get is the following:

TypeError Traceback (most recent call last) in ----> 1 img = pim.transform(dgms) ~/anaconda3/lib/python3.7/site-packages/persim/images.py in transform(self, diagrams) 92 diagrams = [diagrams] 93 ---> 94 dgs = [np.copy(diagram, np.float64) for diagram in diagrams] 95 landscapes = [PersImage.to_landscape(dg) for dg in dgs] 96 ~/anaconda3/lib/python3.7/site-packages/persim/images.py in (.0) 92 diagrams = [diagrams] 93 ---> 94 dgs = [np.copy(diagram, np.float64) for diagram in diagrams] 95 landscapes = [PersImage.to_landscape(dg) for dg in dgs] 96 <array_function internals> in copy(*args, **kwargs) ~/anaconda3/lib/python3.7/site-packages/numpy/lib/function_base.py in copy(a, order, subok) 790 791 """ --> 792 return array(a, order=order, subok=subok, copy=True) 793 794 # Basic operations

TypeError: order must be str, not type

I have later converted the dionysus output into a python list, and a numpy array using the following:

l = [(pt.birth, pt.death) for pt in dgms[1]]
f=np.asarray(l)

but I still get the same error !!!!

Any help will be appreciated. Many Thanks Aras

aranos-tda avatar Oct 01 '20 12:10 aranos-tda

Hi,

I am using the Persim module to produce the persistent image based on the diagrams generated by RIPS (https://github.com/scikit-tda/ripser.py).

`rips = Rips(maxdim=0)

dgms = rips.fit_transform(data)

plot_diagrams(dgms, show=True)

pim = PersImage(pixels =[100,100],spread =1)

imgs = pim.transform(dgms)

plt.figure(figsize=(15,15))

pim.show(imgs)`

However, I get the following runtime warning: `Rips(maxdim=0, thresh=inf, coeff=2, do_cocycles=False, n_perm = None, verbose=True) I am done with rips PersImage(pixels=[100, 100], spread=1, specs=None, kernel_type="gaussian", weighting_type="linear") Traceback (most recent call last):

File "/Users/kianamac/Desktop/mahdi files/index.py", line 44, in imgs = pim.transform(dgms)

File "/Users/kianamac/Applications/anaconda3/lib/python3.8/site-packages/persim/images.py", line 104, in transform imgs = [self._transform(dgm) for dgm in landscapes]

File "/Users/kianamac/Applications/anaconda3/lib/python3.8/site-packages/persim/images.py", line 104, in imgs = [self._transform(dgm) for dgm in landscapes]

File "/Users/kianamac/Applications/anaconda3/lib/python3.8/site-packages/persim/images.py", line 119, in _transform xs_lower = np.linspace(minBD, maxBD, self.nx)

File "<array_function internals>", line 5, in linspace

File "/Users/kianamac/Applications/anaconda3/lib/python3.8/site-packages/numpy/core/function_base.py", line 153, in linspace y *= step

RuntimeWarning: invalid value encountered in multiply`

Would you please help me to understand what could be the source of the problem?

Thanks,

kalikhademi avatar Jan 06 '21 01:01 kalikhademi

Hi,

I am using the Persim module to produce the persistent image based on the diagrams generated by RIPS (https://github.com/scikit-tda/ripser.py).

`rips = Rips(maxdim=0)

dgms = rips.fit_transform(data)

plot_diagrams(dgms, show=True)

pim = PersImage(pixels =[100,100],spread =1)

imgs = pim.transform(dgms)

plt.figure(figsize=(15,15))

pim.show(imgs)`

However, I get the following runtime warning: `Rips(maxdim=0, thresh=inf, coeff=2, do_cocycles=False, n_perm = None, verbose=True) I am done with rips PersImage(pixels=[100, 100], spread=1, specs=None, kernel_type="gaussian", weighting_type="linear") Traceback (most recent call last):

File "/Users/kianamac/Desktop/mahdi files/index.py", line 44, in imgs = pim.transform(dgms)

File "/Users/kianamac/Applications/anaconda3/lib/python3.8/site-packages/persim/images.py", line 104, in transform imgs = [self._transform(dgm) for dgm in landscapes]

File "/Users/kianamac/Applications/anaconda3/lib/python3.8/site-packages/persim/images.py", line 104, in imgs = [self._transform(dgm) for dgm in landscapes]

File "/Users/kianamac/Applications/anaconda3/lib/python3.8/site-packages/persim/images.py", line 119, in _transform xs_lower = np.linspace(minBD, maxBD, self.nx)

File "<array_function internals>", line 5, in linspace

File "/Users/kianamac/Applications/anaconda3/lib/python3.8/site-packages/numpy/core/function_base.py", line 153, in linspace y *= step

RuntimeWarning: invalid value encountered in multiply`

Would you please help me to understand what could be the source of the problem?

Thanks,

@kalikhademi Not sure if it is still relevant, but I think the issue is that with Vietoris-Rips filtration, in dimension 0 all persistence pairs have birth=0, and thus there is not really a notion of 2D image there (as range of birth in birth-persistence diagram is [0, 0]).

jakipatryk avatar Sep 11 '22 13:09 jakipatryk