Returns the normalised confusion matrix
341686
def confusion_matrix(self):
        
        confusion_matrix = self.pixel_classification_sum.astype(np.float)
        confusion_matrix = np.divide(confusion_matrix.T, self.pixel_truth_sum.T).T

        return confusion_matrix * 100.0
935204
def _covariance_matrix(self, type='noise'):
        
        if type == 'sampling':
            return self.sigma**2/(self.n-1)
        elif type == 'noise':
            return 4*self.sigma*N.var(self.rotated(), axis=0)
949415
def computePreRec(cm, class_names):
    '''
    
    '''
    n_classes = cm.shape[0]
    if len(class_names) != n_classes:
        print("Error in computePreRec! Confusion matrix and class_names "
              "list must be of the same size!")
        return
    precision = []
    recall = []
    f1 = []    
    for i, c in enumerate(class_names):
        precision.append(cm[i,i] / numpy.sum(cm[:,i]))
        recall.append(cm[i,i] / numpy.sum(cm[i,:]))
        f1.append( 2 * precision[-1] * recall[-1] / (precision[-1] + recall[-1]))
    return recall, precision, f1
822307
def normalized_mutual_info_score(self, reference_clusters):
        
        return normalized_mutual_info_score(self.get_labels(self), self.get_labels(reference_clusters))
939687
def G(self):
        
        if self.c is None:
            raise RuntimeError('Inverse cross spectral density requires '
                               'invertible noise covariance matrix c.')
        A = self.A()
        # TODO: can we do that more efficiently?
        G = np.einsum('ji..., jk... ->ik...', A.conj(), self.Cinv())
        G = np.einsum('ij..., jk... ->ik...', G, A)
        return G
1000303
def get_matrices():
    
    with open('hwrt/misc/is_one_symbol_classifier.pickle', 'rb') as f:
        a = pickle.load(f)

    arrays = []
    for el1 in a.input_storage:
        for el2 in el1.__dict__['storage']:
            if isinstance(el2, cuda.CudaNdarray):
                arrays.append({'storage': numpy.asarray(el2),
                               'name': el1.name})
            else:
                logging.warning("was type %s. Do nothing." % type(el2))
                logging.debug(el1.name)
    return arrays
280507
function getModelMatrix (rb) {
  var ms = rb.getMotionState()

  if (ms) {
    ms.getWorldTransform(transformTemp)
    var p = transformTemp.getOrigin()
    var q = transformTemp.getRotation()

    return mat4.fromRotationTranslation(
      [], [q.x(), q.y(), q.z(), q.w()], [p.x(), p.y(), p.z()])
  }
}
496076
def plot_confusion_matrix(cm, title="Confusion Matrix"):
    
    import matplotlib.pyplot as plt
    import math
    plt.figure()
    subjects = len(cm)
    root_subjects = math.sqrt(subjects)
    cols = math.ceil(root_subjects)
    rows = math.ceil(subjects/cols)
    classes = cm[0].shape[0]
    for subject in range(subjects):
        plt.subplot(rows, cols, subject+1)
        plt.imshow(cm[subject], interpolation='nearest', cmap=plt.cm.bone)
        plt.xticks(np.arange(classes), range(1, classes+1))
        plt.yticks(np.arange(classes), range(1, classes+1))
        cbar = plt.colorbar(ticks=[0.0, 1.0], shrink=0.6)
        cbar.set_clim(0.0, 1.0)
        plt.xlabel("Predicted")
        plt.ylabel("True label")
        plt.title("{0:d}".format(subject + 1))
    plt.suptitle(title)
    plt.tight_layout()
    plt.show()
1337119
def get_matrix(self):
        
        return np.array([ self.get_row_list(i) for i in range(self.row_count()) ])
610388
def asML(self):
        
        return newlinalg.DenseMatrix(self.numRows, self.numCols, self.values, self.isTransposed)
678629
def normalize(self):
		
		for i, (_, amplitude, phase) in enumerate(self.model):
			if amplitude < 0:
				self.model['amplitude'][i] = -amplitude
				self.model['phase'][i] = phase + 180.0
			self.model['phase'][i] = np.mod(self.model['phase'][i], 360.0)
1332125
def normalization(self):
        
        norm_r = self.normalization_range()        
        return quad(self, norm_r[0]*self._j_ref, norm_r[1]*self._j_ref)[0]
84881
def recall(self):
        
        true_pos = self.matrix[0][0]
        false_neg = self.matrix[0][1]
        return divide(1.0 * true_pos, true_pos + false_neg)
759126
def draw_confusion_matrix(matrix):
    ''''''
    fig = tfmpl.create_figure(figsize=(7,7))
    ax = fig.add_subplot(111)
    ax.set_title('Confusion matrix for MNIST classification')
    
    tfmpl.plots.confusion_matrix.draw(
        ax, matrix,
        axis_labels=['Digit ' + str(x) for x in range(10)],
        normalize=True
    )

    return fig
438820
def confusion_performance(mat, fn):
    
    if mat.shape[0] != mat.shape[1] or mat.shape < (2, 2):
        raise TypeError('{} is not a confusion matrix'.format(mat))
    elif mat.shape == (2, 2):
        return fn(mat[TP], mat[TN], mat[FP], mat[FN])
    res = numpy.empty(mat.shape[0])
    for i in range(len(res)):
        res[i] = fn(mat[i, i],                                   # TP
                    sum(mat) - sum(mat[:, i]) - sum(mat[i, :]),  # TN
                    sum(mat[:, i]) - mat[i, i],                  # FP
                    sum(mat[i, :]) - mat[i, i])                  # FN
    return res
1260442
def normalize(self):
        ''''''
        error = self.a * self.b
        t0 = self.a - (self.b * (0.5 * error))
        t1 = self.b - (self.a * (0.5 * error))
        t2 = t0 % t1
        self.a = t0 * (1.0 / t0.length())
        self.b = t1 * (1.0 / t1.length())
        self.c = t2 * (1.0 / t2.length())
725435
def value_matrix(self):
        

        if self.__value_matrix:
            return self.__value_matrix

        self.__value_matrix = [
            [value_dp.data for value_dp in value_dp_list] for value_dp_list in self.value_dp_matrix
        ]

        return self.__value_matrix