Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float64_t C = 1.0;
- index_t num_samples = 50;
- CMath::init_random(5);
- SGMatrix<float64_t> data =
- CDataGenerator::generate_gaussians(num_samples, 2, 2);
- CDenseFeatures<float64_t> features(data);
- SGVector<index_t> train_idx(num_samples), test_idx(num_samples);
- SGVector<float64_t> labels(num_samples);
- for (index_t i = 0, j = 0; i < data.num_cols; ++i)
- {
- if (i % 2 == 0)
- train_idx[j] = i;
- else
- test_idx[j++] = i;
- labels[i/2] = (i < data.num_cols/2) ? 0.0 : 1.0;
- }
- CDenseFeatures<float64_t>* train_feats = (CDenseFeatures<float64_t>*)features.copy_subset(train_idx);
- CDenseFeatures<float64_t>* test_feats = (CDenseFeatures<float64_t>*)features.copy_subset(test_idx);
- CMulticlassLabels* ground_truth = new CMulticlassLabels(labels);
- //CMulticlassOCAS* mocas = new CMulticlassOCAS(C, train_feats, ground_truth);
- CMulticlassLibLinear* mocas = new CMulticlassLibLinear(C, train_feats, ground_truth);
- mocas->io->set_loglevel(MSG_DEBUG);
- mocas->train();
- CLabels* pred = mocas->apply_multiclass(test_feats);
- for (int i = 0; i < num_samples; ++i)
- std::cout << ((CMulticlassLabels*)pred)->get_label(i) << " " << ((CMulticlassLabels)labels).get_label(i) << std::endl;
- SG_UNREF(mocas);
- SG_UNREF(train_feats);
- SG_UNREF(test_feats);
- SG_UNREF(pred);
Advertisement
Add Comment
Please, Sign In to add comment