def test_varSelection(self): linearSelection = model_order_reduction.variables_selection(self.X) linearSelection.eigens = self.nPCtest linearSelection.retained = self.nVarTest linearSelection.method = self.selMethod1 labels1, ____ = linearSelection.fit() linearSelection.method = self.selMethod2 labels2, ____ = linearSelection.fit() linearSelection.method = self.selMethod3 labels3, ____ = linearSelection.fit() self.assertEqual(len(labels1), self.nVarTest) self.assertEqual(len(labels2), self.nVarTest) self.assertEqual(len(labels3), self.nVarTest)
#set the initialization method "initialization_method": "uniform", #enable additional options: "write_stats": False, "evaluate_clustering": True, } X = readCSV(file_options["path_to_file"], file_options["input_file_name"]) print("matrix dimensions: {}".format(X.shape)) if settings["select_variables"]: PVs = model_order_reduction.variables_selection(X, settings) labels, numbers = PVs.fit() redX = X[:, numbers] print("The new data dimensions are: {}".format(X.shape)) model = clustering.lpca(redX, settings) index = model.fit() if settings["evaluate_clustering"]: #evaluate the clustering solution PHC_coeff, PHC_deviations = evaluate_clustering_PHC(X, index,
newDirName = "trainingMGPCAforPV2ndtry_time" + now.strftime( "%Y_%m_%d-%H%M") os.mkdir(newDirName) os.chdir(newDirName) # Write a txt to recap the prescribed settings text_file = open("Recap_training.txt", "wt") method_used = text_file.write("The PV method is: " + str(settings["method"]) + ". \n") minVar = text_file.write( "The number of considered variables for the model reduction is: {} \n". format(settings["number_of_variables"])) text_file.close() # Retrieve the PVs name, and the corresponding numbers in the original matrix X PV = model_order_reduction.variables_selection(X_preprocessed, settings) PVs, numbers = PV.fit() # Save the selected variables in a .txt, they can be useful later on np.savetxt("Selected_variables.txt", numbers) # Cut the dimensionality of the original matrix, considering only # the selected 'm' variables X_preprocessed_cut = X_preprocessed[:, numbers] #perform the dimensionality reduction via Principal Component Analysis, # and return the eigenvectors of the reduced manifold (PCs). model = model_order_reduction.PCA(X_preprocessed, settings) PCs, ____ = model.fit() #compute the projection of the original points on the reduced