From 4bdf96bd6aafbec6bc3f0eab8739d6652878fd24 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Fri, 06 Dec 2013 21:26:09 +0000
Subject: [PATCH] New data format

---
 src/utils.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/src/utils.c b/src/utils.c
index 8229b2d..5180fe6 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -180,6 +180,35 @@
     sigma = sqrt(variance_array(a,n));
 }
 
+void translate_array(double *a, int n, double s)
+{
+    int i;
+    for(i = 0; i < n; ++i){
+        a[i] += s;
+    }
+}
+
+void scale_array(double *a, int n, double s)
+{
+    int i;
+    for(i = 0; i < n; ++i){
+        a[i] *= s;
+    }
+}
+int max_index(double *a, int n)
+{
+    if(n <= 0) return -1;
+    int i, max_i = 0;
+    double max = a[0];
+    for(i = 1; i < n; ++i){
+        if(a[i] > max){
+            max = a[i];
+            max_i = i;
+        }
+    }
+    return max_i;
+}
+
 double rand_normal()
 {
     int i;
@@ -187,3 +216,16 @@
     for(i = 0; i < 12; ++i) sum += (double)rand()/RAND_MAX;
     return sum-6.;
 }
+
+double **one_hot_encode(double *a, int n, int k)
+{
+    int i;
+    double **t = calloc(n, sizeof(double*));
+    for(i = 0; i < n; ++i){
+        t[i] = calloc(k, sizeof(double));
+        int index = (int)a[i];
+        t[i][index] = 1;
+    }
+    return t;
+}
+

--
Gitblit v1.10.0