def __init__(self, *args, **kwargs): """ Constructor. """ super(NNVisualiseTestCase, self).__init__(*args, **kwargs) self.cnns = generate_cnn_architectures() self.mlps_reg = generate_mlp_architectures('reg') self.mlps_class = generate_mlp_architectures('class') self.save_dir = '../scratch/unittest_visualisations/' self.save_dir_for_pres = '../scratch/unittest_visualisations_for_pres/'
def test_mlp_distance_computation(self): """ Tests the computation of the distance for CNNs. """ self.report('Testing distance computation for specific mlps.') # Create the transport computation object mlp_layer_labels, label_mismatch_penalty = \ nn_comparators.get_mlp_layer_label_mismatch_penalties(self.non_assignment_penalty, 'reg') mlp_tp_comp = nn_comparators.OTMANNDistanceComputer( mlp_layer_labels, label_mismatch_penalty, self.non_assignment_penalty, nn_comparators.MLP_STRUCTURAL_PENALTY_GROUPS, nn_comparators.PATH_LENGTH_TYPES, dflt_mislabel_coeffs=1.0, dflt_struct_coeffs=1.0) # Create the mlp architectures mlps = generate_mlp_architectures() struct_coeffs = [0.1, 0.2] dist_types = ['lp-emd', 'lp', 'emd'] mislabel_coeffs = [1.0] * len(struct_coeffs) self.report( 'Testing distance computation for specific mlps with default coeffs.' ) self._test_dist_comp_for_single_conn_coeff(mlps, dist_types, mlp_tp_comp) self.report( 'Testing distance computation for specific mlps with conn_coeffs=%s.' % (struct_coeffs)) self._test_dist_comp_for_multiple_coeffs(mlps, dist_types, mislabel_coeffs, struct_coeffs, mlp_tp_comp)
def test_call_with_list(self): """ Tests the __call__ function with a single input of the modifier. """ self.report('Testing the __call__ function with a list of inputs.') num_modifications = 40 num_steps_probs = [0.5, 0.25, 0.125, 0.075, 0.05] save_dir = os.path.join(self.save_dir, 'modifier_call_list') if os.path.exists(save_dir): rmtree(save_dir) test_probs = [ self.cnns, self.mlps, generate_mlp_architectures('class') ] for idx, prob in enumerate(test_probs): save_prefix = str(idx) modifier = self.modifier_wo_cc modifications = modifier(prob, num_modifications, num_steps_probs) for new_idx, new_nn in enumerate(modifications): assert isinstance(new_nn, NeuralNetwork) visualise_nn( new_nn, os.path.join(save_dir, '%s_%d' % (save_prefix, new_idx))) self.report( 'With list of %d nns(%s):: #new-networks: %d.' % (len(prob), prob[0].nn_class, len(modifications)), 'test_result')
def __init__(self, *args, **kwargs): """ Constructor. """ super(NNConstraintCheckerTestCase, self).__init__(*args, **kwargs) self.nns = generate_cnn_architectures() + generate_mlp_architectures() self.cnn_constraint_checker = nn_constraint_checkers.CNNConstraintChecker( 25, 5, 500000, 0, 5, 2, 15, 512, 16, 4) self.mlp_constraint_checker = nn_constraint_checkers.MLPConstraintChecker( 25, 5, 500000, 900, 5, 2, 15, 30, 8)
def __init__(self, *args, **kwargs): """ Constructor. """ super(NNModifierTestCase, self).__init__(*args, **kwargs) self.cnns = generate_cnn_architectures() self.mlps = generate_mlp_architectures() self.save_dir = '../scratch/unittest_modifier_class/' self.cnn_constraint_checker = nn_constraint_checkers.CNNConstraintChecker( 50, 4, np.inf, 4.0, 5, 5, 100, 8000, 8) self.mlp_constraint_checker = nn_constraint_checkers.MLPConstraintChecker( 50, 4, np.inf, 4.0, 5, 5, 100, 8000, 8) self.cnn_modifier = nn_modifiers.NNModifier( self.cnn_constraint_checker) self.mlp_modifier = nn_modifiers.NNModifier( self.mlp_constraint_checker) self.modifier_wo_cc = nn_modifiers.NNModifier(None)
def __init__(self, *args, **kwargs): """ Constructor. """ super(DistSumNNKernelTestCase, self).__init__(*args, **kwargs) self.non_assignment_penalty = 1 mlp_layer_labels, label_mismatch_penalty = \ nn_comparators.get_mlp_layer_label_mismatch_penalties(self.non_assignment_penalty, 'reg') self.all_layer_labels = mlp_layer_labels self.label_mismatch_penalty = label_mismatch_penalty self.tp_comp = nn_comparators.OTMANNDistanceComputer( mlp_layer_labels, label_mismatch_penalty, self.non_assignment_penalty, nn_comparators.MLP_STRUCTURAL_PENALTY_GROUPS, nn_comparators.PATH_LENGTH_TYPES) self.mislabel_coeffs = [2.0, 2.0, 1.0, 1.0, 1.0] self.struct_coeffs = [0.25, 0.5, 1.0, 2.0, 4.0] self.lp_betas = [1e-6] * len(self.struct_coeffs) self.emd_betas = [1] * len(self.struct_coeffs) self.mlps = generate_mlp_architectures()