Ejemplo n.º 1
0
 def _alt_sfa2_grad(self, x):
     """Reference grad method based on quadratic forms."""
     # note that the H and f arrays are cached in the node and remain even
     # after the extension has been deactivated
     if not hasattr(self, "__gradient_Hs"):
         quad_forms = [self.get_quadratic_form(i)
                       for i in range(self.output_dim)]
         self.__gradient_Hs = numx.vstack((quad_form.H[numx.newaxis]
                                         for quad_form in quad_forms))
         self.__gradient_fs = numx.vstack((quad_form.f[numx.newaxis]
                                         for quad_form in quad_forms))
     grad = (numx.dot(x, self.__gradient_Hs) +
                 numx.repeat(self.__gradient_fs[numx.newaxis,:,:],
                           len(x), axis=0))
     return grad
Ejemplo n.º 2
0
 def _alt_sfa2_grad(self, x):
     """Reference grad method based on quadratic forms."""
     # note that the H and f arrays are cached in the node and remain even
     # after the extension has been deactivated
     if not hasattr(self, "__gradient_Hs"):
         quad_forms = [
             self.get_quadratic_form(i) for i in range(self.output_dim)
         ]
         self.__gradient_Hs = numx.vstack(
             (quad_form.H[numx.newaxis] for quad_form in quad_forms))
         self.__gradient_fs = numx.vstack(
             (quad_form.f[numx.newaxis] for quad_form in quad_forms))
     grad = (numx.dot(x, self.__gradient_Hs) + numx.repeat(
         self.__gradient_fs[numx.newaxis, :, :], len(x), axis=0))
     return grad
Ejemplo n.º 3
0
 def _stop_training(self):
     """Calculate the class means."""
     ordered_means = []
     for label in self.label_means:
         self.label_means[label] /= self.n_label_samples[label]
         self.ordered_labels.append(label)
         ordered_means.append(self.label_means[label])
     self.ordered_means = numx.vstack(ordered_means)
Ejemplo n.º 4
0
 def _stop_training(self):
     """Calculate the class means."""
     ordered_means = []
     for label in self.label_means:
         self.label_means[label] /= self.n_label_samples[label]
         self.ordered_labels.append(label)
         ordered_means.append(self.label_means[label])
     self.ordered_means = numx.vstack(ordered_means)