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 }