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