Apply this expert onto a dataset for multiclass problem.
468 {
469
470 uint64_t numberOfFeatures = test_data.getNumberOfFeatures();
471 uint64_t numberOfEvents = test_data.getNumberOfEvents();
472
473 auto X = std::unique_ptr<float[]>(new float[numberOfEvents * numberOfFeatures]);
474 npy_intp dimensions_X[2] = {static_cast<npy_intp>(numberOfEvents), static_cast<npy_intp>(numberOfFeatures)};
475
476 for (uint64_t iEvent = 0; iEvent < numberOfEvents; ++iEvent) {
477 test_data.loadEvent(iEvent);
479 for (uint64_t iFeature = 0; iFeature < numberOfFeatures; ++iFeature)
480 X[iEvent * numberOfFeatures + iFeature] = (test_data.m_input[iFeature] -
m_means[iFeature]) /
m_stds[iFeature];
481 } else {
482 for (uint64_t iFeature = 0; iFeature < numberOfFeatures; ++iFeature)
483 X[iEvent * numberOfFeatures + iFeature] = test_data.m_input[iFeature];
484 }
485 }
486
488 std::vector<std::vector<float>> probabilities(test_data.getNumberOfEvents(), std::vector<float>(nClasses,
489 std::numeric_limits<float>::quiet_NaN()));
490
491 try {
492 auto ndarray_X = boost::python::handle<>(PyArray_SimpleNewFromData(2, dimensions_X, NPY_FLOAT32, X.get()));
494 for (uint64_t iEvent = 0; iEvent < numberOfEvents; ++iEvent) {
495
496
497 for (uint64_t iClass = 0; iClass < nClasses; ++iClass) {
498 probabilities[iEvent][iClass] = static_cast<float>(*static_cast<float*>(PyArray_GETPTR2(reinterpret_cast<PyArrayObject*>
499 (result.ptr()),
500 iEvent, iClass)));
501 }
502 }
503 } catch (...) {
504 PyErr_Print();
505 PyErr_Clear();
506 B2ERROR("Failed calling applying PythonExpert");
507 throw std::runtime_error("Failed calling applying PythonExpert");
508 }
509
510 return probabilities;
511 }
GeneralOptions m_general_options
General options loaded from the weightfile.
unsigned int m_nClasses
Number of classes in a classification problem.