def test_sample_array_throws_for_nonpositive_input(self):
     self.assertRaises(ValueError,
                       lambda: SamplingFunctions.sample_array(np.array(list(range(20))), -1))
     self.assertRaises(ValueError,
                       lambda: SamplingFunctions.sample_array(np.array(list(range(20))), 0.0))
     self.assertRaises(ValueError,
                       lambda: SamplingFunctions.sample_array(np.array(list(range(20))), -0.000001))
Ejemplo n.º 2
0
    def get_init_population(self, num_features):
        feature_idxs = np.array(range(num_features))
        population = []
        for k in range(self.init_population_size):
            selected_features_idxs = SamplingFunctions.sample_array(feature_idxs, self.percent_features_first_selected)
            features = np.zeros(num_features, dtype=int)
            features[selected_features_idxs] = 1
            individual = GPIndividual(random.choice(self.clfs), self.scorer, features, self.use_proba)
            population.append(individual)

        return population
    def test_sample_array__handles_probability(self):
        l = np.array(list(range(3, 33, 3)))
        n = 0.3
        l2 = SamplingFunctions.sample_array(l, n)

        self.assertTrue(len(l2), 3)