<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Snake</title>
<style>
body { font-familly : tahoma,verdana, sanserif; }
.container {
width: 810px;
margin: 0 auto;
}
.header, .body { width 800px;
padding : 1em;
float: left;
border: 1px solid #888;
}
.footer {width:800px;
font-size:80%;
background-color:#ccc;
border: 1px solid #888;
float: left;
margin-right: 10px;
}
.span-6,.span-12 {
float: left;
margin-right: 10px;
}
.span-6 {width: 230px;}
.span-12 {width: 470px;}
.last { margin-right: 0; }
.margin-top { margin-top : 20px; }
</style>
<script type="text/javascript" src="fuzzy-logic-class.js"></script>
<script type="text/javascript">
var calculate = function() {
var F = new FuzzyLogic();
F.clearMembers();
F.setInputNames(['age','tol']);
F.addMember('age','young', 0, 20, 45 ,LINFINITY);
F.addMember('age','middle' , 20, 45, 70 ,TRIANGLE);
F.addMember('age','old' , 45, 70, 100,RINFINITY);
F.addMember('tol','low', 0, 20, 50 ,LINFINITY);
F.addMember('tol','mod' , 20, 50, 80 ,TRIANGLE);
F.addMember('tol','hgh' , 50, 80, 100,RINFINITY);
F.setOutputNames(['sav','inc','grv']);
F.addMember('sav','low_sav', 0, 20, 50 ,LINFINITY);
F.addMember('sav','mid_sav' , 20, 50, 80 ,TRIANGLE);
F.addMember('sav','hgh_sav' , 50, 80, 100,RINFINITY);
F.addMember('inc','low_inc', 0, 20, 50 ,LINFINITY);
F.addMember('inc','mid_inc' , 20, 50, 80 ,TRIANGLE);
F.addMember('inc','hgh_inc' , 50, 80, 100,RINFINITY);
F.addMember('grv','low_grv', 0, 20, 50 ,LINFINITY);
F.addMember('grv','mid_grv' , 20, 50, 80 ,TRIANGLE);
F.addMember('grv','hgh_grv' , 50, 80, 100,RINFINITY);
F.clearRules();
F.addRule('IF age.young AND tol.low THEN sav.mid_sav');
F.addRule('IF age.young AND tol.mod THEN sav.low_sav');
F.addRule('IF age.young AND tol.hgh THEN sav.low_sav');
F.addRule('IF age.middle AND tol.low THEN sav.mid_sav');
F.addRule('IF age.middle AND tol.mod THEN sav.low_sav');
F.addRule('IF age.middle AND tol.hgh THEN sav.low_sav');
F.addRule('IF age.old AND tol.low THEN sav.hgh_sav');
F.addRule('IF age.old AND tol.mod THEN sav.mid_sav');
F.addRule('IF age.old AND tol.hgh THEN sav.mid_sav');
// -------------------
F.addRule('IF age.young AND tol.low THEN inc.mid_inc');
F.addRule('IF age.young AND tol.mod THEN inc.mid_inc');
F.addRule('IF age.young AND tol.hgh THEN inc.low_inc');
F.addRule('IF age.middle AND tol.low THEN inc.hgh_inc');
F.addRule('IF age.middle AND tol.mod THEN inc.hgh_inc');
F.addRule('IF age.middle AND tol.hgh THEN inc.mid_inc');
F.addRule('IF age.old AND tol.low THEN inc.hgh_inc');
F.addRule('IF age.old AND tol.mod THEN inc.hgh_inc');
F.addRule('IF age.old AND tol.hgh THEN inc.mid_inc');
// -------------------
F.addRule('IF age.young AND tol.low THEN grv.mid_grv');
F.addRule('IF age.young AND tol.mod THEN grv.hgh_grv');
F.addRule('IF age.young AND tol.hgh THEN grv.hgh_grv');
F.addRule('IF age.middle AND tol.low THEN grv.low_grv');
F.addRule('IF age.middle AND tol.mod THEN grv.mid_grv');
F.addRule('IF age.middle AND tol.hgh THEN grv.hgh_grv');
F.addRule('IF age.old AND tol.low THEN grv.low_grv');
F.addRule('IF age.old AND tol.mod THEN grv.low_grv');
F.addRule('IF age.old AND tol.hgh THEN grv.mid_grv');
var pf = document.getElementById('age').value;
var ps = document.getElementById('rtol').value;
F.setRealInput('age' , pf );
F.setRealInput('tol' , ps );
var fuzzy_arr = F.calcFuzzy();
var setStyle = function(id,styleProp, value) {
var elm = document.getElementById(id);
elm.style[styleProp]=value;
}
var getStyle = function(id,styleProp) {
var elm = document.getElementById(id);
if (elm.currentStyle)
var y = elm.currentStyle[styleProp];
else if (window.getComputedStyle)
var y = document.defaultView.getComputedStyle(elm,null).getPropertyValue(styleProp);
return y;
}
var barWidth = parseInt(getStyle('inc','width'));
var incValue = Math.ceil(fuzzy_arr['inc'] * barWidth /100);
setStyle('inc-bar','width',incValue+'px');
var savValue = Math.ceil(fuzzy_arr['sav'] * barWidth /100);
setStyle('sav-bar','width',savValue+'px');
var grvValue = Math.ceil(fuzzy_arr['grv'] * barWidth /100);
setStyle('grv-bar','width',grvValue+'px');
document.getElementById('sav-txt').innerHTML = 'Savings : '+(fuzzy_arr['sav']).toFixed(2);
document.getElementById('inc-txt').innerHTML = 'Income : '+(fuzzy_arr['inc']).toFixed(2);
document.getElementById('grv-txt').innerHTML = 'Grovth : '+(fuzzy_arr['grv']).toFixed(2);
};
var upValue = function(id) {
elm=document.getElementById(id);
elm.value++;
calculate();
}
var dnValue = function(id) {
elm=document.getElementById(id);
elm.value--;
calculate();
}
</script>
</head>
<body>
<div class="container">
<h3> Example from book : <br />Fuzzy Logic for Business, Finance, and
Management</h3>
<div class="header">
<p>
Financial service organizations have developed various advisory investment models for clients based on age and risk tolerance. The objective is to advice clients how to allocate portions of their investments across the three main asset types: savings, income, and growth (asset allocation). The concepts age and risk tolerance are measured on suitable scales. Age is partitioned into three groups, for instance young (< 30 years), middle age (between 30 and 60 years), and old (> 60 years). The risk tolerance is partitioned on a psychometric scale from 0 to 100 into low (<= 30), moderate (between 30 and 70), and high (<= 70). A questionary filled by the client help fnancial experts to determine his/her risk tolerance group (low, moderate, or high). Knowing the client's age and risk tolerance group and using results from previous studies presented.<p>
<p> In tables and charts, the financial experts are in a position to advise a client how to allocate money into savings, income, and growth. A defciency in this model is that a person 31 years old is middle age as well as a person who is 45 years old. All ages in the interval [31; 59] have the same status; they equally qualify to be middle age; there is no
gradation level of belonging to the interval. The same is valid for those who are young and old. Similar difficulty arises with the notion of risk tolerance. Classical (crisp) models of this type can be improved by using FLC methodology. This is illustrated in the following case study.
</p>
<p>
<fieldset>
<legend>Client Asset Allocation Model</legend>
<p><label for="age" class="span-6"> Client Age :</label><input class="span-6" style="left:200px" type="text" id="age" name="age" value="40" /><input type="button" value=" + " onclick="upValue('age');" /><input type="button" value=" - " onclick="dnValue('age');" /><br /></p>
<p><label for="rtol" class="span-6"> Risk tolerance :</label><input class="span-6" style="left:200px" type="text" id="rtol" name="rtol" value="50" /><input type="button" value=" + " onclick="upValue('rtol');" /><input type="button" value=" - " onclick="dnValue('rtol');" /><br /></p>
<p>
<input type="button" name="calc" id="calc" value="Asset allocation portions of their investments as (savings, income, and growth)" onclick="return calculate();"/><br /></p>
</fieldset>
</p>
<p>
<h4>Asset allocation portions of their investments as (savings, income, and growth) :</h4></p>
<div id="sav-txt" class="span-12 last">Savings :</div>
<div class="span-12 last" id="sav" style="height:22px;border: 1px solid #000;;text-align:center;">
<div id="sav-bar" style="width: 0px;height:18px;margin:1px;background-color:red;border: 1px solid #000"></div>
</div>
<div class="span-12 last" id="inc-txt">Income :</div>
<div class="span-12 last" id="inc" style="height:22px;border: 1px solid #000;;text-align:center;">
<div id="inc-bar" style="width: 0px;height:18px;margin:1px;background-color:red;border: 1px solid #000"></div>
</div>
<div id="grv-txt" class="span-12 last">Growth :</div>
<div class="span-12 last" id="grv" style="height:22px;border: 1px solid #000;;text-align:center;">
<div id="grv-bar" style="width: 0px;height:18px;margin:1px;background-color:red;border: 1px solid #000"></div>
</div>
<div class="footer last margin-top">copyright 2011 by Wojtek Jarzęcki <script language="javascript">
<!--
var part1 = "lottocad";
var part2 = "gmail.com?subject=javascript fuzzy logic";
var part3 = "email";
document.write('<a href="mai' + 'lto:' + part1 + '@' + part2 + '">');
document.write(part3 + '</a>');
// -->
</script> </div>
</div>
</div>
</body>
</html> |