From 2d44fb1e76ed8d336a98b74ebe36476e30c81d15 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Sun, 31 May 2020 08:09:05 -0400 Subject: [PATCH] added option for predict function to return value before applying activation function as optional argument --- machine_learning/adaline_learning.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/machine_learning/adaline_learning.cpp b/machine_learning/adaline_learning.cpp index ec0dd27c8..562958d64 100644 --- a/machine_learning/adaline_learning.cpp +++ b/machine_learning/adaline_learning.cpp @@ -74,9 +74,11 @@ class adaline { /** * predict the output of the model for given set of features * \param[in] x input vector + * \param[out] out optional argument to return neuron output before applying + * activation function (optional, `nullptr` to ignore) * \returns model prediction output */ - int predict(const std::vector &x) { + int predict(const std::vector &x, double *out = nullptr) { if (!check_size_match(x)) return 0; @@ -85,6 +87,9 @@ class adaline { // for (int i = 0; i < x.size(); i++) y += x[i] * weights[i]; y = std::inner_product(x.begin(), x.end(), weights.begin(), y); + if (out != nullptr) // if out variable is provided + *out = y; + return activation(y); // quantizer: apply ADALINE threshold function }