def main(): import os os.chdir("/media/fabio/Storage/UCT/Thesis/Coding/MSc_Thesis_Obj1/src") # fetch data meshes = loadMeshes("../meshes/femurs/", ply_Bool=False) # dims 50 36390 # create vertices dataset rawData = meshToData(meshes) mean = rawData.mean(axis=0) # center the data data = (rawData - mean) # Get triangles triangles = meshes[0].triangles # Set colour colour = [141, 182, 205] # light blue colour #### TRAINING #### # Full training scheme # param_grid = {'dimension': [50], # 'epochs': [10000], # 'learning_rate': [1e-4], # 'batch_size': [5,10], # 'regularization': [1e-1,1e-2, 1e-3], # 'activation': ['linear']} # Best result param_grid = { 'dimension': [50], 'epochs': [1000], 'learning_rate': [1e-4], 'batch_size': [10], 'regularization': [1e-5], 'activation': ['linear'] } # training_function(data, param_grid,name='femur_linear_') #### VISUALISING #### # Set the directory and the wild cards to select all runs of choice direc = '../results/' paths = glob2.glob(direc + "*femur_linear_linear_AE_w2*") trainingAEViz(rawData, paths, triangles, "femur_linear_AE_", colour, cameraName="femur", eigen_faust_Bool=False, trim_type="femur") print("fin")
def main(): # fetch data meshes = loadMeshes("../meshes/faust/") # create vertices dataset rawData = meshToData(meshes) mean = rawData.mean(axis=0) # center the data data = (rawData - mean) # Get triangles triangles = meshes[0].triangles # Set colour colour = [141, 182, 205] # light blue colour #### TRAINING #### # Full training scheme # param_grid = {'dimension': [20,100], # 'epochs': [100,1000,10000,20000], # 'learning_rate': [1e-6, 1e-4, 1e-2], # 'batch_size': [5, 25], # 'regularization': [0, 1e-2, 1e-4], # 'activation': ['linear']} # Best result param_grid = { 'dimension': [100], 'epochs': [1000], 'learning_rate': [1e-4], 'batch_size': [25], 'regularization': [1e-5], 'activation': ['linear'] } # training_function(data, param_grid,name='faust_linear_') #### VISUALISING #### # Set the directory and the wild cards to select all runs of choice direc = '../results/' # paths = glob2.glob(direc + "*faust_linear_linear_AE_w2_*") paths = glob2.glob(direc + "faust_linear_linear_AE_w2_*") trainingAEViz(rawData, paths, triangles, "faust_linear_AE_", colour, cameraName="faust", eigen_faust_Bool=True, trim_type="faust")
def main(): import os # os.chdir("/media/fabio/Storage/UCT/Thesis/Coding/MSc_Thesis_Obj1/src") # fetch data meshes = loadMeshes("../meshes/faust/") # print(np.array(meshes[0].triangles).shape, np.array(meshes[0].vertices).shape) # create vertices dataset rawData = meshToData(meshes) mean = rawData.mean(axis=0) # sd = np.std(data, axis=0) data = (rawData - mean) # Get triangles triangles = meshes[0].triangles # dimension to reduce to dimension = 100 # Set the colour colour = [180, 180, 180] # Grey # PCA # (components,eigenvalues) = AnalyticalPCA(data, dimension, "sklearn") # print("sklearn eigenvalues", eigenvalues) # print("sklearn components", components) # (components,eigenvalues) = AnalyticalPCA(data, dimension, "eigen") # print("eigen eigenvalues", eigenvalues) # print("eigen components", components) (components, eigenvalues) = AnalyticalPCA(data, dimension, "SVD") print("SVD eigenvalues", eigenvalues) print("SVD components", components) eigenvalues = np.sqrt(eigenvalues * data.shape[1])**2 / data.shape[0] np.savetxt('../results/faust_PCA_Eigen.csv', eigenvalues, delimiter=',') # visualise and save the mean mesh mean3DVis(rawData, triangles, "faust_PCA_", col=colour, cameraName="faust") # Get and save shape parameters b = shapeParameters(data, components) np.savetxt('../results/faust_PCA_ShapeParamaters_b.csv', b, delimiter=',') # Save modes of variation modesOfVariationVis(mean, components, eigenvalues, 3, triangles, "faust_PCA_", col=colour, cameraName="faust") # Plot modes of variation PlotModesVaration(3, "faust_PCA_", trim_type="faust") # Plot a basic scatterGram PlotScatterGram(b, 3, "faust_PCA_") # plot variation explained by PCA variationExplainedPlot(eigenvalues, "faust_PCA_")
cutoff = 0.05 # fetch data os.chdir("/media/fabio/Storage/UCT/Thesis/Coding/MSc_Thesis_Obj1/src") # fetch data faustmeshes = loadMeshes("../meshes/faust/") femurmeshes = loadMeshes("../meshes/femurs/", ply_Bool=False) faustShapeParameters = np.genfromtxt( "../results/faust_PCA_ShapeParamaters_b.csv", delimiter=",") femurShapeParameters = np.genfromtxt( "../results/femur_PCA_ShapeParamaters_b.csv", delimiter=",") # create vertices dataset faustData = meshToData(faustmeshes) femurData = meshToData(femurmeshes) def normalityTestCoordiate(data, cutoff): """ This tests the univariate normality of the x , y , z of a mesh's vertices individually Tests are Shapiro Wilks, Jarque Bera, D Agostino, Lilliefors :param data: :param cutoff: :return: proportion that pass all tests """ shapiroList = [] jarque_beraList = []
def main(): import os os.chdir("/media/fabio/Storage/UCT/Thesis/Coding/MSc_Thesis_Obj1/src") # fetch data meshes = loadMeshes("../meshes/femurs/", ply_Bool=False) # create vertices dataset rawData = meshToData(meshes) mean = rawData.mean(axis=0) # sd = np.std(rawData, axis=0) # Centering data = (rawData - mean) # print(data.shape) # dims 50, 35982 # Faust is roughly 20000 # Get triangles triangles = meshes[0].triangles # dimension to reduce to dimension = 50 # Set the colour colour = [180, 180, 180] # Grey # meshVis(meshes[0], colour) # find the position you like and press "p" This will save the camera position # save as femurCameraSettings.json in src # PCA - The data is too large to do a full PCA, thus we do an SVD - This is built in in the PCA code # PCA # (components,eigenvalues) = AnalyticalPCA(data, dimension, "sklearn") # print("sklearn eigenvalues", eigenvalues) # print("sklearn components", components) # (components,eigenvalues) = AnalyticalPCA(data, dimension, "eigen") # print("eigen eigenvalues", eigenvalues) # print("eigen components", components) (components, eigenvalues) = AnalyticalPCA(data, dimension, "SVD") print("SVD eigenvalues", eigenvalues) print("SVD components", components) eigenvalues = np.sqrt(eigenvalues * data.shape[1])**2 / data.shape[0] np.savetxt('../results/femur_PCA_Eigen.csv', eigenvalues, delimiter=',') # visualise and save the mean mesh mean3DVis(rawData, triangles, "femur_PCA_", col=colour, cameraName="femur") # Get and save shape parameters b = shapeParameters(data, components) np.savetxt('../results/femur_PCA_ShapeParamaters_b.csv', b, delimiter=',') # Save modes of variation modesOfVariationVis(mean, components, eigenvalues, 3, triangles, "femur_PCA_", col=colour, cameraName="femur") # Plot modes of variation PlotModesVaration(3, "femur_PCA_", trim_type="femur") # Plot a basic scatterGram PlotScatterGram(b, 3, "femur_PCA_") # plot variation explained by PCA variationExplainedPlot(eigenvalues, "femur_PCA_") print("fin")