mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
added option for predict function to return value before applying activation function as optional argument
This commit is contained in:
parent
b1c6556475
commit
2d44fb1e76
@ -74,9 +74,11 @@ class adaline {
|
|||||||
/**
|
/**
|
||||||
* predict the output of the model for given set of features
|
* predict the output of the model for given set of features
|
||||||
* \param[in] x input vector
|
* \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
|
* \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))
|
if (!check_size_match(x))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -85,6 +87,9 @@ class adaline {
|
|||||||
// for (int i = 0; i < x.size(); i++) y += x[i] * weights[i];
|
// for (int i = 0; i < x.size(); i++) y += x[i] * weights[i];
|
||||||
y = std::inner_product(x.begin(), x.end(), weights.begin(), y);
|
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
|
return activation(y); // quantizer: apply ADALINE threshold function
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user