Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- double fx(double x) //Sigmoid function
- {
- return 1 / (1 + exp(-(x)));
- }
- double fd(double x) //Sigmoid derivative
- {
- return x * (1 - x);
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- double f_out = 0; //output
- double input=0.50;
- double weight=0.10;
- double learn=0.1; //learning-rate
- double desired_output=0.12;
- double requested_data=0.65;
- double err; //error value calculation, the error function 2(out-desired) is the derivative of the cost function C = (out-desired)^2
- int i; // iteration
- for (i = 0; i <= 30000; i++) {
- // 1 single node, sigmoid backprop.
- f_out = fx(input * weight);
- err = 2*( f_out - desired_output );
- weight = weight - learn * err *fd(f_out) * input; // weight minus learning_rate * error * derivative_output * input
- //all numbers must be between -1 and 1.
- printf("\n%d. desired output is %.2lf",i, desired_output);
- printf("\nweight %.9lf error %.9lf", weight, err);
- printf("\nOutput for the current input (0.50) is %.9lf", f_out);
- printf("\nOutput for value 0.65 as new requested data would be %.9lf\n", fx(requested_data*weight));
- }
- scanf("%lf", &input);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement