Skip to content

Commit

Permalink
fix betti numbers calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-louvet committed Oct 5, 2020
1 parent bf99275 commit da8462f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
21 changes: 12 additions & 9 deletions bettiScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import tensorflow as tf
tf.compat.v1.disable_eager_execution()

holeDimList = [[2, 1], [2, 2], [2], [1], [3, 2],
[3, 3], [3], [2], [4, 3], [4, 4], [4], [3]]

score = [0, 0, 0, 0, 0, 0, 0, 0, 0]

instanceNumber = int(sys.argv[1])
Expand All @@ -21,7 +24,7 @@
randomSeed = pickle.load(input)

dataDescriptor = DataDescriptor(nHoles=len(centerList), centerList=centerList,
radiusList=radiusList, random=t.time(), bounds=bounds)
radiusList=radiusList, random=t.time(), bounds=bounds, holeDimension=holeDimList[i])

instance = dataDescriptor.generateData(classNumber=2, pointsNumber=50000)
data_betti = instance.newBettiNumbers(threshold=0.04, nPoints=5000)
Expand All @@ -48,42 +51,42 @@
predictedTest = test.predict(model2, verbose=1)
temp2 = predictedTest.newBettiNumbers(threshold=0.04, nPoints=50000)
if temp2 == data_betti:
score[0] += 1
score[1] += 1

predictedTest = test.predict(model4, verbose=1)
temp4 = predictedTest.newBettiNumbers(threshold=0.04, nPoints=50000)
if temp4 == data_betti:
score[0] += 1
score[2] += 1

predictedTest = test.predict(model6, verbose=1)
temp6 = predictedTest.newBettiNumbers(threshold=0.04, nPoints=50000)
if temp6 == data_betti:
score[0] += 1
score[3] += 1

predictedTest = test.predict(model8, verbose=1)
temp8 = predictedTest.newBettiNumbers(threshold=0.04, nPoints=50000)
if temp8 == data_betti:
score[0] += 1
score[4] += 1

predictedTest = test.predict(model10, verbose=1)
temp10 = predictedTest.newBettiNumbers(threshold=0.04, nPoints=50000)
if temp10 == data_betti:
score[0] += 1
score[5] += 1

predictedTest = test.predict(model12, verbose=1)
temp12 = predictedTest.newBettiNumbers(threshold=0.04, nPoints=50000)
if temp12 == data_betti:
score[0] += 1
score[6] += 1

predictedTest = test.predict(model14, verbose=1)
temp14 = predictedTest.newBettiNumbers(threshold=0.04, nPoints=50000)
if temp14 == data_betti:
score[0] += 1
score[7] += 1

predictedTest = test.predict(model16, verbose=1)
temp16 = predictedTest.newBettiNumbers(threshold=0.04, nPoints=50000)
if temp16 == data_betti:
score[0] += 1
score[8] += 1

breakpoint()
file = open(directory + '/betti.txt', "w")
Expand Down
21 changes: 18 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

def independent(x, S):
import numpy as np
mat = S.copy()
mat.append(x)
rank = np.linalg.matrix_rank(mat)
mat = []
for i in range(len(S[0])):
temp = []
for j in range(len(S)):
temp.append(S[j][i])
temp.append(x[i])
mat.append(temp)
rank = np.linalg.matrix_rank(mat, tol=0.1)
return rank == len(mat[0])


Expand All @@ -20,3 +25,13 @@ def findPointStructDimension(pointList):
if independent(head, B):
B.append(head)
return len(B) - 1


def selectRandomSublist(L, s):
import random as r
res = []
for _ in range(s):
random = r.randint(0, len(L) - 1)
a = L.pop(random)
res.append(a)
return res

0 comments on commit da8462f

Please sign in to comment.