Topics

Difficulty understanding bar plot of persistent homology

eric.a.bunch@...
 

I'm using dionysus to compute persistent homology for a point cloud by using the `dionysus.fill_rips()` method, then using `dionysus.homology_persistence()`, and then plotting the bar chart using the `dionysus.plot().plot_bars()` method. I obtain a graph like the one following



My confution is, since I built the filtration by using `filtration = dionysus.fill_rips(point_cloud, 2, 0.25)`, I would expect the x-axis on the above graph to go from 0 to 0.25 instead of 0 to 0.06. I was anticipating the x-axis to be epsilon values corresponding to the Rips filtration, but this does not seem to be the case.

The code I'm using the generate the point cloud and the bar chart is below--it's a randomly generated point set, so the barcode diagram will not be the same as the above one.

```
n_pts = 100
rrnd = 0.5
alpha = [0.4, 0.6, 0.2, 0.4]
 
pc = np.array([[np.cos(x*np.pi) + alpha[0]*random.random(), np.sin(x*np.pi) + alpha[1]*random.random()] for 
      x in [(r + random.random()*rrnd)*(1/float(n_pts)) for r in range(-n_pts, n_pts)]])
 
f = d.fill_rips(pc, 2, 0.25)
p = d.homology_persistence(f)
dgms = d.init_diagrams(p, f)
 
plt.figure(figsize=(8, 8))
d.plot.plot_bars(dgms[1], show = True);
```

Dmitriy Morozov
 

Hi Eric,

Here's what's going on. When you give `fill_rips()` points in a Euclidean space, it works with squared distances. So the values assigned to the simplices in the Rips complex are really squares of the distances between the points that you are expecting.

```
for s in f:
  print(s)
...
<135,139,143> 0.0624394
```

The square root of the value of the last simplex is 0.24987877060686847, which is the last value below your .25 cutoff.

I realize how incredibly confusing this is, especially since it's not documented. It's an old habit of mine of avoiding square roots, and it's clearly biting us in this case. I should fix this. If you don't mind, can you file a bug report on GitHub?

Meanwhile, a quick fix is for you to take the square roots yourself:
```
for s in f:
  s.data = math.sqrt(s)
``` 

Sorry for the problem, and thanks for catching it.

Dmitriy


On Tue, Dec 5, 2017 at 12:19 PM, <eric.a.bunch@...> wrote:
I'm using dionysus to compute persistent homology for a point cloud by using the `dionysus.fill_rips()` method, then using `dionysus.homology_persistence()`, and then plotting the bar chart using the `dionysus.plot().plot_bars()` method. I obtain a graph like the one following



My confution is, since I built the filtration by using `filtration = dionysus.fill_rips(point_cloud, 2, 0.25)`, I would expect the x-axis on the above graph to go from 0 to 0.25 instead of 0 to 0.06. I was anticipating the x-axis to be epsilon values corresponding to the Rips filtration, but this does not seem to be the case.

The code I'm using the generate the point cloud and the bar chart is below--it's a randomly generated point set, so the barcode diagram will not be the same as the above one.

```
n_pts = 100
rrnd = 0.5
alpha = [0.4, 0.6, 0.2, 0.4]
 
pc = np.array([[np.cos(x*np.pi) + alpha[0]*random.random(), np.sin(x*np.pi) + alpha[1]*random.random()] for 
      x in [(r + random.random()*rrnd)*(1/float(n_pts)) for r in range(-n_pts, n_pts)]])
 
f = d.fill_rips(pc, 2, 0.25)
p = d.homology_persistence(f)
dgms = d.init_diagrams(p, f)
 
plt.figure(figsize=(8, 8))
d.plot.plot_bars(dgms[1], show = True);
```


eric.a.bunch@...
 

Dmitriy,

Thanks for the response! That makes sense, and I understand the aversion to avoiding square roots. The bug report on github is filed. If you would like me to make it more verbose, I can, but I figured it would be you reading it.

Best,
Eric

Dmitriy Morozov
 

Thanks, Eric. The bug report is perfect -- I just need a reminder. Dmitriy

On Mon, Dec 11, 2017 at 8:13 AM, <eric.a.bunch@...> wrote:
Dmitriy,

Thanks for the response! That makes sense, and I understand the aversion to avoiding square roots. The bug report on github is filed. If you would like me to make it more verbose, I can, but I figured it would be you reading it.

Best,
Eric