037 043 3SPZ7HTNYH5UO63HV2ERWHWQOHU6YWKSCGW6DUQ




C++ Neural Networks and Fuzzy Logic:A Look at Fuzzy Logic
LYCOShop Now Open! function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);           Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive




To access the contents, click the chapter and section titles.


C++ Neural Networks and Fuzzy Logic


(Publisher: IDG Books Worldwide, Inc.)

Author(s): Valluru B. Rao

ISBN: 1558515526

Publication Date: 06/01/95










Search this book:
 





















Previous
Table of Contents
Next




Let’s look at the implementation file in Listing 3.2.

Listing 3.2 fuzzfier.cpp


// fuzzfier.cpp V. Rao, H. Rao
// program to fuzzify data

#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <fuzzfier.h>

void category::setname(char *n)
{
strcpy(name,n);
}

char * category::getname()
{
return name;
}

void category::setval(float &h, float &m, float &l)
{
highval=h;
midval=m;
lowval=l;
}

float category::getlowval()
{
return lowval;
}

float category::getmidval()
{
return midval;
}

float category::gethighval()
{
return highval;
}

float category::getshare(const float & input)
{
// this member function returns the relative membership
// of an input in a category, with a maximum of 1.0

float output;
float midlow, highmid;

midlow=midval-lowval;
highmid=highval-midval;

// if outside the range, then output=0
if ((input <= lowval) || (input >= highval))
output=0;

else
{

if (input > midval)

output=(highval-input)/highmid;

else

if (input==midval)

output=1.0;

else

output=(input-lowval)/midlow;

}
return output;

}

int randomnum(int maxval)
{
// random number generator
// will return an integer up to maxval

srand ((unsigned)time(NULL));
return rand() % maxval;
}

void main()
{
// a fuzzifier program that takes category information:
// lowval, midval and highval and category name
// and fuzzifies an input based on
// the total number of categories and the membership
// in each category

int i=0,j=0,numcat=0,randnum;
float l,m,h, inval=1.0;

char input[30]=" ";
category * ptr[10];
float relprob[10];
float total=0, runtotal=0;

//input the category information; terminate with `done';

while (1)

{

cout << "\nPlease type in a category name, e.g. Cool\n";
cout << "Enter one word without spaces\n";
cout << "When you are done, type `done' :\n\n";

ptr[i]= new category;
cin >> input;

if ((input[0]=='d' && input[1]=='o' &&
input[2]=='n' && input[3]=='e')) break;

ptr[i]->setname(input);

cout << "\nType in the lowval, midval and highval\n";
cout << "for each category, separated by spaces\n";
cout << " e.g. 1.0 3.0 5.0 :\n\n";

cin >> l >> m >> h;
ptr[i]->setval(h,m,l);

i++;

}

numcat=i; // number of categories

// Categories set up: Now input the data to fuzzify
cout <<"\n\n";
cout << "===================================\n";
cout << "==Fuzzifier is ready for data==\n";
cout << "===================================\n";

while (1)

{
cout << "\ninput a data value, type 0 to terminate\n";

cin >> inval;

if (inval == 0) break;

// calculate relative probabilities of
// input being in each category

total=0;
for (j=0;j<numcat;j++)
{
relprob[j]=100*ptr[j]->getshare(inval);
total+=relprob[j];
}

if (total==0)
{
cout << "data out of range\n";
exit(1);
}

randnum=randomnum((int)total);

j=0;
runtotal=relprob[0];

while ((runtotal<randnum)&&(j<numcat))
{
j++;
runtotal += relprob[j];
}

cout << "\nOutput fuzzy category is ==> " <<
ptr[j]->getname()<<"<== \n";

cout <<"category\t"<<"membership\n";
cout <<"---------------\n";

for (j=0;j<numcat;j++)
{
cout << ptr[j]->getname()<<"\t\t"<<
(relprob[j]/total) <<"\n";
}

}

cout << "\n\nAll done. Have a fuzzy day !\n";

}


This program first sets up all the categories you define. These could be for the example we choose or any example you can think of. After the categories are defined, you can start entering data to be fuzzified. As you enter data you see the probability aspect come into play. If you enter the same value twice, you may end up with different categories! You will see sample output shortly, but first a technical note on how the weighted probabilities are set up. The best way to explain it is with an example. Suppose that you have defined three categories, A, B, and C. Suppose that category A has a relative membership of 0.8, category B of 0.4, and category C of 0.2. In the program, these numbers are first multiplied by 100, so you end up with A=80, B=40, and C=20. Now these are stored in a vector with an index j initialized to point to the first category. Let’s say that these three numbers represent three adjacent number bins that are joined together. Now pick a random number to index into the bin that has its maximum value of (80+40+20). If the number is 100, then it is greater than 80 and less than (80+40), you end up in the second bin that represents B. Does this scheme give you weighted probabilities? Yes it does, since the size of the bin (given a uniform distribution of random indexes into it) determines the probability of falling into the bin. Therefore, the probability of falling into bin A is 80/(80+40+20).



Previous
Table of Contents
Next






Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.



Wyszukiwarka

Podobne podstrony:
043 Dolina Zaginionych Kobiet
03 0000 037 02 Leczenie dzieci z zespolem Prader Willi hormonem wzrostu
037 Vijeo Look?talogue
v 01 043
043 Jaki stosunek do nauk ścisłych głosił renesans
037 kras artykul
v 04 043
FX1000 037 00
041 043
037 Iwan Groźny
v 04 037
037 06
037 03

więcej podobnych podstron