From 8c3694bc911bbeab63e75c18f920e0991a5fa877 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Sat, 07 Dec 2013 17:38:50 +0000
Subject: [PATCH] Ensemble

---
 src/matrix.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/matrix.c b/src/matrix.c
index 5627b87..68e6f8d 100644
--- a/src/matrix.c
+++ b/src/matrix.c
@@ -13,6 +13,18 @@
     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);
@@ -26,12 +38,14 @@
 
 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