Exemple #1
0
 def accuracy(self, classes):
     c_m = confusion_matrix(self.labels_test, self.prediction)
     acc_test = error_func(self.prediction, self.labels_test)
     for i in range(len(classes)):
         labels_count = np.sum(self.labels_test == i)
         c_m[i, :] = (c_m[i, :] / labels_count) * 100
     return c_m, acc_test
Exemple #2
0
    def spectral_clustering(self, test_pos, labels_bin):
        fiedler_vector_c = self.get_laplacian_eigenmaps(new_dim=1, use_normalized=False).squeeze()
        fiedler_vector_n = self.get_laplacian_eigenmaps(new_dim=1, use_normalized=True).squeeze()

        # We do clustering according to the fiedler vector
        clusters_c = np.zeros([self.n_nodes, ])
        clusters_c[fiedler_vector_c > 0] = 1
        clusters_c[fiedler_vector_c <= 0] = -1

        clusters_n = np.zeros([self.n_nodes, ])
        clusters_n[fiedler_vector_n > 0] = 1
        clusters_n[fiedler_vector_n <= 0] = -1

        clusters_c = clusters_c[test_pos]
        clusters_n = clusters_n[test_pos]

        print('Percentage Error with fiedler vector combinatorial: {:.2f}'.format(error_func(labels_bin, clusters_c)))
        print('Percentage Error with fiedler vector normalized: {:.2f}'.format(error_func(labels_bin, clusters_n)))
Exemple #3
0
 def accuracy(self, classes):
     c_m = confusion_matrix(
         self.labels_test,
         np.argmax(self.prediction.cpu().detach().numpy(), axis=1))
     acc_test = error_func(
         np.argmax(self.prediction.cpu().detach().numpy(), axis=1),
         self.labels_test.numpy())
     for i in range(len(classes)):
         labels_count = np.sum(self.labels_test.numpy() == i)
         c_m[i, :] = (c_m[i, :] / labels_count) * 100
     return c_m, acc_test
Exemple #4
0
 def transductive_learning(self, w, thresholds, n_trials, labels_bin, test_ind, p, **kwargs):
     for _, threshold in enumerate(thresholds):
         # Simulate n_trials times
         for _ in range(n_trials):
             # Subsample randomly
             subsampled = labels_bin * w
             # Solve p-norm interpolation
             sol = self.graph_pnorm_interpolation(sparse.csr_matrix(self.S).T, self.P, w, labels_bin,
                                             x0=subsampled.copy(), p=p, **kwargs)
             # Threshold to -1 and 1
             sol_bin = (sol > threshold).astype(int)
             sol_bin[sol_bin == 0] = -1
             pdb.set_trace()
             print('Percentage Error with threshold: {:.2f}'.format(error_func(labels_bin[test_ind], sol_bin[test_ind])))