# Neural Nets in C++

This topic is 4986 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is there any good article out there witch has applied a neural net in c++ program code? I have heaps of truble of how i should structure up the program. And i have a relativ simpel net. 2 output neurons 4 inputs. donno if i even need a hidden layer. Any tips? any links please? when i serch for it i only get maths =/ Greetings Athos

##### Share on other sites
My latest ANN implementation in C++ is done using a matrix library. Inputs and outputs can thus be encoded as vectors and weights as a matrix. Since all operations can be expressed using vector and matrix operations, this can make the code rather clean.

##### Share on other sites
Yes i have heard this too but but how?

i mean were to put each value? so it becomes correct?
And how to map it to the input values and output values?
How do you structure it within the ANN class?

I have the problem making a program of the theori.
=/

-Athos

##### Share on other sites
Start by creating the matrixes for your weights. For a common fully connected feed-forward net you create one matrix for each hidden or output layer. This is of size (m+1)*n where m is the number of nodes in layer i plus one for the bias, and n is the number of nodes in layer i+1. So if you create a net without a hidden layer such as you describe, the weight matrix would be a 5x2 matrix.

Then you create a vector from your input, adding a 1-input as the bias node at the end to get you a vector of size 5. Taking the transpose of this, you get a 1x5 matrix. Then you can multiply this by the weight matrix to get a 1x2 matrix which you can feed to the activation function for your output nodes. Each element of this transposed vector will be a sum of all the output*weights going in to a node.

Let your activation function produce a similar output vector and you can noe compare this to your target output (also a vector), and do error correction in a similar manner.

I hope this helped.

##### Share on other sites
The tutorial's at my website have C++ implementations of feedforward ANNs and SOMs

(edited by Mod to clean up repeated text and include hyperlink)

[Edited by - Timkin on May 23, 2005 12:04:31 AM]

##### Share on other sites
fup

struct SNeuronLayer{  //the number of neurons in this layer  int m_NumNeurons;   //the layer of neurons  vector&lt;SNeuron&gt; m_vecNeurons;   SNeuronLayer(int NumNeurons, int NumInputsPerNeuron);};

you havent written out SNeuronLayer funktion in your tutorial.
Just wondering how you think you should add static objects to the SNeuron Vector? Becouse i cant really see a good way to do this unless i make it a vector array of sneuron pointers.

Might be something to look into.

-Athos

##### Share on other sites
Athos: I haven't written out all the code because you can download it using the link at the beginning of the tutorial.

Also, the code is kept very simple since I want it to be as easy to understand as possible, not only to C++ programmers but to programmers of other languages. This is why I avoid using pointers and allocating heap memory. It's up to the reader to customize it to suit their own requirements.

Timkin: What duplicated text? (also the hyperlink to the tutorials was in my sig)

##### Share on other sites

If you are considering doing more on your site i would recomend maby hyperlinking funktions to were thay are explained so you have the option to look at it. But over all a good page.

##### Share on other sites
Quote:
 Timkin: What duplicated text? (also the hyperlink to the tutorials was in my sig)

Your original post looked like the following:

"The tutorial's at my website have C++ implementations of feedforward ANNThe tutorial's at my website have C++ implementations of feedforward ANNs and SOMs."

##### Share on other sites
Quote:
 Your original post looked like the following:"The tutorial's at my website have C++ implementations of feedforward ANNThe tutorial's at my website have C++ implementations of feedforward ANNs and SOMs."

ah! Weird. Cheers.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015431
×