15,849,328 members
See more: , +
What is the definition of the unary function in the following procedure?
C++
```void train(NeuralNetwork& net)
{
cout << "Training:" << endl; RowVector input(3), output(3);
int stop = 0;
for (int i = 0; stop < 8 && i < 50000; i++)
{
cout << i + 1 << endl;
for (int num = 0; stop < 8 && num < 8; num++)
{
input.coeffRef(0) = (num >> 2) & 1;
input.coeffRef(1) = (num >> 1) & 1;
input.coeffRef(2) = num & 1;
output.coeffRef(0) = ((num + 1) >> 2) & 1;
output.coeffRef(1) = ((num + 1) >> 1) & 1;
output.coeffRef(2) = (num + 1) & 1;
net.train(input, output);
double mse = net.mse();
cout << "In [" << input << "] " << " Desired [" << output << "] " << " Out [" << net.mNeurons.back()->unaryExpr(ptr_fun(unary)) << "] " << " MSE [" << mse << "]" << endl;
stop = mse < 0.1 ? stop + 1 : 0;
}
}
}```

What I have tried:

I searched your source code for unary definition.
I searched the Eigen library for unary function definition.
I searched for unary function on the Web.
I defined my own arbitrary unary function to get the example to compile.
Posted
Updated 26-Nov-23 5:52am
v2
Rick York 26-Nov-23 22:03pm
You have not provide nearly enough information for us to guess. The biggest questions are what is NeuralNetwork and what are the prototypes of unaryExpr and ptr_fun?
How do you expect us to know?

## Solution 1

What source code are you referring to? If you found this in a CodeProject article, then you should post your question in the forum below the article.