473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Neural Networks

A friend of mine just was over at my house explaining Neural Networks
and I understood it as well as I could. Here is my own explination.

A neural network has to first run in a loop 1,000's of times given
it's input and output. It then naturally learns the simplest
algorithm to generate that input and output, using a networked matrix
of numbers that are run through a filter, and compared to the input.

The algorithm to train a neural network looks like this:

Start off with a random algorithm

Provide Input (input layer)

Multiply the random weights along with the input, and a static weight.
(hidden layer)

Run the weights through a Sigmoid function as a filter.

Take one of the weighted networks, after it has run through a sigmoid
function, and weight it again. (Output layer).

Now we calculate all of our networks to see how much they disagree
with the provided output.
Then we loop through the weights, changing them all to a better fit.

So each time we run this function it gets a little bit better. But
ultimately we are going to be getting output that is either closer to
zero or closer to one. The network just remembers at the final output
layer what is the closest to 0 and 1 it can get too.

IT'S REALLY COOL! This program below, makes its own binary XOR
function.
#include <math.h>

#include <stdlib.h>

#include <time.h>

#include <iostream.h>

#define BPM_ITER 2000

#define BP_LEARNING (float)(0.5) // The learning coefficient.

class CBPNet {

public:

CBPNet();

~CBPNet() {};

float Train(float, float, float);

float Run(float, float);

private:

float m_fWeights[3][3]; // Weights for the 3 neurons.

float Sigmoid(float); // The sigmoid function.

};

CBPNet::CBPNet() {

srand((unsigned)(time(NULL)));

for (int i=0;i<3;i++) {

for (int j=0;j<3;j++) {

// For some reason, the Microsoft rand() function

// generates a random integer. So, I divide by the

// number by MAXINT/2, to get a num between 0 and 2,

// the subtract one to get a num between -1 and 1.

m_fWeights[i][j] = (float)(rand())/(32767/2) - 1;

}

}

}

float CBPNet::Train(float i1, float i2, float d) {

// These are all the main variables used in the

// routine. Seems easier to group them all here.

float net1, net2, i3, i4, out;

// Calculate the net values for the hidden layer neurons.

net1 = 1 * m_fWeights[0][0] + i1 * m_fWeights[1][0] +

i2 * m_fWeights[2][0];

net2 = 1 * m_fWeights[0][1] + i1 * m_fWeights[1][1] +

i2 * m_fWeights[2][1];

// Use the hardlimiter function - the Sigmoid.

i3 = Sigmoid(net1);

i4 = Sigmoid(net2);

// Now, calculate the net for the final output layer.

net1 = 1 * m_fWeights[0][2] + i3 * m_fWeights[1][2] +

i4 * m_fWeights[2][2];

out = Sigmoid(net1);

// We have to calculate the deltas for the two layers.

// Remember, we have to calculate the errors backwards

// from the output layer to the hidden layer (thus the

// name 'BACK-propagation').

float deltas[3];

deltas[2] = out*(1-out)*(d-out);

deltas[1] = i4*(1-i4)*(m_fWeights[2][2])*(deltas[2]);

deltas[0] = i3*(1-i3)*(m_fWeights[1][2])*(deltas[2]);

// Now, alter the weights accordingly.

float v1 = i1, v2 = i2;

for(int i=0;i<3;i++) {

// Change the values for the output layer, if necessary.

if (i == 2) {

v1 = i3;

v2 = i4;

}

m_fWeights[0][i] += BP_LEARNING*1*deltas[i];

m_fWeights[1][i] += BP_LEARNING*v1*deltas[i];

m_fWeights[2][i] += BP_LEARNING*v2*deltas[i];

}

return out;

}

float CBPNet::Sigmoid(float num) {

return (float)(1/(1+exp(-num)));

}

