def test_file_manager(self): file_manager = FileManager() file_manager.load_file("../Datasets/test.data") normalize_data_1 = [[2.0, 2.0, 2.0, 2.0, [0, 1, 0]]] normalize_data_2 = [[1.0, 1.0, 1.0, 1.0, [1, 0, 0]]] self.assertEqual(file_manager.get_train_data(), normalize_data_1) self.assertEqual(file_manager.get_test_data(), normalize_data_2)
def __init__(self, initial_population, generations): """ A genetic algorithm is used to learn the weights and bias of a topology fixed network. """ super().__init__(initial_population) #self.expected_precision = expected_precision self.generation_span = generations self.precision = 0 self.epoch = 0 self.num_inputs = 4 self.neurons_per_layer = [self.num_inputs, 4, 3] # Build Fixed Neural Network, with 4 inputs self.neural_network = NeuralNetwork(self.num_inputs) # The neural network has 3 layers with 3,4 and 3 neurons in each self.neural_network.buildFixed(self.neurons_per_layer) self.test_values = 20 # Parse data set file_manager = FileManager() file_manager.load_file("../Datasets/iris.data") self.train_data = file_manager.get_train_data() self.test_data = file_manager.get_test_data() self.neurons_position = [] self.x_plot = [] self.y_plot = []
def main(): # Parse data set file_manager = FileManager() file_manager.load_file("../Datasets/iris.data") train_data = file_manager.get_train_data() test_data = file_manager.get_test_data() number_of_epochs = 2000 # Training data can be shuffled # shuffle(train_data) """ Genetic Algorithm (Tarea 3) """ # ------------------------------------------------- genetic = GeneticFixedTopology(100, 1000) best_neural_network = genetic.run() genetic.plot_results()
def test_fit(self): file_path = "../Dataset/00-91-Drugs-All-In-One-File.csv" loaded_data = FileManager.load_file(file_path) data_manager = DataManager(normalizer=None) data_manager.set_data(loaded_data) data_manager.split_data_into_train_valid_test_sets(test_split=0.15, train_split=0.70) model = svm.SVR() velocity = Velocity() velocity_matrix = velocity.create_first_velocity() # define the first population # validation of a row generating random row for population = Population(velocity_matrix=velocity_matrix) population.create_first_population() debpso = DEBPSO(population.population_matrix[1]) debpso.fit(data_manager.inputs[SplitTypes.Train], data_manager.targets[SplitTypes.Train]) print("Population 1 row sum ", population.population_matrix[1].sum()) print("Selected feature descriptors", debpso.sel_descriptors_for_curr_population)
def read_data_and_set_variable_settings(self, data_file_path, variable_file_path): loaded_data = FileManager.load_file(data_file_path) no_of_drugs = loaded_data.shape[0] no_of_descriptors = loaded_data.shape[1] - 1 # excluding the last column that is the y axis variables = FileManager.load_variable_file(variable_file_path) VariableSetting.set_variables(variables, no_of_drugs, no_of_descriptors) return loaded_data
def read_data_and_set_variable_settings(self, data_file_path, variable_file_path): loaded_data = FileManager.load_file(data_file_path) no_of_drugs = loaded_data.shape[0] no_of_descriptors = loaded_data.shape[ 1] - 1 # excluding the last column that is the y axis variables = FileManager.load_variable_file(variable_file_path) VariableSetting.set_variables(variables, no_of_drugs, no_of_descriptors) return loaded_data
def test_fit(self): file_path = "../Dataset/00-91-Drugs-All-In-One-File.csv" loaded_data = FileManager.load_file(file_path) data_manager = DataManager(normalizer=None) data_manager.set_data(loaded_data) data_manager.split_data_into_train_valid_test_sets(test_split=0.15, train_split=0.70) model = svm.SVR() velocity = Velocity() velocity_matrix = velocity.create_first_velocity() # define the first population # validation of a row generating random row for population = Population(velocity_matrix=velocity_matrix) population.create_first_population() debpso = DEBPSO(population.population_matrix[1]) debpso.fit(data_manager.inputs[SplitTypes.Train], data_manager.targets[SplitTypes.Train]) print("Population 1 row sum ", population.population_matrix[1].sum()) print("Selected feature descriptors",debpso.sel_descriptors_for_curr_population)
from src.FileManager import FileManager from src.DataManager import DataManager from src.Population import Population from src.Normalizer import * no_of_populations = 50 # should be 50 population no_of_descriptors = 385 # should be 385 descriptors unfit = 1000 required_r2 = {} required_r2[SplitTypes.Train] = .6 required_r2[SplitTypes.Valid] = .5 required_r2[SplitTypes.Test] = .5 file_path = "../Dataset/00-91-Drugs-All-In-One-File.csv" loaded_data = FileManager.load_file(file_path) output_filename = FileManager.create_output_file() #rescaling_normalizer = RescalingNormalizer() #scikit_normalizer = ScikitNormalizer() #data_manager = DataManager(normalizer=scikit_normalizer) data_manager = DataManager(normalizer=None) data_manager.set_data(loaded_data) data_manager.split_data(test_split=0.15, train_split=0.70) model = svm.SVR() population = Population() population.load_data()
import numpy as np import Bio print(Bio.__version__) exit(0) from src.FileManager import FileManager __author__ = 'FalguniT' #Ehux JGI Fasta file Ehux_JGI_file_path = "../data/Ehux_JGI.fasta" Ehux_JGI_data = FileManager.load_file(Ehux_JGI_file_path) #Geph Blast output file Geph_file_path = "../data/Ehux_Geph_Blast_060916.txt.p1" Geph_data = FileManager.load_file(Geph_file_path) Geph_count = len(Geph_data) print("geph count", Geph_count) #ISO blast output file ISO_file_path = "../data/Ehux_ISO_Blast_060916.txt.p1" ISO_data = FileManager.load_file(ISO_file_path) ISO_count = len(ISO_data) print("ISO_ count", ISO_count) #Strains 92A blast strains_92A_file_path = "../data/Ehux_strains_92A_Blast_060816.txt.p1" strains_92A_data = FileManager.load_file(strains_92A_file_path) strains_92A_count = len(strains_92A_data)