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])
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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_precomputed_two_stage():
	model1 = FacilityLocationSelection(100)
	model2 = GraphCutSelection(100)
	model = MixtureSelection(100, [model1, model2], [1.0, 0.3],
		metric='precomputed', optimizer='two-stage')
	model.fit(X_digits_cosine_cupy)
	assert_array_equal(model.ranking, digits_cosine_ranking)
	assert_array_almost_equal(model.gains, digits_cosine_gains, 4)
def test_digits_cosine_modular_sparse():
	model1 = FacilityLocationSelection(100)
	model2 = GraphCutSelection(100)
	model = MixtureSelection(100, [model1, model2], [1.0, 0.3],
		metric='precomputed', optimizer='modular', random_state=0)
	model.fit(X_digits_cosine_sparse)
	assert_array_equal(model.ranking, digits_cosine_modular_ranking)
	assert_array_almost_equal(model.gains, digits_cosine_modular_gains, 4)
예제 #8
0
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)
예제 #9
0
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)
예제 #10
0
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_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_sqrt_modular_object():
	model1 = FacilityLocationSelection(100)
	model2 = GraphCutSelection(100)
	model = MixtureSelection(100, [model1, model2], [1.0, 0.3],
		metric='cosine', optimizer=ModularGreedy(random_state=0))
	model.fit(X_digits)
	assert_array_equal(model.ranking, digits_cosine_modular_ranking)
	assert_array_almost_equal(model.gains, digits_cosine_modular_gains, 4)
	assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_precomputed_two_stage_init():
	model1 = FacilityLocationSelection(100)
	model2 = GraphCutSelection(100)
	model = MixtureSelection(100, [model1, model2], [1.0, 0.3],
		metric='precomputed', optimizer='two-stage', 
		initial_subset=digits_cosine_ranking[:5])
	model.fit(X_digits_cosine_cupy)
	assert_array_equal(model.ranking[:-5], digits_cosine_ranking[5:])
	assert_array_almost_equal(model.gains[:-5], digits_cosine_gains[5:], 4)
def test_digits_euclidean_lazy():
	model1 = FacilityLocationSelection(100)
	model2 = GraphCutSelection(100)
	model = MixtureSelection(100, [model1, model2], [1.0, 0.3],
		metric='euclidean', optimizer='lazy')
	model.fit(X_digits)
	assert_array_equal(model.ranking, digits_euclidean_ranking)
	assert_array_almost_equal(model.gains, digits_euclidean_gains, 4)
	assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_corr_two_stage():
	model1 = FacilityLocationSelection(100)
	model2 = GraphCutSelection(100)
	model = MixtureSelection(100, [model1, model2], [1.0, 0.3],
		metric='corr', optimizer='two-stage')
	model.fit(X_digits)
	assert_array_equal(model.ranking, digits_corr_ranking)
	assert_array_almost_equal(model.gains, digits_corr_gains, 4)
	assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_cosine_greedi_ll_sparse():
	model1 = FacilityLocationSelection(100)
	model2 = GraphCutSelection(100)
	model = MixtureSelection(100, [model1, model2], [1.0, 0.3],
		metric='precomputed', optimizer='greedi', optimizer_kwds={
		'optimizer1': 'lazy', 'optimizer2': 'lazy'}, random_state=0)
	model.fit(X_digits_cosine_sparse)
	assert_array_equal(model.ranking[:30], digits_cosine_greedi_ranking[:30])
	assert_array_almost_equal(model.gains[:30], digits_cosine_greedi_gains[:30], 4)
def test_digits_cosine_sample():
	model1 = FacilityLocationSelection(100)
	model2 = GraphCutSelection(100)
	model = MixtureSelection(100, [model1, model2], [1.0, 0.3],
		metric='cosine', optimizer='sample', random_state=0)
	model.fit(X_digits)
	assert_array_equal(model.ranking, digits_cosine_sample_ranking)
	assert_array_almost_equal(model.gains, digits_cosine_sample_gains, 4)
	assert_array_almost_equal(model.subset, X_digits[model.ranking])
예제 #18
0
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_cosine_lazy_init():
	model1 = FacilityLocationSelection(100)
	model2 = GraphCutSelection(100)
	model = MixtureSelection(100, [model1, model2], [1.0, 0.3],
		metric='cosine', optimizer='lazy', 
		initial_subset=digits_cosine_ranking[:5])
	model.fit(X_digits)
	assert_array_equal(model.ranking[:-5], digits_cosine_ranking[5:])
	assert_array_almost_equal(model.gains[:-5], digits_cosine_gains[5:], 4)
	assert_array_almost_equal(model.subset, X_digits[model.ranking])
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_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())
예제 #22
0
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_euclidean_two_stage_init():
	model1 = FacilityLocationSelection(100)
	model2 = GraphCutSelection(100)
	model = MixtureSelection(100, [model1, model2], [1.0, 0.3],
		metric='euclidean', optimizer='two-stage', 
		initial_subset=digits_euclidean_ranking[:5])
	model.fit(X_digits)
	assert_array_equal(model.ranking[:-5], digits_euclidean_ranking[5:])
	assert_array_almost_equal(model.gains[:-5], digits_euclidean_gains[5:], 4)
	assert_array_almost_equal(model.subset, X_digits[model.ranking])
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_cosine_greedi_nl_object():
	model1 = FacilityLocationSelection(100)
	model2 = GraphCutSelection(100)
	model = MixtureSelection(100, [model1, model2], [1.0, 0.3],
		metric='cosine', optimizer=GreeDi(optimizer1='naive', 
			optimizer2='lazy', random_state=0))
	model.fit(X_digits)
	assert_array_equal(model.ranking[:30], digits_cosine_greedi_ranking[:30])
	assert_array_almost_equal(model.gains[:30], digits_cosine_greedi_gains[:30], 4)
	assert_array_almost_equal(model.subset, X_digits[model.ranking])
def test_digits_cosine_greedi_ln():
	model1 = FacilityLocationSelection(100)
	model2 = GraphCutSelection(100)
	model = MixtureSelection(100, [model1, model2], [1.0, 0.3],
		metric='cosine', optimizer='greedi', 
		optimizer_kwds={'optimizer1': 'lazy', 'optimizer2': 'naive'}, 
		random_state=0)
	model.fit(X_digits)
	assert_array_equal(model.ranking, digits_cosine_greedi_ranking)
	assert_array_almost_equal(model.gains, digits_cosine_greedi_gains, 4)
	assert_array_almost_equal(model.subset, X_digits[model.ranking])
예제 #27
0
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)
예제 #28
0
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)