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

Method train_binary

src/thundersvm/model/svc.cpp:147–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145}
146
147void SVC::train_binary(const DataSet &dataset, int i, int j, SyncArray<float_type> &alpha, float_type &rho) {
148 DataSet::node2d ins = dataset.instances(i, j);//get instances of class i and j
149 SyncArray<int> y(ins.size());
150 alpha.resize(ins.size());
151 SyncArray<float_type> f_val(ins.size());
152 alpha.mem_set(0);
153 int *y_data = y.host_data();
154 float_type *f_val_data = f_val.host_data();
155 for (int l = 0; l < dataset.count()[i]; ++l) {
156 y_data[l] = +1;
157 f_val_data[l] = -1;
158 }
159 for (int l = 0; l < dataset.count()[j]; ++l) {
160 y_data[dataset.count()[i] + l] = -1;
161 f_val_data[dataset.count()[i] + l] = +1;
162 }
163 KernelMatrix k_mat(ins, param);
164 int ws_size = get_working_set_size(ins.size(), k_mat.n_features());
165 CSMOSolver solver;
166 solver.solve(k_mat, y, alpha, rho, f_val, param.epsilon, param.C * c_weight[i], param.C * c_weight[j], ws_size,
167 max_iter);
168 LOG(INFO) << "rho = " << rho;
169 int n_sv = 0;
170 y_data = y.host_data();
171 float_type *alpha_data = alpha.host_data();
172 for (int l = 0; l < alpha.size(); ++l) {
173 alpha_data[l] *= y_data[l];
174 if (alpha_data[l] != 0) n_sv++;
175 }
176 LOG(INFO) << "#sv = " << n_sv;
177}
178
179vector<float_type> SVC::predict(const DataSet::node2d &instances, int batch_size) {
180 dec_values.resize(instances.size() * n_binary_models);

Callers

nothing calls this directly

Calls 7

instancesMethod · 0.80
resizeMethod · 0.80
mem_setMethod · 0.80
solveMethod · 0.80
sizeMethod · 0.45
host_dataMethod · 0.45
n_featuresMethod · 0.45

Tested by

no test coverage detected