summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/svm/src/c/getAlphaFromTrainSet.c
diff options
context:
space:
mode:
authorLeo Chan <leochanj@live.unc.edu>2020-10-22 01:53:21 -0400
committerJoshua Bakita <jbakita@cs.unc.edu>2020-10-22 01:56:35 -0400
commitd17b33131c14864bd1eae275f49a3f148e21cf29 (patch)
tree0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/benchmarks/svm/src/c/getAlphaFromTrainSet.c
parent601ed25a4c5b66cb75315832c15613a727db2c26 (diff)
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to: - Use libextra to loop as realtime jobs - Preallocate memory before starting their main computation - Accept input via stdin instead of via argc Does not include the SD-VBS matlab code. Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/benchmarks/svm/src/c/getAlphaFromTrainSet.c')
-rw-r--r--SD-VBS/benchmarks/svm/src/c/getAlphaFromTrainSet.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/svm/src/c/getAlphaFromTrainSet.c b/SD-VBS/benchmarks/svm/src/c/getAlphaFromTrainSet.c
new file mode 100644
index 0000000..681f2c6
--- /dev/null
+++ b/SD-VBS/benchmarks/svm/src/c/getAlphaFromTrainSet.c
@@ -0,0 +1,98 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5#include "svm.h"
6
7alphaRet* getAlphaFromTrainSet(int N, F2D* trn1, F2D* trn2, int iterations)
8{
9 float tolerance, C, eps, *b;
10 F2D *a_result, *b_result;
11 int NumChanged, r, ExamineAll, cnt, d, dim, ret, iter, i;
12 F2D *X, *Y;
13 F2D *a, *e;
14
15 b = malloc(sizeof(float));
16 alphaRet* alpha;
17 alpha = (alphaRet*)malloc(sizeof(alphaRet));
18 tolerance = 0.001;
19 C = 0.05;
20 d = -1;
21 dim = 256;
22 eps = 0.001;
23 a_result = fSetArray(iterations, N, 0);
24 b_result = fSetArray(iterations, 1, 0);
25 ret = 0;
26
27 X = usps_read_partial( trn1, trn2, 0, 1, (N/iterations), iterations);
28
29 for(iter=0; iter<iterations; iter++)
30 {
31 Y = usps_read_partial( trn1, trn2, iter, 0, N/iterations, iterations);
32
33 a = fSetArray(N, 1, 0);
34 arrayref(b,0) = 0; /** check if ptr **/
35 e = fSetArray(N, 1, 0);
36 ExamineAll = 1;
37 cnt = 0;
38 NumChanged = 0;
39
40 while(NumChanged>0 || ExamineAll == 1)
41 {
42 cnt = cnt + 1;
43 NumChanged = 0;
44 if(ExamineAll == 1)
45 {
46 for(i=0; i<N; i++)
47 {
48 ret = examineExample(i, a, b, C, e, X, Y, tolerance, N, eps, dim);
49 NumChanged = NumChanged + ret;
50 }
51 }
52 else
53 {
54 for(i=0; i<N; i++)
55 {
56 if( asubsref(a,i) > 0 && asubsref(a,i) <C )
57 {
58 ret = examineExample(i, a, b, C, e, X, Y, tolerance, N, eps, dim);
59 NumChanged = NumChanged + ret;
60 }
61 }
62 }
63 if(ExamineAll == 1)
64 ExamineAll = 0;
65 else if(NumChanged == 0)
66 ExamineAll = 1;
67 }
68
69 for(r=0; r<N; r++)
70 subsref(a_result,iter,r) = asubsref(a,r); /** a_result has size iteration,N .. Check **/
71 asubsref(b_result,iter) = arrayref(b,0);
72
73 fFreeHandle(Y);
74 fFreeHandle(e);
75 fFreeHandle(a);
76 }
77
78 alpha->C = C;
79 alpha->d = d;
80 alpha->dim = dim;
81 alpha->eps = eps;
82 alpha->a_result = a_result;
83 alpha->b_result = b_result;
84 alpha->a = a;
85 alpha->b = arrayref(b,0);
86 alpha->X = X;
87 alpha->tolerance = tolerance;
88 alpha->ret;
89
90 free(b);
91
92 return alpha;
93
94}
95
96
97
98