float CBPNet::Run(float i1, float i2) {

// I just copied and pasted the code from the Train() function,

// so see there for the necessary documentation.

float net1, net2, i3, i4;

net1 = 1 * m_fWeights[0][0] + i1 * m_fWeights[1][0] +

i2 * m_fWeights[2][0];

net2 = 1 * m_fWeights[0][1] + i1 * m_fWeights[1][1] +

i2 * m_fWeights[2][1];

i3 = Sigmoid(net1);

i4 = Sigmoid(net2);

net1 = 1 * m_fWeights[0][2] + i3 * m_fWeights[1][2] +

i4 * m_fWeights[2][2];

return Sigmoid(net1);

}

void main() {

CBPNet bp;

for (int i=0;i<BPM_ITER;i++) {

bp.Train(0,0,0);

bp.Train(0,1,1);

bp.Train(1,0,1);

bp.Train(1,1,0);

}

cout << "0,0 = " << bp.Run(0,0) << endl;

cout << "0,1 = " << bp.Run(0,1) << endl;

cout << "1,0 = " << bp.Run(1,0) << endl;

cout << "1,1 = " << bp.Run(1,1) << endl;

}

Apr 7 '07 #1
3 2909
On 6 Apr 2007 22:07:13 -0700 in comp.lang.c++, "CoreyWhite"
<Co********@gmail.comwrote,
>Newsgroups: alt.magick,alt.native,comp.lang.c++,alt.2600
Apr 7 '07 #2
It looks neurological ... hey look at this free book:
http://www.relisoft.com/book/index.htm

Apr 7 '07 #3
On Apr 7, 5:55 am, "boson boss" <junker...@gmail.comwrote:
It looks neurological ... hey look at this free book:http://www.relisoft.com/book/index.htm
The book looks fine, but I am on an iMac. I even have my iMac
keyboard plugged in today! I like it better than my IBM keyboard
now. You can't type as quick on an iMac keyboard, but it is easier to
avoid typos.

I'm not sure if you understand this Neural network yet. It begins
with a random matrix of numbers between 0 and 1. These are the
weights that form the basis of the algorithm. The basic algorithm
just multiplies the matrix of weights with our input, and then it runs
through a filter. The sigmoid filter can take even random information
and morph it into something straight along the range from 0 or 1. So
everything gets closer to our end goal. In the end the values are
just adjusted closer to what the output should be with a complicated
little Delta function, that basically subtracts the difference between
the weights and the output we know is what we want.

The final result is a fuzzy algorithm that can take guesses at what
the right answer is, even if it is given information it hasn't seen
before.
Apr 7 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Aum | last post by:
Hi, Can anyone please recommend a python-accessible library for neural network simulation? I've already got code for standard feed-forward, back-propagation networks, but am needing something...
1
by: Yaroslav Bulatov | last post by:
Just for fun :) http://yaroslav.hopto.org/russianwiki/index.php/neural-impl Is there a more compact way? Yaroslav
0
by: I. Myself | last post by:
The VizANN package is a free download from annevolve.sf.net. It contains a python program that graphically demonstrates a recurrent binary neural network. There is also an explanatory text file....
0
by: I. Myself | last post by:
Release Name: vizann-2.0 This freeware program may be downloaded from http://sourceforge.net/projects/annevolve. *Notes:* This is a program to graphically demonstrate the operational details...
1
by: AndreaM | last post by:
Hi all, I'm looking for a C++ (or at least C) library that implements both standard feedforward neural networks and also recurrent neural networks (RNN)... Any suggestion? I tried FANN but it...
4
by: pradeep.blogs | last post by:
I have implemented neural net in C++. I have tested with a simple OCR. You can download Source code for Neural net and simple OCR. http://neuralnetworks.in OCR is for handwritten recognition. I...
2
by: mwojc | last post by:
Hi! I released feed-forward neural network for python (ffnet) project at sourceforge. Implementation is extremelly fast (code written mostly in fortran with thin python interface, scipy optimizers...
0
by: buzzer | last post by:
i would like to build a software coding which can classify image and pattern using artificial neural networks the idea is it should be able to do feature extraction on a certain image (can consist...
0
by: YellowFin Announcements | last post by:
Yellowfin has announced a new partnership with Extol, one of Malaysia's largest ICT security solutions providers, in which Extol will integrate their predictive analytics application into...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.