Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Complicated recursive function help to find the output of a NN after n epochs of learning

Velpus Captiosus

Well-Known Coder
I think I have developed a algorithm to calculate the output of a NN after n epochs of learning ->this link:Expressing the output of a neural network after n iteration as a recursive function

I have written some code:

C:
int input()
{
    int x;
    printf("Give me the input:\n");
    scanf_s("%d", &x);
    return x;
}

int desiredOutput(int n)
{
    int x;
    printf("Give me the desired value of iteration %d:\n",n);
    scanf_s("%d", &x);

    if (n == 0)
    {
        return x;
    }
    else
    {
        return desiredOutput(n - 1);
    }
}

int output(int n)
{
    if (n == 0)
    {
        int b = 0;
        printf("The output at iteration n=%d is equal to %d\n", n, b);
        return b;
    }
    else
    {
        int b = input() * (desiredOutput(n - 1) - output(n - 1));
        printf("The output at iteration n=%d is equal to %d\n", n,b);
        return b;
    }
}

int main()
{
    output(2);

    return 0;
}

Output = input * bias and bias = previous desired output - previous output

But I am unsure if it does what the link says also i am confused on the order of the inputs.The program is written on a C++ compiler(VS extension) but it is a .c source file thats why there is the scanf_s() function instead of scanf().
 
I think I have developed a algorithm to calculate the output of a NN after n epochs of learning ->this link:Expressing the output of a neural network after n iteration as a recursive function

I have written some code:

C:
int input()
{
    int x;
    printf("Give me the input:\n");
    scanf_s("%d", &x);
    return x;
}

int desiredOutput(int n)
{
    int x;
    printf("Give me the desired value of iteration %d:\n",n);
    scanf_s("%d", &x);

    if (n == 0)
    {
        return x;
    }
    else
    {
        return desiredOutput(n - 1);
    }
}

int output(int n)
{
    if (n == 0)
    {
        int b = 0;
        printf("The output at iteration n=%d is equal to %d\n", n, b);
        return b;
    }
    else
    {
        int b = input() * (desiredOutput(n - 1) - output(n - 1));
        printf("The output at iteration n=%d is equal to %d\n", n,b);
        return b;
    }
}

int main()
{
    output(2);

    return 0;
}

Output = input * bias and bias = previous desired output - previous output

But I am unsure if it does what the link says also i am confused on the order of the inputs.The program is written on a C++ compiler(VS extension) but it is a .c source file thats why there is the scanf_s() function instead of scanf().
Hi there,

Have you attempted to test your code out with some test data? Try finding an example with an answer and run the numbers through the code and see if you can get anywhere near the known answer
 
I have but because the inputs are mixed up , I dont understand if what I am giving as input gives the correct output.
Not sure what you mean there by "...the order of the inputs are mixed up". When asking for user input, what you ask first will be stored first, and will be used at the time you tell it to use it.
 
Nah,since desiredOutput() is recursive (because it has to be) we get first the inputs for the nth epoch and we move recursively to the zeroth epoch,while input() is not recursive so there is the problem.
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom