From 1d53b6414e0cd81043d7c76aa89f4f97da5e479f Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Thu, 23 Jan 2014 19:24:37 +0000
Subject: [PATCH] Stable on MNIST, about to change a lot
---
src/matrix.c | 29 +++++++++++++++++++++++++++--
1 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/matrix.c b/src/matrix.c
index 562a364..68e6f8d 100644
--- a/src/matrix.c
+++ b/src/matrix.c
@@ -13,14 +13,39 @@
free(m.vals);
}
+double matrix_accuracy(matrix truth, matrix guess)
+{
+ int k = truth.cols;
+ int i;
+ int count = 0;
+ for(i = 0; i < truth.rows; ++i){
+ int class = max_index(guess.vals[i], k);
+ if(truth.vals[i][class]) ++count;
+ }
+ return (double)count/truth.rows;
+}
+
+void matrix_add_matrix(matrix from, matrix to)
+{
+ assert(from.rows == to.rows && from.cols == to.cols);
+ int i,j;
+ for(i = 0; i < from.rows; ++i){
+ for(j = 0; j < from.cols; ++j){
+ to.vals[i][j] += from.vals[i][j];
+ }
+ }
+}
+
matrix make_matrix(int rows, int cols)
{
+ int i;
matrix m;
m.rows = rows;
m.cols = cols;
m.vals = calloc(m.rows, sizeof(double *));
- int i;
- for(i = 0; i < m.rows; ++i) m.vals[i] = calloc(m.cols, sizeof(double));
+ for(i = 0; i < m.rows; ++i){
+ m.vals[i] = calloc(m.cols, sizeof(double));
+ }
return m;
}
--
Gitblit v1.10.0