示例#1
0
 def _label(self, x):
     """Label the data by comparison with the reference points."""
     square_distances = (x * x).sum(1)[:, numx.newaxis] + (self.samples * self.samples).sum(1)
     square_distances -= 2 * numx.dot(x, self.samples.T)
     min_inds = square_distances.argsort()
     win_inds = [numx.bincount(self.sample_label_indices[indices[0 : self.k]]).argmax(0) for indices in min_inds]
     labels = [self.ordered_labels[i] for i in win_inds]
     return labels
示例#2
0
 def _label(self, x):
     """Label the data by comparison with the reference points."""
     square_distances = (x*x).sum(1)[:, numx.newaxis] \
                   + (self.samples*self.samples).sum(1)
     square_distances -= 2 * numx.dot(x, self.samples.T)
     min_inds = square_distances.argsort()
     win_inds = [
         numx.bincount(
             self.sample_label_indices[indices[0:self.k]]).argmax(0)
         for indices in min_inds
     ]
     labels = [self.ordered_labels[i] for i in win_inds]
     return labels
示例#3
0
 def _inverse(self, x):
     """Take the mean of overlapping values."""
     n_y_cons = numx.bincount(self.connections)  # n. connections to y_i
     y_cons = numx.argsort(self.connections)  # x indices for y_i
     y = numx.zeros((len(x), self.input_dim))
     i_x_counter = 0  # counter for processed x indices
     i_y = 0  # current y index
     while True:
         n_cons = n_y_cons[i_y]
         if n_cons > 0:
             y[:, i_y] = old_div(
                 numx.sum(x[:, y_cons[i_x_counter:i_x_counter + n_cons]],
                          axis=1), n_cons)
             i_x_counter += n_cons
             if i_x_counter >= self.output_dim:
                 break
         i_y += 1
     return y
示例#4
0
 def _inverse(self, x):
     """Take the mean of overlapping values."""
     n_y_cons = numx.bincount(self.connections)  # n. connections to y_i
     y_cons = numx.argsort(self.connections)  # x indices for y_i
     y = numx.zeros((len(x), self.input_dim))
     i_x_counter = 0  # counter for processed x indices
     i_y = 0  # current y index
     while True:
         n_cons = n_y_cons[i_y]
         if n_cons > 0:
             y[:,i_y] = old_div(numx.sum(x[:,y_cons[i_x_counter:
                                            i_x_counter + n_cons]],
                                 axis=1), n_cons)
             i_x_counter += n_cons
             if i_x_counter >= self.output_dim:
                 break
         i_y += 1
     return y