Comments (3)
@ubauer
Hi Uli,
I have pasted some code below that I use to test the cocycles. First, here's how it should look on this example, and how it looks if you compile what's on master (python setup.py install). You can visually verify the cocycle condition below. Vertex indices are plotted in red, cocycle values in blue. Orientation goes from white to black along the edge. In the list below, I show what gets returned from the program, which is vertex index 1, vertex index 2, and cocycle value in each row
[[11 2 16]
[ 4 1 1]
[ 3 1 1]
[ 3 0 1]
[ 2 1 1]
[ 2 0 1]]
Here's what happens when you checkout the sparsedm branch. Notice how some of the simplices have more than one, conflicting value. For instance, edge 2->1 has both 1, 2, and 0
[[2 1 1]
[2 1 2]
[0 1 2]
[1 2 0]
[3 1 1]
[2 1 2]]
import numpy as np
import matplotlib.pyplot as plt
from ripser import Rips
def drawLineColored(X, C):
for i in range(X.shape[0]-1):
plt.plot(X[i:i+2, 0], X[i:i+2, 1], c=C[i, :], lineWidth = 3)
def plotCocycle2D(r, X, cocycle, thresh):
"""
Given a 2D point cloud X, display a cocycle projected
onto edges under a given threshold "thresh"
"""
D = r.dm_
#Plot all edges under the threshold
N = X.shape[0]
t = np.linspace(0, 1, 10)
c = plt.get_cmap('Greys')
C = c(np.array(np.round(np.linspace(0, 255, len(t))), dtype=np.int32))
C = C[:, 0:3]
for i in range(N):
for j in range(N):
if D[i, j] <= thresh:
Y = np.zeros((len(t), 2))
Y[:, 0] = X[i, 0] + t*(X[j, 0] - X[i, 0])
Y[:, 1] = X[i, 1] + t*(X[j, 1] - X[i, 1])
drawLineColored(Y, C)
#Plot cocycle projected to edges under the chosen threshold
for k in range(cocycle.shape[0]):
[i, j, val] = cocycle[k, :]
if D[i, j] <= thresh:
[i, j] = [min(i, j), max(i, j)]
a = 0.5*(X[i, :] + X[j, :])
plt.text(a[0], a[1], '%g'%val, color='b')
#Plot vertex labels
for i in range(N):
plt.text(X[i, 0], X[i, 1], '%i'%i, color='r')
plt.axis('equal')
def testCocycle():
#Setup noisy circle with 12 points
np.random.seed(5)
n = 12
t = np.linspace(0, 2*np.pi, n+1)[0:n]
x = np.zeros((n, 2))
x[:, 0] = np.cos(t)
x[:, 1] = np.sin(t)
x += 0.1*np.random.randn(n, 2)
r = Rips(coeff=17, do_cocycles=True)
diagrams = r.fit_transform(x)
plt.figure(figsize=(12, 6))
#Extract the index of the most persistence point in H1
dgm1 = diagrams[1]
idx = np.argmax(dgm1[:, 1] - dgm1[:, 0])
plt.subplot(121)
r.plot(diagrams, plot_only = [1], show = False)
#Store cocycle from class we chose
cocycle = r.cocycles_[1][idx]
print(cocycle)
#Project cocycle onto edges less slightly less than the death time and plot
thresh = dgm1[idx, 1]-0.00001
plt.subplot(122)
plotCocycle2D(r, x, cocycle, thresh)
plt.title("1-Form Thresh=%g"%thresh)
plt.show()
testCocycle()
from ripser.py.
Okay, I have gotten to the point with 631fe33 where the above example is fixed, but I'm finding with larger examples (200 points) that sometimes the code freezes when trying to pop off elements from the working_reduction_column (this doesn't happen in master). @ubauer I noticed you merged together sparse distance matrices and cocycles in
https://github.com/Ripser/ripser/tree/representative-cocycles
Is that branch stable with both sparse matrix support and popping off the representative cocycles? If so, I think I'm going to do my edits over again starting with this branch
from ripser.py.
Hi Chris,
that branch has both sparse matrix support and representative cocycles. I wouldn't call it stable, I haven't done extensive testing on it yet, but it's the best place to start.
from ripser.py.
Related Issues (20)
- std::overflow_error
- Issue with plotting dependencies import HOT 7
- ValueError: numpy.ndarray size changed, may indicate binary incompatibility. HOT 7
- Build failure on GNU/Linux (GCC 11.1.0 and Python 3.9.6 on Arch Linux) HOT 3
- Jupyter notebook crash on input of large sparse distance matrix HOT 1
- [Suggestion] Throw exception when computing bottleneck distance
- Dead comments in 0-dimensional computation/preferential treatment of edges with zero value
- get_greedy_perm (Samples)
- Get the indices of the vectors forming a hole HOT 2
- Install Ripser on ArchLinux HOT 2
- ld: cannot find /lib64/libpthread.so.0
- `ValueError: numpy.ndarray size changed` HOT 5
- Failed to build ripser, error: subprocess-exited-with-error HOT 6
- Knowing required RAM to run ripser
- Unsuccessful installation HOT 2
- Is there a way to get ripser to use virtual memory? HOT 2
- Failed building wheel for Ripser on Win11 HOT 3
- ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject HOT 1
- Failed building wheel for ripser HOT 1
- Failing to generate H1 result with small dataset. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ripser.py.