コード例 #1
0
a_ind.discard(4)
# add a batch of indexes.
a_ind.update([4, 5])
# discard a batch of indexes.
a_ind.difference_update([1, 2])
print(a_ind)

# ---------MultiLabelIndexCollection-------------
from alipy.index import MultiLabelIndexCollection
multi_lab_ind1 = MultiLabelIndexCollection([(0, 1), (0, 2), (0, (3, 4)),
                                            (1, (0, 1))],
                                           label_size=5)
multi_lab_ind1.update((0, 0))
multi_lab_ind1.update([(1, 2), (1, (3, 4))])
multi_lab_ind1.update([(2, )])
multi_lab_ind1.difference_update([(0, )])
print(multi_lab_ind1)

# matlab style 1d index supporting
b = [1, 4, 11]
mi = MultiLabelIndexCollection.construct_by_1d_array(array=b,
                                                     label_mat_shape=(3, 4))
print(mi)
print('col major:', mi.get_onedim_index(order='F', ins_num=3))
print('row major:', mi.get_onedim_index(order='C'))

# mask supporting
mask = np.asarray([[0, 1], [1, 0], [1, 0]])  # 3 rows, 2 lines
mi = MultiLabelIndexCollection.construct_by_element_mask(mask=mask)
print(mi)
mi = MultiLabelIndexCollection([(0, 1), (2, 0), (1, 0)], label_size=2)
コード例 #2
0
ファイル: feature_querying.py プロジェクト: yyht/ALiPy
for i in range(5):
    train_idx = tr[i]
    test_idx = te[i]
    label_ind = MultiLabelIndexCollection(lab[i], label_size=X.shape[1])
    unlab_ind = MultiLabelIndexCollection(unlab[i], label_size=X.shape[1])
    saver = StateIO(i, train_idx, test_idx, label_ind, unlab_ind)
    strategy = QueryFeatureAFASMC(X=X, y=y, train_idx=train_idx)

    while not stopping_criterion.is_stop():
        # query
        selected_feature = strategy.select(observed_entries=label_ind,
                                           unkonwn_entries=unlab_ind)

        # update index
        label_ind.update(selected_feature)
        unlab_ind.difference_update(selected_feature)

        # train/test
        lab_in_train = map_whole_index_to_train(train_idx, label_ind)
        X_mc = AFASMC_mc(X=X[train_idx], y=y[train_idx], omega=lab_in_train)
        model.fit(X_mc, y[train_idx])
        pred = model.predict(X[test_idx])
        perf = accuracy_score(y_true=y[test_idx], y_pred=pred)

        # save
        st = State(select_index=selected_feature, performance=perf)
        saver.add_state(st)
        # saver.save()

        stopping_criterion.update_information(saver)