added option for predict function to return value before applying activation function as optional argument

This commit is contained in:
Krishna Vedala 2020-05-31 08:09:05 -04:00
parent b1c6556475
commit 2d44fb1e76

View File

@ -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<double> &x) {
int predict(const std::vector<double> &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
}