ClassifierEngine::ResultVector ClassifierEngine::runOnBatch(const Bundle& input) { auto network = getAggregateNetwork(); network->setIsTraining(false); auto bundle = network->runInputs(input); auto& result = bundle["outputActivations"].get<matrix::MatrixVector>().front(); auto labels = convertActivationsToLabels(std::move(result), *getModel()); ClassifierEngine::ResultVector results; if(_shouldUseLabeledData) { bundle = network->getCost(input); auto cost = bundle["cost"].get<double>(); results = compareWithReference(cost * labels.size(), getIteration(), labels, getReferenceLabels(bundle, *getModel())); } else { results = recordLabels(labels); } restoreAggregateNetwork(); return results; }
NeuralNetwork::Matrix NeuralNetwork::runInputs(const Matrix& m) const { //util::log("NeuralNetwork") << "Running forward propagation on matrix (" << m.rows() // << " rows, " << m.columns() << " columns).\n"; auto temp = convertToBlockSparseForLayerInput(front(), m); return runInputs(temp).toMatrix(); }
float NeuralNetwork::computeAccuracy(const BlockSparseMatrix& input, const BlockSparseMatrix& reference) const { assert(input.rows() == reference.rows()); assert(reference.columns() == getOutputCount()); auto result = runInputs(input); float threshold = 0.5f; auto resultActivations = result.greaterThanOrEqual(threshold); auto referenceActivations = reference.greaterThanOrEqual(threshold); util::log("NeuralNetwork") << "Result activations " << resultActivations.toString(); util::log("NeuralNetwork") << "Reference activations " << referenceActivations.toString(); auto matchingActivations = resultActivations.equals(referenceActivations); float matches = matchingActivations.reduceSum(); return matches / result.size(); }