MCPcopy Create free account
hub / github.com/Xtra-Computing/thundersvm / nu_smo_solve_kernel

Function nu_smo_solve_kernel

src/thundersvm/kernel/smo_kernel.cpp:127–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125 }
126
127 void nu_smo_solve_kernel(const int *y, float_type *f_val, float_type *alpha, float_type *alpha_diff,
128 const int *working_set, int ws_size, float_type C, const kernel_type *k_mat_rows,
129 const kernel_type *k_mat_diag, int row_len, float_type eps, float_type *diff,
130 int max_iter) {
131 //allocate shared memory
132 float_type alpha_i_diff; //delta alpha_i
133 float_type alpha_j_diff;
134 kernel_type *kd = new kernel_type[ws_size]; // diagonal elements for kernel matrix
135
136 //index, f value and alpha for each instance
137 float_type *a_old = new float_type[ws_size];
138 kernel_type *kIpwsI = new kernel_type[ws_size];
139 kernel_type *kInwsI = new kernel_type[ws_size];
140 float_type *f = new float_type[ws_size];
141 for (int tid = 0; tid < ws_size; ++tid) {
142 int wsi = working_set[tid];
143 f[tid] = f_val[wsi];
144 a_old[tid] = alpha[wsi];
145 kd[tid] = k_mat_diag[wsi];
146 }
147 float_type local_eps;
148 int numOfIter = 0;
149 while (1) {
150 //select I_up (y=+1)
151 int ip = 0;
152 float_type up_value_p = INFINITY;
153 for (int tid = 0; tid < ws_size; ++tid) {
154 int wsi = working_set[tid];
155 if (y[wsi] > 0 && alpha[wsi] < C)
156 if (f[tid] < up_value_p) {
157 ip = tid;
158 up_value_p = f[tid];
159 }
160 }
161
162 for (int tid = 0; tid < ws_size; ++tid) {
163 kIpwsI[tid] = k_mat_rows[row_len * ip + working_set[tid]];//K[i, wsi]
164 }
165
166 //select I_up (y=-1)
167 int in = 0;
168 float_type up_value_n = INFINITY;
169 for (int tid = 0; tid < ws_size; ++tid) {
170 int wsi = working_set[tid];
171 if (y[wsi] < 0 && alpha[wsi] > 0)
172 if (f[tid] < up_value_n) {
173 in = tid;
174 up_value_n = f[tid];
175 }
176 }
177 for (int tid = 0; tid < ws_size; ++tid) {
178 kInwsI[tid] = k_mat_rows[row_len * in + working_set[tid]];//K[i, wsi]
179 }
180
181 //select I_low (y=+1)
182 float_type low_value_p = -INFINITY;
183 for (int tid = 0; tid < ws_size; ++tid) {
184 int wsi = working_set[tid];

Callers 1

nu_smo_solveFunction · 0.85

Calls 2

maxFunction · 0.85
minFunction · 0.85

Tested by

no test coverage detected