From b2b7137b6f185ce2f01664d782a09b08d50d5a07 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Tue, 28 Jan 2014 07:16:56 +0000
Subject: [PATCH] About to do something stupid...
---
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