C++ Neural Networks and Fuzzy Logic: Preface


Notes on the Header File Hop.h



Download 1,14 Mb.
Pdf ko'rish
bet74/443
Sana29.12.2021
Hajmi1,14 Mb.
#77367
1   ...   70   71   72   73   74   75   76   77   ...   443
Bog'liq
C neural networks and fuzzy logic

Notes on the Header File Hop.h

Notice that the data item activation in the neuron class is declared as protected. In order to make the member

activation of the neuron class accessible to the network class, the network is declared a friend class in the

class neuron. Also, there are two constructors for the class neuron. One of them creates the object neuron

without initializing any data members. The other creates the object neuron and initializes the connection

weights.


Source Code for the Hopfield Network

Listing 4.2 contains the source code for the C++ program for a Hopfield network in the file Hop.cpp. The

member functions of the classes declared in Hop.h are implemented here. The function main contains the

input patterns, values to initialize the weight matrix, and calls to the constructor of network class and other

member functions of the network class.

Listing 4.2 Source code for C++ program for Hopfield network.

//Hop.cpp   V. Rao, H. Rao

//Single layer Hopfield Network with 4 neurons

#include "hop.h"

neuron::neuron(int *j)

{

int i;



for(i=0;i<4;i++)

     {


     weightv[i]= *(j+i);

     }


}

int neuron::act(int m, int *x)

{

int i;


int a=0;

for(i=0;i

     {

     a += x[i]*weightv[i];



     }

return a;

}

int network::threshld(int k)



{

if(k>=0)


     return (1);

else


     return (0);

}

network::network(int a[4],int b[4],int c[4],int d[4])



{

C++ Neural Networks and Fuzzy Logic:Preface

Notes on the Header File Hop.h

57



nrn[0] = neuron(a) ;

nrn[1] = neuron(b) ;

nrn[2] = neuron(c) ;

nrn[3] = neuron(d) ;

}

void network::activation(int *patrn)



{

int i,j;


for(i=0;i<4;i++)

     {


     for(j=0;j<4;j++)

          {

          cout<<"\n nrn["<

               <

          }

     nrn[i].activation = nrn[i].act(4,patrn);

     cout<<"\nactivation is "<

     output[i]=threshld(nrn[i].activation);

     cout<<"\noutput value is  "<

     }


}

void main ()

{

int patrn1[]= {1,0,1,0},i;



int wt1[]= {0,−3,3,−3};

int wt2[]= {−3,0,−3,3};

int wt3[]= {3,−3,0,−3};

int wt4[]= {−3,3,−3,0};

cout<<"\nTHIS PROGRAM IS FOR A HOPFIELD NETWORK WITH A SINGLE LAYER OF";

cout<<"\n4 FULLY INTERCONNECTED NEURONS. THE NETWORK SHOULD RECALL THE";

cout<<"\nPATTERNS 1010 AND 0101 CORRECTLY.\n";

//create the network by calling its constructor.

// the constructor calls neuron constructor as many times as the number of

// neurons in the network.

network h1(wt1,wt2,wt3,wt4);

//present a pattern to the network and get the activations of the neurons

h1.activation(patrn1);

//check if the pattern given is correctly recalled and give message

for(i=0;i<4;i++)

     {


     if (h1.output[i] == patrn1[i])

          cout<<"\n pattern= "<

          "  output = "<


Download 1,14 Mb.

Do'stlaringiz bilan baham:
1   ...   70   71   72   73   74   75   76   77   ...   443




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish