File: features_bool.c

package info (click to toggle)
libocas 0.97%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 6,760 kB
  • sloc: ansic: 7,956; makefile: 103; sh: 7
file content (177 lines) | stat: -rw-r--r-- 4,263 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*-----------------------------------------------------------------------
 * ocas_helper.c: Implementation of helper functions for the OCAS solver.
 *
 * It supports both sparse and dense matrices and loading data from
 * the SVM^light format.
 *-------------------------------------------------------------------- */

#define _FILE_OFFSET_BITS  64

#include <pthread.h>

#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <sys/time.h>
#include <stdlib.h>
#include <time.h>

#include "libocas.h"
#include "ocas_helper.h"


/*----------------------------------------------------------------------
  full_bool_compute_output( output ) does the follwing:

  output = data_X'*W;
  ----------------------------------------------------------------------*/
int full_bool_compute_output( double *output, void* user_data )
{
  uint32_t i, j, k, dataDim; /* k is new index for the vector W */
  double tmp;
  uint8_t* ptr;

  ptr = (uint8_t*)mxGetPr( data_X );
  
  dataDim = nDim/8;

  for(i=0; i < nData; i++) { 
    tmp = X0*W0;
    
    k = 0;

    for(j=0; j < dataDim; j++ ) {
      if (ptr[LIBOCAS_INDEX(j,i,dataDim)] & 0x01) {
	tmp += W[k];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,i,dataDim)] & 0x02) {
	tmp += W[k];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,i,dataDim)] & 0x04) {
	tmp += W[k];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,i,dataDim)] & 0x08) {
	tmp += W[k];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,i,dataDim)] & 0x10) {
	tmp += W[k];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,i,dataDim)] & 0x20) {
	tmp += W[k];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,i,dataDim)] & 0x40) {
	tmp += W[k];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,i,dataDim)] & 0x80) {
	tmp += W[k];
      }
      k++;
    }
    output[i] = tmp*data_y[i];
  }
  
  return 0;
}



/*----------------------------------------------------------------------------------
  full_bool_add_new_cut( new_col_H, new_cut, cut_length, nSel ) does the following:

    new_a = sum(data_X(:,find(new_cut ~=0 )),2);
    new_col_H = [full_A(:,1:nSel)'*new_a ; new_a'*new_a];
    full_A(:,nSel+1) = new_a;

  ---------------------------------------------------------------------------------*/
int full_bool_add_new_cut( double *new_col_H, 
                           uint32_t *new_cut, 
                           uint32_t cut_length, 
                           uint32_t nSel,
                           void* user_data)
{
  /*****************************/
  double sq_norm_a;
  uint32_t i, j, k, dataDim; /* k is new index for the vector a*/
  uint8_t *ptr;

  ptr = (uint8_t*)mxGetPr(data_X);
  
  dataDim = nDim/8;
  
  memset(new_a, 0, sizeof(double)*nDim);


  for(i=0; i < cut_length; i++) {
    
    k = 0;
    
    for(j=0; j < dataDim; j++ ) {
      if (ptr[LIBOCAS_INDEX(j,new_cut[i],dataDim)] & 0x01) {
	new_a[k] += data_y[new_cut[i]];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,new_cut[i],dataDim)] & 0x02) {
	new_a[k] += data_y[new_cut[i]];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,new_cut[i],dataDim)] & 0x04) {
	new_a[k] += data_y[new_cut[i]];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,new_cut[i],dataDim)] & 0x08) {
	new_a[k] += data_y[new_cut[i]];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,new_cut[i],dataDim)] & 0x10) {
	new_a[k] += data_y[new_cut[i]];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,new_cut[i],dataDim)] & 0x20) {
	new_a[k] += data_y[new_cut[i]];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,new_cut[i],dataDim)] & 0x40) {
	new_a[k] += data_y[new_cut[i]];
      }
      k++;
      if (ptr[LIBOCAS_INDEX(j,new_cut[i],dataDim)] & 0x80) {
	new_a[k] += data_y[new_cut[i]];
      }
      k++;
    }

    A0[nSel] += X0*data_y[new_cut[i]];    
  }

  /*****************************/

  /* compute new_a'*new_a and insert new_a to the last column of full_A */
  sq_norm_a = A0[nSel]*A0[nSel];
  for(j=0; j < nDim; j++ ) {
    sq_norm_a += new_a[j]*new_a[j];
    full_A[LIBOCAS_INDEX(j,nSel,nDim)] = new_a[j];
  }

  new_col_H[nSel] = sq_norm_a;
  for(i=0; i < nSel; i++) {
    double tmp = A0[nSel]*A0[i];

    for(j=0; j < nDim; j++ ) {
      tmp += new_a[j]*full_A[LIBOCAS_INDEX(j,i,nDim)];
    }
    new_col_H[i] = tmp;
  }

/*  mxFree( new_a );*/

  return 0;
}