All Things Techie With Huge, Unstructured, Intuitive Leaps
Showing posts with label fuzzy logic. Show all posts
Showing posts with label fuzzy logic. Show all posts

Fuzzy Logic, "Ish" values, Java

I previously wrote about an "ish" function ( which can be read HERE ) , that describes the need for a fuzzificator that identifies things from incomplete or incorrect knowledge. Humans are excellent at doing this in some sort of neural pattern recognition. In my "ish" function article, I made the case that it was needed to crack a code that the FBI was working on and asking for the public's help.

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;
}

}

Solving The "ish" Function

Quick question: "What is sort of like a dog, belongs to the dog family, has the features of a dog, sort of looks like a dog, but isn't really a dog, but is real "dog-ish"? Can you pick out the answer in the photo below?


What the human brain is very good at, is pattern recognition, or in pseudo techno talk, solving the "ish" function. Our minds can make huge intuitive leaps on very little information. We correctly surmise a correct conclusion from imperfect clues. It serves us well in the real world, because that is a necessity in many situations, including survival situations.

Computers are not so good at the "ish" function. We carbon units have neural nets that are superb at pattern recognition. When you are reading these words, your are not constructing them in your head from the assemblage of letters, rather your brain is instantly recognizing the pattern of the word. That is why you can udenrtnasd tihs snetncee if jsut the frsit and lsat ltetres are itnact.

What got me thinking about the ish function is in the following photo below (click on it for a larger image):

This comes from the actual FBI website. It is a code that they have been trying to crack for 10 years and have failed. Finally they put it up on their website and they are asking the publics's help to solve the puzzle. The URL is http://www.fbi.gov/news/stories/2011/march/cryptanalysis_032911

The back story is that a man was murdered and the only thing in his pocket, were two pages of writing written in some sort of code. The best codebreakers in the world have been toiling for 10 years trying to break this code. After putting up the story on their website, they have gotten over 2,000 tips and comments, including one from me.

What I did, was let my own ish circuits process the code. A couple of things jumped out at me. There are repetitions, but I don't think this is cryptography. Cryptography is where you substitute one letter for another, for example an E would be substituted with a J and L would be substitued with a Z. In this way the word "eel" would be written as JJZ.

Rather, I think this is shorthand, where just a few letters represent the whole word. And my contention is that this is bookie shorthand. For example, one can see the word "CBET". Everyone knows that a C note is a 100, so a CBET is code for a hundred dollar bet. You can also make out "TOTE". A tote bet is for win, place or show on horse race.

So this note would be eminently solvable quickly with a built-in ish function in an operating system. One would give the ish function a glossary of betting terms, and the computer would spew out the solutions. One quick ish function that my brain did, was assign the sequence "NCBE" as a Nickel Bet or a $500 bet.

To write an ish function is harder than it looks. Let's suppose that you had to pick out the word GLANDULAR from this sequence FRGGNGBIGGLNDLREGO. There are no white spaces to help you out. What you have to do in general terms is to first look for the general wildcard symbol G*R. In this case it would return 5 possibilities, and then you have have to eliminate the ones that didn't fit. The human brain doesn't have much trouble seeing NiCkelBEt in NCBE, but the ish function would require a lot of flops to tentatively figure it out.

However the ish function would be mighty handy. It would greatly improve OCR or optical character recognition. It would include ROM or Rough Order of Magnitude. When you and I are working on a problem, and our frame of reference tells us that the possible range of answers lie say between 46 and 59, if we get an answer close to that range, we know that we are on the right track.

In the old days, computers were assigned tasks to determine exact values. Quantum physics and fuzzy logic has shown us the shortcomings of exact values. The human brain doesn't operate with exact values, and if we want computers to emulate the human brain, then we need a real good ish function for words, math, pictures, images, meanings and memes. This list isn't comprehensive, but it is ish!