Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello there
I try to update elements of a array but it does not perform correctly
for instance I have this array:

static double[,] weigh = { { 0.05, 0.1 }, { 0.2, 0.2 }, { 0.5, 0.5 } };


and I try to perform this on it:


for (k = 0; k < 2; k++)
                            {
                                if (z_input[k] > 0.0)
                                {
                                    bias[k] = bias[k] + 0.5 * (-1.0 - z_input[k]);
                                    weigh[k, 0] += (0.5 * (-1.0 - z_input[k]) * input1);
                                    weigh[k, 1] += (0.5 * (-1.0 - z_input[k]) * input2);
                                }
                            }



it performs on w[0,0] and w[0,1] correctly but give me w[1,0] and w[1,1] wrong!
what's wrong with it?
help me
thanks

What I have tried:

static int[,] input = { { 1, 1 }, { 1, -1 }, { -1, 1 } };
        static int[] target = { -1, 1, 1 };
        static double[,] weigh = { { 0.05, 0.1 }, { 0.2, 0.2 } };
        static double[] vector = { 0.5, 0.5 };
        static double[] bias = { 0.3, 0.15, 0.5 };
        static bool epoch = true;
        static int input1 = 0, input2 = 0;
        static int k = 0;
        static double[] z_input = new double[2];
        static int[] z_layer = new int[2];
        static double y_input;
        static int y;


if (target[j] == -1)
                       {

                           for (k = 0; k < 2; k++)
                           {
                               if (z_input[k] > 0.0)
                               {
                                   bias[k] = bias[k] + 0.5 * (-1.0 - z_input[k]);
                                   weigh[k, 0] += (0.5 * (-1.0 - z_input[k]) * input1);
                                   weigh[k, 1] += (0.5 * (-1.0 - z_input[k]) * input2);
                               }
                           }

                       }
Posted
Updated 18-Jul-17 7:29am
Comments
LLLLGGGG 18-Jul-17 13:22pm    
It does not update the element of the array or it updates them but the value is not what you want?
amir.nazarizadeh 18-Jul-17 13:37pm    
it updates but when second iteration of loop (k=1) starts, it updates weighs wrong!

1 solution

We have no idea of what can go wrong because you didn't gave us an autonomous piece of code, we can't test your code or reproduce the problem;
The only useful advice is to learn the debugger to see what the code is doing.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
Debugging C# Code in Visual Studio - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
Quote:
with debugger I found that the weights are wrong.

Can you update the question with a short piece of code that reproduce the problem ?
"weights are wrong" id not informative, give details.
 
Share this answer
 
v2
Comments
amir.nazarizadeh 18-Jul-17 13:38pm    
yes I used debugger and found it!
the problem is that when second iteration of loop (k=1) starts it updates weight wrong!
Patrice T 18-Jul-17 13:59pm    
If the problem is solved, you can accept the solution: it will tell everyone the question is solved.
Otherwise, update the question with your findings and explain how it is wrong.
amir.nazarizadeh 18-Jul-17 14:11pm    
I know!
but I used debugger before post this question
with debugger I found that the weights are wrong.
but It did not solve yet!

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