Click here to Skip to main content
15,849,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
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?

1 solution

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.
 
Share this answer
 

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



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