예제 #1
0
def compute_sph2_pl1():
    sph2_pts = dsphere(n=100, d=2, r=1)
    sph2_dgm = ripser(sph2_pts, maxdim=2)['dgms']
    sph2_pl = PersLandscapeExact(diagrams=sph2_dgm, homological_degree=1)
    sph2_pl.compute_landscape()
    sph2_pl1_list.append(sph2_pl)
    return sph2_pl
예제 #2
0
def construct_random_landscape(_):
    sph2_pts = dsphere(n=100, d=2, r=1)
    sph2_dgm = ripser(sph2_pts, maxdim=2)['dgms']
    pl = PersistenceLandscapeGrid(start=_b,
                                  stop=_d,
                                  num_dims=500,
                                  diagrams=sph2_dgm,
                                  homological_degree=1)
    pl.compute_landscape()
    return pl
예제 #3
0
from histomicstk.segmentation import label as htk_label

import logging
logging.basicConfig(level=logging.CRITICAL)

from ctk_cli import CLIArgumentParser


def main(args):

    feature_list = []


# Initialize a noisy circle
X = tadasets.dsphere(n=100, d=1, r=1, noise=0.2)
# Instantiate and build a rips filtration
rips = cm.Rips(1)  #Go up to 1D homology
rips.build(X)
dgmsrips = rips.diagrams()

plt.subplot(121)
plt.scatter(X[:, 0], X[:, 1])
plt.axis('square')
plt.title("Point Cloud")
plt.subplot(122)
plot_diagrams(dgmsrips)
plt.title("Rips Persistence Diagrams")
plt.tight_layout()
plt.show()
예제 #4
0
#%% Construct a list of 100 landscapes from randomly sampled points.
sph2_dgm_list = []
sph3_dgm_list = []
sph2_pl1_list = []
sph2_pl2_list = []
sph3_pl1_list = []
sph3_pl2_list = []
#sph2_b = 100.
#sph2_d = -100.
#sph3_b = 100.
#sph3_d = -100.

#%%
for i in range(100):
    sph2_pts = dsphere(n=100, d=2, r=1)
    sph2_dgm = ripser(sph2_pts, maxdim=2)['dgms']
    #if min(sph2_dgm[1],key=itemgetter(0))[0] < sph2_b:
    #    sph2_b = min(sph2_dgm[1],key=itemgetter(0))[0]
    #if max(sph2_dgm[1],key=itemgetter(1))[1] > sph2_d:
    #    sph2_d = max(sph2_dgm[1],key=itemgetter(1))[1]
    sph2_dgm_list.append(sph2_dgm)

    sph3_pts = dsphere(n=100, d=3, r=1)
    sph3_dgm = ripser(sph3_pts, maxdim=2)['dgms']
    #if min(sph3_dgm[1],key=itemgetter(0))[0] < sph3_b:
    #    sph3_b = min(sph3_dgm[1],key=itemgetter(0))[0]
    #if max(sph3_dgm[1],key=itemgetter(1))[1] > sph3_d:
    #    sph3_d = max(sph3_dgm[1],key=itemgetter(1))[1]
    sph3_dgm_list.append(sph3_dgm)
#%%
예제 #5
0
# import PyLandscapes and nessasary functions
from PersistenceLandscapeGrid import PersistenceLandscapeGrid, snap_PL, average_grid
from PersistenceLandscapeExact import PersistenceLandscapeExact
from auxiliary import linear_combination
from visualization import plot_landscape


#  Sample 100 points from $S^2$ and $S^3$, 100 times and normalize

# In[2]:


# sph2: list of 100 runs of sampling S2
sph2 = []
for i in range(100):
    sph2.append( preprocessing.scale(dsphere(n=100, d=2, r=1)) ) #preprocessing.scale to normalize samples

# sph3: list of 100 runs of sampling S3
sph3 = []
for i in range(100):
    sph3.append( preprocessing.scale(dsphere(n=100, d=3, r=1)) )


# Compute persistence diagram for $S^2$ and $S^3$

# In[3]:


#sph2_dgm: list of 100 diagrams for 100 sampled points on S2
sph2_dgm = [ripser(sphere, maxdim=2)['dgms'] for sphere in sph2]
예제 #6
0
                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')


np.random.seed(9)
x = tadasets.dsphere(n=12, d=1, noise=0.1)
'''
data_path='centroid.dat' 
x=np.loadtxt(data_path,delimiter="\t", usecols=(0,1,2),dtype=float,skiprows=0)

fig=plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x[:, 0], x[:, 1],x[:,2])
plt.show()
'''

result = ripser(x)
#for key in result:
#	print(key, result[key])
diagrams = result['dgms']
cocycles = result['cocycles']
예제 #7
0
                    default='mpi')
args = parser.parse_args()

epsilon = args.epsilon
maxDim = args.dim
dataDim = args.datadim
npoints = args.npoints
centroids = args.centroids
reps = args.reps
mode = args.mode
noproc = args.np
timings = {}

print "Running " + mode + " experiments with:\nEpsilon: ", epsilon, "\nMaxDim", maxDim, "\ndataDim: ", dataDim, "\nnPoints: ", npoints, "\nCentroids: ", centroids, "\nNProcs", noproc, "\n"
''' Generate input data '''
originalData = tadasets.dsphere(n=npoints, d=dataDim - 1, r=1, noise=0.1)

for i in range(0, int(reps)):
    ''' Create folder for output '''
    outDir = "perf_dsphere_" + str(centroids) + "_e" + str(
        epsilon) + "_d" + str(maxDim) + "_np" + str(noproc) + "/" + str(
            i) + "/"
    if not os.path.exists(outDir):
        os.makedirs(outDir)

    if not os.path.isfile(os.getcwd() + "/aggResults.csv"):
        outfile = file(os.getcwd() + "/aggResults.csv", 'a')
        outfile.write(
            'OutputPath,No.Procs,Vectors,Dimensions,maxDim,Epsilon,Centroids,PH_Time(s),BettiCount\n'
        )
        outfile.close()
예제 #8
0
 def test_r(self):
     s = tadasets.dsphere(n=100, d=2, r=4)
     rs = np.fromiter((norm(p) for p in s), np.float64)
     assert np.all([4 - 1e-5 <= r <= 4 + 1e-5 for r in rs])
예제 #9
0
 def test_equivalence(self):
     s = tadasets.dsphere(n=100, d=2)
     rs = np.fromiter((norm(p) for p in s), np.float64)
     assert np.all([1 - 1e-5 <= r <= 1 + 1e-5 for r in rs])
예제 #10
0
 def test_d(self):
     s = tadasets.dsphere(n=100, d=2)
     assert s.shape[1] == 3
예제 #11
0
import collections
import tadasets
import numpy as np
import csv

torus = tadasets.torus(n=2000, c=2, a=1, ambient=200, noise=0.2)
swiss_roll = tadasets.swiss_roll(n=2000, r=4, ambient=10, noise=1.2)
dsphere = tadasets.dsphere(n=1000, d=12, r=3.14, ambient=14, noise=0.14)
inf_sign = tadasets.infty_sign(n=3000, noise=0.1)

np.savetxt('torus.csv', (torus), delimiter=',')
np.savetxt('swiss_roll.csv', (swiss_roll), delimiter=',')
np.savetxt('dsphere.csv', (dsphere), delimiter=',')
np.savetxt('inf_sign.csv', (inf_sign), delimiter=',')