Пример #1
0
def main(argv):
    global symbName
    path = argv[0]
    symbName = argv[1]

    #optional parameter
    folderPath = None
    E = None
    if len(argv) >= 3:
        folderPath = argv[2]
    if len(argv) >= 4:
        E = argv[3]
    try:
        os.makedirs(savePath + symbName)
    except:
        if os.path.isfile(generateBettiSavePath()):
            print("Betti data already exists for: " + generateBettiSavePath())
            return

    print('Obtaining adjacency matrix...')
    #weights = loadWeights(path,['dense_1'])
    weights = loadWeightsCustom(folderPath, E)
    matrix = getWeightedAdjacencyMatrixNoBias(weights)
    print('Transforming weight matrix into distance matrix...')
    matrix = makeWeightAbsoluteDistance(matrix)
    #np.save(savePath + symbName + "/" + 'originalMatrix.npy', matrix)
    matrix = removeZeros(matrix)
    print('Running Floyd-Warshall (Transform to Shortest Distance Matrix)...')
    matrix = floyd_warshall_fastest(matrix)
    #np.save(savePath + symbName + "/" + 'shortMatrix.npy', matrix)
    print('Running VR Filtration...')
    runVRFiltration(matrix)
    return
Пример #2
0
def runPipeline(epoch):
    print('Loading Weights...')
    weights = wl.simpleLoader(nnSavePath(epoch))
    print('Generating Adjacency Matrix...')
    adjacencyMatrix = adj.getWeightedAdjacencyMatrixNoBias(weights)
    print('Preprocessing')
    processedMatrix = pp.standardVR(adjacencyMatrix)
    filtration.VR(vrSavePath(epoch), processedMatrix)

    print(f"Finished epoch: {epoch}")
Пример #3
0
def runFloydReplacement(config):
    import NNGeneration.nnUtil as utils
    import NNGeneration.NNDigits as digits
    import weightLoader as wl
    import generateAdjacencyMatrix as adj
    import preprocessing as pp
    from NNGeneration.DigitsPositive import base_model, get_dataset

    #model = digits.emptyModel(config)
    #xTrain,yTrain,xTest,yTest = utils.mnistTrainTest()
    model = base_model()
    xTrain, xTest, yTrain, yTest = get_dataset()
    trainAccs = []
    testAccs = []

    for epoch in config["epochs"]:
        weights = wl.simpleLoader(config["nnSaveFn"](epoch))
        adjacencyMatrix = adj.getWeightedAdjacencyMatrixNoBias(weights.copy())
        processedMatrix = pp.standardVR(adjacencyMatrix)

        model = utils.replaceModelParams(model, epoch, processedMatrix, config,
                                         weights)
        train = utils.getAccuracy(model, xTrain, yTrain)
        test = utils.getAccuracy(model, xTest, yTest)

        trainAccs.append(train)
        testAccs.append(test)

        print(f"Finished epoch: {epoch}. Train: {train}, Test: {test}")

    path = config["analysisSaveFn"] + "replacement/"
    if not os.path.isdir(path):
        os.mkdir(path)

    with open(path + "acc.txt", "w+") as f:
        for i in range(len(trainAccs)):
            f.write(f"{i},\t{trainAccs[i]},\t{testAccs[i]}")
    return
Пример #4
0
def main(argv):
	global symbName
	path = argv[0]
	symbName = argv[1]
	#optional parameter
	folderPath = None
	E = None
	if len(argv) >= 3:
		folderPath = argv[2]
	if len(argv) >= 4:
		E = argv[3]
	print('Epoch', E)
	print('Obtaining adjacency matrix...')
	#weights = loadWeights(path,['dense_1'])
	weights = loadWeightsCustom(folderPath, E)
	matrix = getWeightedAdjacencyMatrixNoBias(weights)
	print('Transforming weight matrix into distance matrix...')
	matrix = adjacencyToDistance(matrix)
	M1 = matrix
	print('Running Floyd-Warshall (Transform to Shortest Distance Matrix)...')
	matrix = floyd_warshall_fastest(matrix)
	#np.save(savePath + symbName + "/" + 'shortMatrix.npy', matrix)
	print(calculatePercentStatic(M1,matrix))
	return
Пример #5
0
    return ret


def symbName(e):
    return "CIFAR-10_" + str(e)


def pathName(e):
    return constant + "MODEL_Epoch" + str(e)


filepath = "NNGeneration/Saved Models/CIFAR-10-AML/model-{epoch:02d}.hdf5"
"NNGeneration/Saved Models/CIFAR-10-Variation2/MODEL_Epoch9_W7.npy"

W = loadweights.loadWeights(filepath.format(epoch=str(10)), ['dense_1'])
M1 = GAM.getWeightedAdjacencyMatrixNoBias(W)
M2 = makeAllGraphs.main(["", "0", "-w", "-nb", None, path + fn + str(e)])
print(np.allclose(M1, M2, atol=tol))


def check_symmetric(a, tol=1e-8):
    return


assert False
epochs = 125
matrices = []
for e in range(epochs + 1):
    m = makeAllGraphs.main(["", "0", "-w", "-nb", None, path + fn + str(e)])
    matrices.append(m)