def test_digits_lazy(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer='lazy') model.fit(X_digits_cupy) assert_array_equal(model.ranking, digits_ranking) assert_array_almost_equal(model.gains, digits_gains, 4)
def test_digits_approximate_object(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer=ApproximateLazyGreedy()) model.fit(X_digits_cupy) assert_array_equal(model.ranking, digits_approx_ranking) assert_array_almost_equal(model.gains, digits_approx_gains, 4)
def test_digits_modular_object(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer=ModularGreedy(random_state=0)) model.fit(X_digits_cupy) assert_array_equal(model.ranking, digits_modular_ranking) assert_array_almost_equal(model.gains, digits_modular_gains, 4)
def test_digits_two_stage_sparse(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer='two-stage') model.fit(X_digits_sparse) assert_array_equal(model.ranking, digits_ranking) assert_array_almost_equal(model.gains, digits_gains, 4)
def test_digits_sqrt_sieve_batch(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], random_state=0) model.partial_fit(X_digits) assert_array_equal(model.ranking, digits_sieve_ranking) assert_array_almost_equal(model.gains, digits_sieve_gains, 4) assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_naive(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer='naive') model.fit(X_digits_cupy) assert_array_equal(model.ranking[:30], digits_ranking[:30]) assert_array_equal(model.ranking[-30:], digits_ranking[-30:]) assert_array_almost_equal(model.gains, digits_gains, 4)
def test_digits_two_stage_init(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer='two-stage', initial_subset=digits_ranking[:5]) model.fit(X_digits_cupy) assert_array_equal(model.ranking[:-5], digits_ranking[5:]) assert_array_almost_equal(model.gains[:-5], digits_gains[5:], 4)
def test_digits_modular_sparse(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer='modular', random_state=0) model.fit(X_digits_sparse) assert_array_equal(model.ranking, digits_modular_ranking) assert_array_almost_equal(model.gains, digits_modular_gains, 4)
def test_digits_stochastic(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer='stochastic', random_state=0) model.fit(X_digits_cupy) assert_array_equal(model.ranking, digits_stochastic_ranking) assert_array_almost_equal(model.gains, digits_stochastic_gains, 4)
def test_digits_sample_object(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer=SampleGreedy(random_state=0)) model.fit(X_digits) assert_array_equal(model.ranking, digits_sample_ranking) assert_array_almost_equal(model.gains, digits_sample_gains, 4) assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_greedi_nl_object(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer=GreeDi(optimizer1='naive', optimizer2='lazy', random_state=0)) model.fit(X_digits_cupy) assert_array_equal(model.ranking[:85], digits_greedi_ranking[:85]) assert_array_almost_equal(model.gains[:85], digits_greedi_gains[:85], 4)
def test_digits_naive_init(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer='naive', initial_subset=digits_ranking[:5]) model.fit(X_digits) assert_array_equal(model.ranking[:20], digits_ranking[5:25]) assert_array_almost_equal(model.gains[:20], digits_gains[5:25], 4) assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_naive_sparse(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer='naive') model.fit(X_digits_sparse) assert_array_equal(model.ranking, digits_ranking) assert_array_almost_equal(model.gains, digits_gains, 4) assert_array_almost_equal(model.subset, X_digits_sparse[model.ranking].toarray())
def test_digits_approximate(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer='approximate-lazy', random_state=0) model.fit(X_digits) assert_array_equal(model.ranking, digits_approx_ranking) assert_array_almost_equal(model.gains, digits_approx_gains, 4) assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_greedi_ln(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer='two-stage', optimizer_kwds={ 'optimizer1': 'lazy', 'optimizer2': 'naive' }, random_state=0) model.fit(X_digits_cupy) assert_array_equal(model.ranking, digits_greedi_ranking) assert_array_almost_equal(model.gains, digits_greedi_gains, 4)
def test_digits_greedi_nl_sparse(): model1 = FeatureBasedSelection(100, 'sqrt') model2 = FeatureBasedSelection(100, 'log') model = MixtureSelection(100, [model1, model2], [1.0, 0.3], optimizer='greedi', optimizer_kwds={ 'optimizer1': 'naive', 'optimizer2': 'lazy' }, random_state=0) model.fit(X_digits_sparse) assert_array_equal(model.ranking[:85], digits_greedi_ranking[:85]) assert_array_almost_equal(model.gains[:85], digits_greedi_gains[:85], 4)
def test_digits_sqrt_approximate_object(): model = FeatureBasedSelection(100, 'sqrt', optimizer=ApproximateLazyGreedy()) model.fit(X_digits) assert_array_equal(model.ranking, digits_sqrt_approx_ranking) assert_array_almost_equal(model.gains, digits_sqrt_approx_gains, 4) assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_sqrt_modular_sparse(): model = FeatureBasedSelection(100, 'sqrt', optimizer='modular', random_state=0) model.fit(X_digits_sparse) assert_array_equal(model.ranking, digits_sqrt_modular_ranking) assert_array_almost_equal(model.gains, digits_sqrt_modular_gains, 4) assert_array_almost_equal(model.subset, X_digits_sparse[model.ranking].toarray())
def test_digits_sqrt_greedi_ln(): model = FeatureBasedSelection(100, 'sqrt', optimizer='greedi', optimizer_kwds={'optimizer1': 'lazy', 'optimizer2': 'naive'}, random_state=0) model.fit(X_digits_cupy) assert_array_equal(model.ranking, digits_sqrt_greedi_ranking) assert_array_almost_equal(model.gains, digits_sqrt_greedi_gains, 4)
def test_digits_sqrt_two_stage_init(): model = FeatureBasedSelection(100, 'sqrt', optimizer='two-stage', initial_subset=digits_sqrt_ranking[:5]) model.fit(X_digits) assert_array_equal(model.ranking[:-5], digits_sqrt_ranking[5:]) assert_array_almost_equal(model.gains[:-5], digits_sqrt_gains[5:], 4) assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_sigmoid_lazy_init(): model = FeatureBasedSelection(100, 'sigmoid', optimizer='lazy', initial_subset=digits_sigmoid_ranking[:5]) model.fit(X_digits) assert_array_equal(model.ranking[:-5], digits_sigmoid_ranking[5:]) assert_array_almost_equal(model.gains[:-5], digits_sigmoid_gains[5:], 4) assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_sqrt_sample(): model = FeatureBasedSelection(100, 'sqrt', optimizer='sample', random_state=0) model.fit(X_digits) assert_array_equal(model.ranking, digits_sqrt_sample_ranking) assert_array_almost_equal(model.gains, digits_sqrt_sample_gains, 4) assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_sqrt_greedi_nl_sparse(): model = FeatureBasedSelection(100, 'sqrt', optimizer='greedi', optimizer_kwds={'optimizer1': 'naive', 'optimizer2': 'lazy'}, random_state=0) model.fit(X_digits_sparse) assert_array_equal(model.ranking[:30], digits_sqrt_greedi_ranking[:30]) assert_array_almost_equal(model.gains[:30], digits_sqrt_greedi_gains[:30], 4)
def test_digits_sqrt_greedi_nl_object(): model = FeatureBasedSelection(100, 'sqrt', optimizer=GreeDi( optimizer1='naive', optimizer2='lazy', random_state=0)) model.fit(X_digits) assert_array_equal(model.ranking[:30], digits_sqrt_greedi_ranking[:30]) assert_array_almost_equal(model.gains[:30], digits_sqrt_greedi_gains[:30], 4) assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_sqrt_modular_object(): model = FeatureBasedSelection(100, 'sqrt', optimizer=ModularGreedy(random_state=0)) model.fit(X_digits) assert_array_equal(model.ranking, digits_sqrt_modular_ranking) assert_array_almost_equal(model.gains, digits_sqrt_modular_gains, 4) assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_log_naive_init(): model = FeatureBasedSelection(100, 'log', optimizer='naive', initial_subset=digits_log_ranking[:5]) model.fit(X_digits) assert_array_equal(model.ranking[:20], digits_log_ranking[5:25]) assert_array_almost_equal(model.gains[:20], digits_log_gains[5:25], 4) assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_sqrt_small_pq_bool_initialized(): mask = numpy.zeros(X_digits.shape[0], dtype=bool) mask[digits_sqrt_ranking[:5]] = True model = FeatureBasedSelection(10, 'sqrt', 1, initial_subset=mask) model.fit(X_digits) assert_array_equal(model.ranking, digits_sqrt_ranking[5:15]) assert_array_almost_equal(model.gains, digits_sqrt_gains[5:15], 4)
def test_digits_log_naive(): model = FeatureBasedSelection(100, 'log', optimizer='naive') model.fit(X_digits) assert_array_equal(model.ranking[:30], digits_log_ranking[:30]) assert_array_equal(model.ranking[-30:], digits_log_ranking[-30:]) assert_array_almost_equal(model.gains, digits_log_gains, 4) assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_sqrt_sieve_minibatch_sparse(): model = FeatureBasedSelection(100, 'sqrt', random_state=0) model.partial_fit(X_digits_sparse[:300]) model.partial_fit(X_digits_sparse[300:500]) model.partial_fit(X_digits_sparse[500:]) assert_array_equal(model.ranking, digits_sqrt_sieve_ranking) assert_array_almost_equal(model.gains, digits_sqrt_sieve_gains, 4) assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_sqrt_greedi_nn_sparse(): model = FeatureBasedSelection(100, 'sqrt', optimizer='greedi', optimizer_kwds={'optimizer1': 'naive', 'optimizer2': 'naive'}, random_state=0) model.fit(X_digits_sparse) assert_array_equal(model.ranking, digits_sqrt_greedi_ranking) assert_array_almost_equal(model.gains, digits_sqrt_greedi_gains, 4) assert_array_almost_equal(model.subset, X_digits_sparse[model.ranking].toarray())