473,836 Members | 1,472 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
#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 {



~CBPNet() {};

float Train(float, float, float);

float Run(float, float);


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 2949
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:

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
Apr 7 '07 #4

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

Similar topics

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.
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
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."
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
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
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
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...)
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...
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...
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...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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...
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...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.