Little did I realize that I would need an "ish" function or a fuzzy value function shortly in my work. I am writing software that processes health surveys sent by smart phone to identify persons that need immediate care in a Third World country. The way this is done, is by sending people out using a survey tool that asks questions which identifies risk signs. There are many different types of surveys, and the only way to classify what comes in over GPRS or HTTP, is the XML document with the survey answers. I parse the document, and identify the type of survey by the number of answers.
However this method is not foolproof, because the tool lets the interviewer skip an answer. At this point, my survey classifier throws an exception because it cannot determine the type of survey. However each type of survey has a significant difference in the number of answers, so a fuzzificator would work well here. For example, one particular survey has 12 answers, the next has 25 and the next has 64, so making a fuzzy logic class to determine the type of survey is quite easy. I just give the exact answer a range, and if it falls into that range, then I know what type of survey it is.
Right now, my fuzzy value function works only on integers. It works on an actual difference or a percentage difference. The values are hard coded but the code could be modified to get the values from a config file or a database.
I see this function extended to strings, doubles, floats and indeed anything you want. In addition, once you have the fuzzificator, one can make the same thing for logic types, for example Boolean algebra. One could have a fuzzy AND gate where there are many inputs, and if one or two is out, a decision still could be made. And if one combines the decision making with Bayesian inference, or probabilities, then one has a truly useful tool for complex fuzzy logic.
Here is the prototype source code in Java:
package org.FuzzyLogic;
public class FuzzyValues {
static final int PLUS_MINUS_VALUE_INT = 1;
static final double PLUS_MINUS_VALUE_INT_PERCENT = 0.09;
static final int expectedInput = 12;
public static boolean fuzzyInt(int actualInput) {
boolean fuzzy = ((expectedInput-PLUS_MINUS_VALUE_INT) <= actualInput) && (actualInput <= (expectedInput+PLUS_MINUS_VALUE_INT ));
return fuzzy;
}
public static boolean intPercentMatch(int input) {
double minus_percent_value = expectedInput * (1 + PLUS_MINUS_VALUE_INT_PERCENT);
double plus_percent_value = expectedInput * (1 - PLUS_MINUS_VALUE_INT_PERCENT);
boolean fuzzy = (minus_percent_value <= input)&& (plus_percent_value >= input);
return fuzzy;
}
public static boolean isFuzzyIntValue(int input)
{
boolean success = fuzzyInt(input);
return success;
}
public static boolean isFuzzyIntPercent(int input)
{
boolean success = intPercentMatch(input);
return success;
}
}
No comments:
Post a Comment