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

Method load_from_file

src/thundersvm/model/svmmodel.cpp:201–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199}
200
201void SvmModel::load_from_file(string path) {
202 ifstream ifs;
203 ifs.open(path.c_str());
204 if(!ifs.is_open()){
205 LOG(INFO)<<"file "<<path<<" not found";
206 exit(1);
207 }
208 //CHECK(ifs.is_open()) << "file " << path << " not found";
209 string feature;
210 while (ifs >> feature) {
211 if (feature == "svm_type") {
212 string value;
213 ifs >> value;
214 for (int i = 0; i < 6; i++) {
215 if (value == SvmParam::svm_type_name[i])
216 param.svm_type = static_cast<SvmParam::SVM_TYPE>(i);
217 }
218 } else if (feature == "kernel_type") {
219 string value;
220 ifs >> value;
221 for (int i = 0; i < 6; i++) {
222 if (value == SvmParam::kernel_type_name[i])
223 param.kernel_type = static_cast<SvmParam::KERNEL_TYPE>(i);
224 }
225 } else if (feature == "degree") {
226 ifs >> param.degree;
227 } else if (feature == "nr_class") {
228 ifs >> n_classes;
229 n_binary_models = n_classes * (n_classes - 1) / 2;
230 rho.resize(n_binary_models);
231 n_sv.resize(n_classes);
232 } else if (feature == "coef0") {
233 ifs >> param.coef0;
234 } else if (feature == "gamma") {
235 ifs >> param.gamma;
236
237 } else if (feature == "total_sv") {
238 ifs >> n_total_sv;
239 } else if (feature == "rho") {
240 for (int i = 0; i < n_binary_models; ++i) {
241 ifs >> rho.host_data()[i];
242 }
243 } else if (feature == "label") {
244 label = vector<int>(n_classes);
245 for (int i = 0; i < n_classes; ++i) {
246 ifs >> label[i];
247 }
248 } else if (feature == "nr_sv") {
249 for (int i = 0; i < n_classes; ++i) {
250 ifs >> n_sv.host_data()[i];
251 }
252 } else if (feature == "probA") {
253 param.probability = 1;
254 probA = vector<float_type>(n_binary_models);
255 for (int i = 0; i < n_binary_models; ++i) {
256 ifs >> probA[i];
257 }
258 } else if (feature == "probB") {

Callers

nothing calls this directly

Calls 3

resizeMethod · 0.80
clearMethod · 0.80
host_dataMethod · 0.45

Tested by

no test coverage detected