15,879,844 members
0.00/5 (No votes)
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 4:52am
v2
Comments
Rick York 26-Nov-23 22:03pm
I assume you are asking about this : net.mNeurons.back()->unaryExpr(ptr_fun(unary))
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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Pete O'Hanlon 80 OriginalGriff 75 Richard MacCutchan 65 Rick York 50 Graeme_Grant 45
 Pete O'Hanlon 1,790 OriginalGriff 1,325 Graeme_Grant 835 Richard Deeming 743 Dave Kreskowiak 634

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900