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