Commit 6ff67875 authored by Cas Spaans's avatar Cas Spaans

fixed bug with homemade random landmark, started torus

parent 64f3498c
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -823,7 +823,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.7.6"
}
},
"nbformat": 4,
......
import gudhi as gd
import numpy as np
import tadasets
from ripser import ripser
from persim import plot_diagrams
%matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import time
N = 500 #Number of initial points in (theta, phi) space
noise=0.01
n= 4
p=0.1
samplesize=round(N*p)
X=tadasets.infty_sign(n=N, noise=0)
xr = [np.min(X.flatten()), np.max(X.flatten())]
def get_eucl_dist_table(X,Y):
nrows= X.shape[0]
ncols= Y.shape[0]
D=np.zeros((nrows,ncols))
for i in range(nrows):
for j in range(ncols):
deltvec=X[i]-Y[j]
D[i,j]=np.linalg.norm(deltvec)
return D
D= get_eucl_dist_table(X,X)
def minmax_landmark_indices(D,n):
rows=D.shape[0]
l=np.array([np.random.randint(0,rows)])
temp= np.argmax(D[:,l[0]])
np.append(l,temp)
while len(l)<n:
templist=np.zeros(rows)
for i in range(rows):
templist[i]=np.min(D[i,l])
temp=np.argmax(templist)
l=np.append(l,temp)
return l
def random_landmark_indices(X,n):
l=np.random.choice(X.shape[0],size=n)
return l
def index_to_cloud(indices,X):
l=np.zeros([len(indices),X.shape[1]])
j=0
for i in indices:
l[j]=X[i]
j=j+1
return l
def make_landmark_table(X,landmark_indices,D,n):
rows=X.shape[0]
cols=n
nearest_landmark_table=np.zeros((rows,(cols)))
lst=[]
for i in range(rows):
temp=D[i,landmark_indices]
tempind=np.argsort(temp)
templst=[]
for j in range(cols):
templst.append((landmark_indices[tempind[j]],temp[tempind[j]]))
lst.append(templst)
return lst
randind=random_landmark_indices(X,samplesize)
randlandmarks=index_to_cloud(randind,X)
t1=time.time()
landtablerand=make_landmark_table(X,randind,D,3)
t2=time.time()
print("this random landmark table making takes:")
print(t2-t1)
st=gd.WitnessComplex(nearest_landmark_table=landtablerand).create_simplex_tree(max_alpha_square=1.)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment