473,651 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(f loat 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*d eltas[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(flo at 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 2930
On 6 Apr 2007 22:07:13 -0700 in comp.lang.c++, "CoreyWhite "
<Co********@gma il.comwrote,
>Newsgroups: alt.magick,alt. native,comp.lan g.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...@gmai l.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
2018
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 which does recurrent networks. Also desirable is self-organising maps and Hopfield nets.
1
2144
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
1249
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. Mitchell Timin -- "In theory, there is no difference between theory and practice. In practice, there is."
0
978
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 of two types of ANN (Artificial Neural Network) when used to implement the XOR function. The program is 100% GUI, meaning that there is no
1
3243
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 doesn't have any RNN support, ANNIE seems hard to compile and however RNN support seems to be limited. Thanks in advance for any help! Andrea
4
2384
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 have used 10X12 matrix for representing character
2
2330
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 involved) and very easy to use. I'm announcing it here because you, folks, are potential users/testers. If anyone is interested please visit http://ffnet.sourceforge.net (and then post comments if any...)
0
2124
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 of characters/pictures) and let the network learn about the difference of each extracted image and finally able to decide what the image is and classify it. is there any code for the feature extraction part?? or any coding or ideas on how to...
0
1568
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 Yellowfin. Neural Networks for predictive analysis As part of their risk management business, Extol have developed a neural network predictive analysis engine, and are now working with Yellowfin to develop a usable front end that is integrated with...
0
8352
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8802
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8697
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8579
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.