GNUstepWiki - New pages [en]2018-06-20T17:45:14ZFrom GNUstepWikiMediaWiki 1.5.1Gnustep-fuzzy2014-12-16T13:08:30Z2014-12-16T13:08:302014-12-16T13:08:30Z<p>Summary: </p>
<hr />
<div><b>This is a proposal for an approach that is not yet part of GNUstep though there is source code</b><br />
<!--{{stub}}--><br />
<br />
{{Application|<br />
<br />
shortdescription = AI library for rendering GNUstep. |<br />
<br />
currentversion = [[Image:Gnustep-fuzzy-0.2.tar.gz|0.2]]|<br />
<br />
releasedate = 2014-12-21 |<br />
<br />
license = LGPL GPL |<br />
<br />
overview = Gnustep-fuzzy is a library for decision tree and fuzzy logic in GNUstep applications.<br />
<br />
== Description ==<br />
<br />
Gnustep-fuzzy is a library for updating the renderer with fuzzy logic and decision tree code. It will try to update the renderer of QuartzCore or CoreAnimation and CoreGraphics later on. It can also be used stand-alone for GNUstep games writing as simple AI engine.<br />
It is written in portable Objective-C with no dependencies except gnustep-base.<br />
== Links ==<br />
<br />
Feedback and response can be sent later on when the library is developed further.<br />
<br />
The main development site is at [http://github.com/enrytheermit/gnustep.git github] and here is a [[Image:Gnustep-fuzzy-0.2.tar.gz|0.2 development release tarball]]|<br />
<br />
features = fuzzy logic and decision tree inferer |<br />
<br />
maintainer = `Enry the `Ermit |<br />
<br />
relatedlinks = <br />
* [[Fuzzy]] Documentation of the library with explanations about the AI on this wiki<br />
* [https://github.com/enrytheermit/gnustep/tree/master/gnustep-fuzzy gnustep-fuzzy at github]|<br />
<br />
category = [[Category:Libraries]]<br />
}}</div>Bubble.roguefoobarFuzzy2014-12-16T09:42:46Z2014-12-16T09:42:462014-12-16T09:42:46Z<p>Summary: </p>
<hr />
<div><b>This is a proposal for an approach that is not yet part of GNUstep though there is source code</b><br />
<br />
This page is for GNUstep developers. It explains the Fuzzy Logic system from the gnustep-fuzzy library for e.g. updating the GNUstep System such as drawing to screen. See the references immediately if you do not know anything about fuzzy logic systems. You should concur that you understand fuzzy logic before reading anything else on this page. Source code is provided at the bottom of the page.<br />
<br />
<h2>What is Fuzzy Logic ?</h2><br />
<br />
A fuzzy system is a rule-based systems with inputs and outputs. Each fuzzy rule is associated with a mathematical function. The system is a greedy decision tree algorithm. The rules of a fuzzy system are more random than a decision tree so that it is faster. A decision tree traverses at O(log(n)), the depth of the tree and O(n*log(n)) for a n-ary tree approximately. <br />
<br />
[[Image:300px-Fuzzy_logic_temperature_en.svg.png | Figure 1.1]]<br />
<br />
The image displays the fuzzy logic function value increasing with temperature which is a linear algebraic function system. Values overlap here and there (see the color of the lines), this is where the name fuzzy comes from A function for cold would be f(x), for warm f(x*x) and for hot f(x*x*x). as f(X) increases the return value increases as does the temperature. Another solution would be to have the return value of a temperature fuzzy logic function increasing with temperature.<br />
<br />
As the name fuzzy suggests it uses more general information systems. The functions of the fuzzy logic are most important. For example "extremely" associates with the value x * x * x where x is a floating point number. "a little bit" is associated with sqrt(x) / 1.3 and so on. The fuzzy rules are parsed in succession and yield a value for each natural language word. Thus you can reason as a human what the fuzzy logic should do after a fuzzy function is successful e.g. against some threshold, if x=0 then the "extremely" function i 0 * 0 * 0 = 0 and is smaller than threshold 0.001. The threshold is from Artificial Neural Networks for calculating success of the extremum sought by the network.<br />
<br />
<h2>Fuzzy Networks</h2><br />
<br />
If you implement all rules in a seperate graph node you can reason your way around a graph.<br />
<br />
<h2>Distributed fuzzy networks</h2><br />
<br />
The same as a fuzzy network but with a node for each fuzzy logic set or system of nodes of a fuzzy network. <br />
<br />
<h2>Inference engines</h2><br />
<br />
Inference engines infere rules based on logic such as reasoning with not, and, or and combinations of these logical comparators. You can negate rules and infere less rules this way.<br />
<br />
<h2>prolog</h2><br />
<br />
Prolog is a formal logic rule system which induces rules based on the logical input clauses and then reasons about them by parsing logic rules. You can ask the prolog interpreter questions about what he induced logically.<br />
<br />
<h2>progol</h2><br />
<br />
Progol inferes the most specicic clause by using a graph searching algorithm. It parses e.g. by negation so that input clauses can be ruled out. Progol deduces i.e. makes the most general logical assumptions.<br />
<br />
<h2>How does it apply to GNUstep ?</h2><br />
<br />
You can reason about what or how to draw to an X11/Xquartz window or GS subelement in the window such as a view, a button or a bitmap. You would use a fuzzy paint node which is in a distributed node system. If you switch nodes you either paint or wait (for example with an idle node) or reason (e.g. with an interrupt you must redraw your app screen) and so on. e.g. a mouse node would reason if you are about to click a button and access the region the mouse is in to reason further about what the painting algorithm of the window or rootwindow should do.<br />
<br />
===gnustep-fuzzy===<br />
<br />
gnustep-fuzzy uses a paint node which reasons about when it should paint. It can idle for seconds (or milliseconds) if you like and inferes the rules of the paint node this way. There is a fuzzy function associated with each rule string and a rule associated with a drawing function e.g. paintOn: or paintIdle1Second:. This system can be further distributed from a fuzzy set to a fuzzy node for each rule.<br />
<br />
<h2>rule system code example</h2><br />
<br />
This is portable C and Objective-C :<br />
<br />
<pre><br />
void makePaintRules(OpalFuzzyPaintRuleSystem* sys)<br />
// sys is a node with a fuzzy set (or network in it)<br />
{<br />
/*<br />
sys contains a canvas called _painter and adds here a rule<br />
which redraws the screen, this method is paintOn: with the<br />
canvas as an argument. There are 3 adapters inside sys : self, painter and parser<br />
*/<br />
[sys addRule:"paint extremely fast" : paintOn:];<br />
<br />
/* <br />
f is a functor object which contains the "extremely" reasoning fuzzy function, implemented as <br />
return (x*x*x); where x is initialized to 0.0 thereunder. You change the x not the threshold <br />
in sys, so if you have a threshold of 0.001, f(x)==0 < threshold, and the rule gets matched <br />
by sys. The fuzzy parser of rules is now still simple. I mean the non-fuzzy function part.<br />
*/<br />
OpalFuzzyFunction *f = [OpalFuzzyFunctionExtremely new];<br />
[f x:.0];<br />
[sys addFunction:"paint extremely" : f];<br />
/* here's the same thing the paint thread of e.g. Xquartz event handling sleeps for 1 second */<br />
[sys addRule:"paint not for 1 second" : paintIdle1SecondOn:];<br />
f = [OpalFuzzyFunctionIdle new];<br />
[f x:.0];<br />
[sys addFunction:"paint not for 1 second" : f];<br />
}<br />
</pre><br />
You can change the fuzzy function parameter so that the threshold should not change.<br />
<br />
The threading model of this code is multi-threaded so e.g. drawing to screen happens with interrupts and is managed by a threadpool object which alters the state of your GS windows. Threads can be used to let the fuzzy set parse and change nodes when doing other stuff.<br />
<br />
<h2>gnustep-fuzzy API</h2><br />
<br />
There are three adapters (manipulators) for a rulesystem as used in the above C function. A rulesystem, painter and parser instance wrapper. These can combine the full features with rulesystem parse methods such as the PaintRuleSystem class:<br />
<br />
OpalFuzzyRuleSystem API :<br />
<hr><br />
<pre><br />
@interface OpalFuzzyRuleSystem : NSObject<br />
{<br />
CGFloat _threshold;<br />
<br />
// this is a dictionary with rule-paint method key-value pairs<br />
OpalFuzzyDB *_rules;<br />
// this is a dictionary with rule-fuzzy logic function key-value pairs<br />
OpalFuzzyDB *_functions;<br />
}<br />
<br />
// parseFor:On: calls match:On:<br />
-(void) parseFor:(OpalFuzzyPredicate*)predicate On:(id)o;<br />
// On: is the painting system i.e. where you draw on. preficate gets matched against the rules.<br />
- (id) match:(OpalFuzzyPredicate*)predicate On:(id)o;<br />
<br />
// These are base class adapters :<br />
- (id) createManipulator;<br />
- (id) createArgumentManipulator;<br />
- (id) createParserManipulator;<br />
</pre><br />
<hr><br />
<br />
OpalFuzzyPaintRuleSystem API :<br />
<br />
private _painter and _parser variables where the painter is something to paint or draw on, the parser is the paint rulesystem parser and belongs in a OpalFuzzyNode, which itself is a distributed node for painting or paint node.<br />
<br />
Here is the interface :<br />
<hr><br />
<pre><br />
// painter and parser private variable get/set<br />
- (id) new:(id)painter withParser:(id)parser;<br />
- (void)setPaintSystem:(id)paintsystem;<br />
- (id)painter;<br />
- (void)setParser:(id)parser;<br />
- (id)parser;<br />
<br />
// this is for painting on itself, it is not used<br />
- (void)paintOn;<br />
<br />
// this paints on the painter adapter<br />
- (void)paintOn:(id)painter;<br />
<br />
// this idles updating with painting/drawing<br />
- (void)paintIdle1SecondOn:(id)painter;<br />
<br />
// this is the general predicate variable mathching then drawing on id o :<br />
- (id) match:(OpalFuzzyPredicate*)predicate On:(id)o;<br />
<br />
/* The following is from the code itself :<br />
* NOTE :<br />
* Call the createManipulator method and you can paint on this<br />
* painter system with rules from the super class.<br />
<br />
* The PaintManipulator then hashes the method paintOn: in the dictionary<br />
* and paints on the _painter of the dispatched class due to a call<br />
* of e.g. parseFor:"paint extremely". parseFor is in the super class and has On: for the <br />
* the painter/canvas system to draw on. It gets passed to the match:On: method above.<br />
*<br />
* The super class parseFor:On: method can also be used as a rule (rules have<br />
* a NSString key and a SEL in the form of performSelector:withObject:, so<br />
* only a single argument in e.g. parseForOn: implemented with the API.<br />
* Manipulator stands for adapter or wrapper design patterns.<br />
*/<br />
- (id) createManipulator;<br />
- (id) createArgumentManipulator;<br />
- (id) createParserManipulator;<br />
</pre><br />
<hr><br />
<br />
<h2>references</h2><br />
<br />
====external links====<br />
<br />
* [http://en.wikipedia.org/wiki/Information_Fuzzy_Networks wikipedia page on Fuzzy Networks]<br />
* [http://en.wikipedia.org/wiki/Fuzzy_logic wikipedia page on Fuzzy Logic]<br />
<br />
====source code====<br />
[[Image:Gnustep-fuzzy-0.2.tar.gz|gnustep-fuzzy tarball version 0.2+]]<br />
<br />
====author====<br />
`Enry the `Ermit <goon at yellowcouch dot org></div>Bubble.roguefoobar