def test_benchmark_slm(self): print('Test BenchmarkSLM()...') algorithm = BenchmarkSLM(10, MaxGenerationsCriterion(10), 3, 0.01, 50, Mutation2()) X = get_input_variables(self.training).as_matrix() y = get_target_variable(self.training).as_matrix() log = algorithm.fit(X, y, RootMeanSquaredError, verbose=True) self.assertTrue(expr=log) print()
def test_ols(self): print('OLS tests of fit()...') algorithm = SemanticLearningMachine(100, MaxGenerationsCriterion(200), 3, 'optimized', 50, Mutation2()) X = get_input_variables(self.training).as_matrix() y = get_target_variable(self.training).as_matrix() algorithm.fit(X, y, RootMeanSquaredError, verbose=True) self.assertTrue(expr=algorithm.champion) print()
def test_edv(self): print('EDV tests of fit()...') algorithm = SemanticLearningMachine( 100, ErrorDeviationVariationCriterion(0.25), 3, 0.01, 50, Mutation2()) X = get_input_variables(self.training).as_matrix() y = get_target_variable(self.training).as_matrix() algorithm.fit(X, y, RootMeanSquaredError, verbose=True) self.assertTrue(expr=algorithm.champion) print()
def test_slm_ols_wo_edv(self): print("testing fit for SLM (OLS) without EDV ()...") base_learner = SemanticLearningMachine(50, MaxGenerationsCriterion(20), 2, 'optimized', 10, Mutation2()) ensemble_learner = EnsembleBagging(base_learner, 100) X = get_input_variables(self.training).values y = get_target_variable(self.training).values def time_seconds(): return default_timer() start_time = time_seconds() ensemble_learner.fit(X, y, RootMeanSquaredError, verbose=False) print("time to train algorithm: ", (time_seconds() - start_time)) self.assertTrue(expr=ensemble_learner.learners) print()
def test_predict(self): print("testing predict()...") base_learner = SemanticLearningMachine( 50, ErrorDeviationVariationCriterion(0.25), 2, 1, 10, Mutation2()) ensemble_learner = EnsembleBagging(base_learner, 100) X = get_input_variables(self.training).values y = get_target_variable(self.training).values def time_seconds(): return default_timer() start_time = time_seconds() ensemble_learner.fit(X, y, RootMeanSquaredError, verbose=False) print("time to train algorithm: ", (time_seconds() - start_time)) start_time = time_seconds() prediction = ensemble_learner.predict( get_input_variables(self.validation).values) print("time to predict algorithm: ", (time_seconds() - start_time)) self.assertTrue(expr=len(prediction) == len( get_target_variable(self.validation).values)) print()
def test_tie(self): print('TIE tests of fit()...') def time_seconds(): return default_timer() start_time = time_seconds() algorithm = SemanticLearningMachine(100, TrainingImprovementEffectivenessCriterion(0.25), 3, 0.01, 50, Mutation2(), RootMeanSquaredError, True) X = get_input_variables(self.training).values y = get_target_variable(self.training).values start_time = time_seconds() algorithm.fit(X, y, RootMeanSquaredError, verbose=False) print("time to train algorithm: ", (time_seconds()-start_time)) self.assertTrue(expr=algorithm.champion) print()
def test_ols(self): print('OLS tests of fit()...') def time_seconds(): return default_timer() start_time = time_seconds() algorithm = SemanticLearningMachine(100, MaxGenerationsCriterion(200), 3, 'optimized', 50, Mutation2(), RootMeanSquaredError, True) X = get_input_variables(self.training).values y = get_target_variable(self.training).values start_time = time_seconds() algorithm.fit(X, y, RootMeanSquaredError, verbose=False) print("time to train algorithm: ", (time_seconds()-start_time)) self.assertTrue(expr=algorithm.champion) print()
def test_slm_fls(self): print("testing fit() for SLM (FLS) ...") base_learner = SemanticLearningMachine(50, MaxGenerationsCriterion(100), 2, 1, 10, Mutation2()) ensemble_learner = EnsembleRandomIndependentWeighting(base_learner, 100, weight_range=1) X = get_input_variables(self.training).values y = get_target_variable(self.training).values def time_seconds(): return default_timer() start_time = time_seconds() ensemble_learner.fit(X, y, RootMeanSquaredError, verbose=False) print("time to train algorithm: ", (time_seconds()-start_time)) self.assertTrue(expr=ensemble_learner.learners) print()
from algorithms.simple_genetic_algorithm.mutation_operator import MutationOperatorGaussian from algorithms.simple_genetic_algorithm.crossover_operator import CrossoverOperatorArithmetic from algorithms.semantic_learning_machine.algorithm import SemanticLearningMachine from itertools import product from numpy import mean _BASE_PARAMETERS = {'number_generations': 200, 'population_size': 100} _SLM_FLS_PARAMETERS = { 'stopping_criterion': [MaxGenerationsCriterion(_BASE_PARAMETERS.get('number_generations'))], 'population_size': [_BASE_PARAMETERS.get('population_size')], 'layers': [1, 2, 3], 'learning_step': [0.01], 'max_connections': [1, 10, 50], 'mutation_operator': [Mutation2()] } _SLM_OLS_PARAMETERS = { 'stopping_criterion': [ ErrorDeviationVariationCriterion(0.25), ErrorDeviationVariationCriterion(0.5) ], 'population_size': [_BASE_PARAMETERS.get('population_size')], 'layers': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'learning_step': ['optimized'], 'max_connections': [1, 10, 50, 100], 'mutation_operator': [Mutation2()] } _NEAT_PARAMETERS = {
def setUp(self): base_learner = SemanticLearningMachine(50, MaxGenerationsCriterion(10), 2, 'optimized', 10, Mutation2()) self.ensemble_learner = Ensemble(base_learner, 50) self.training, self.validation, self.testing = load_samples('c_diabetes', 0)