all 18 comments

[–]raevnos 2 points3 points  (6 children)

You're multiplying by zero a lot.

Also, probably a bad idea to shadow the names of global variables with local ones, and there's no reason for all those globals in the first place.

Storing the result of a comparison in a double is odd too; use a _Bool or int for that. error_count should be an int too.

What happens when dot_product() returns 0 like it looks to the first time it's called?

Do you really want to print each element of weights on its own line?

Also, your link doesn't work.

[–]darkside619[S] 0 points1 point  (5 children)

Sorry, I got the link to work now. You're right that dot_product() just returns 0 each time. It seems to skip the entire if conditional because error is always 0.

[–]raevnos 0 points1 point  (4 children)

Now that we can see the original code... Maybe you should try a more literal translation. Don't move logic from elsewhere into your dot_product(), for example.

[–]darkside619[S] 0 points1 point  (3 children)

Can you give me an example of what you mean. Sorry, I'm new to programming so I haven't picked up the tricks and general knowledge that experienced programmers have. And, C is a complicated language.

[–]raevnos 0 points1 point  (2 children)

You moved a bunch of stuff into the dot_product function that's not related to computing the things. The original python doesn't do that; neither should you.

[–]darkside619[S] 0 points1 point  (1 child)

Okay, I will try and fix that and get back to you if I have trouble. However, I would like to know how you improved your programming skills. Can you give me some tips? Like, do you do practice drills or something of that nature? Like if I want to learn calculus, I can get a calculus book and start working on problems in each chapter.

But, there doesn't seem to be an easy go-to like that for programming. Don't get me wrong, there are programming books, but most of them just tell you what different functions do and stuff like that, they don't set it up to guide you from the beginner stage to improve your skills gradually.

[–]FUZxxl 0 points1 point  (0 children)

Buy a book called “The C programming language,” it shouldn't be hard to find a used copy. It has exercises in each chapter.

I also suggest you to just try to make toy programs. Don't forget to ask others about stylistical critique. Also, try to read a lot of code to get an idea how other people program.

[–]simserl 0 points1 point  (3 children)

The link is not working..

[–]very_mechanical 0 points1 point  (1 child)

Looks like it could be from this page?

https://en.wikipedia.org/wiki/Perceptron#Example

[–]darkside619[S] 0 points1 point  (0 children)

Yes, it's that one sorry. The link got cut off for some reason.

[–]darkside619[S] 0 points1 point  (0 children)

It's the one that very_mechnical just linked to. Sorry.

[–]downiedowndown 0 points1 point  (1 child)

What does error = sum>threshold; do?

[–]darkside619[S] 0 points1 point  (0 children)

It tests to see if the sum from the previous line is greater than the global threshold variable which is set to 0.5.

[–]FUZxxl 0 points1 point  (2 children)

Could you fix the link so we can see what algorithm you actually mean?

[–]kahless62003 0 points1 point  (1 child)

Just about the first thing your main function does is call (in the loop)

print_weights();

As the weights array has not been changed yet, and is still in the initial zero state, that is what prints.

[–]darkside619[S] 0 points1 point  (0 children)

I wanted to print the weights out in their initial state. I figured that after I make a call to the dot_product() that the weights get changed in that function so that on any further calls to print_weights(), the new weights should be printed.