[jboss-svn-commits] JBL Code SVN: r21600 - in labs/jbossrules/branches/uncDrools5x: LogicSOM and 14 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Aug 18 08:12:30 EDT 2008
Author: dsotty
Date: 2008-08-18 08:12:30 -0400 (Mon, 18 Aug 2008)
New Revision: 21600
Added:
labs/jbossrules/branches/uncDrools5x/LogicSOM/
labs/jbossrules/branches/uncDrools5x/LogicSOM/.classpath
labs/jbossrules/branches/uncDrools5x/LogicSOM/.project
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/DroolSOM$1.class
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/DroolSOM$2.class
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/DroolSOM.class
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/LogicSOM08$1.class
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/LogicSOM08$2.class
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/LogicSOM08.class
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/SOM.drl
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/Train.class
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/data/
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/data/Acknowledge.class
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/data/Neuron.class
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/data/Point2Dim.class
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/data/Sample.class
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/evaluators/
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/evaluators/NearEvaluatorDefinition$NearEvaluator.class
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/evaluators/NearEvaluatorDefinition.class
labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/som.packagebuilder.conf
labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/
labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/Jama-1.0.2.jar
labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/VisualNumerics.jar
labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/gluegen-rt.jar
labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/jgeom-core_beta.jar
labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/jogl.jar
labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/libgluegen-rt.so
labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/libjogl.so
labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/libjogl_awt.so
labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/libjogl_cg.so
labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/vecmath.jar
labs/jbossrules/branches/uncDrools5x/LogicSOM/log.log
labs/jbossrules/branches/uncDrools5x/LogicSOM/logSOM.txt
labs/jbossrules/branches/uncDrools5x/LogicSOM/native/
labs/jbossrules/branches/uncDrools5x/LogicSOM/native/jogl.dll
labs/jbossrules/branches/uncDrools5x/LogicSOM/native/jogl_awt.dll
labs/jbossrules/branches/uncDrools5x/LogicSOM/native/jogl_cg.dll
labs/jbossrules/branches/uncDrools5x/LogicSOM/oxDur2.txt
labs/jbossrules/branches/uncDrools5x/LogicSOM/oxDuration.txt
labs/jbossrules/branches/uncDrools5x/LogicSOM/rbfinterp.jar
labs/jbossrules/branches/uncDrools5x/LogicSOM/src/
labs/jbossrules/branches/uncDrools5x/LogicSOM/src/DroolSOM.java
labs/jbossrules/branches/uncDrools5x/LogicSOM/src/LogicSOM08.java
labs/jbossrules/branches/uncDrools5x/LogicSOM/src/SOM.drl
labs/jbossrules/branches/uncDrools5x/LogicSOM/src/Train.java
labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/
labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Acknowledge.java
labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Neuron.java
labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Point2Dim.java
labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Sample.java
labs/jbossrules/branches/uncDrools5x/LogicSOM/src/evaluators/
labs/jbossrules/branches/uncDrools5x/LogicSOM/src/evaluators/NearEvaluatorDefinition.java
labs/jbossrules/branches/uncDrools5x/LogicSOM/src/som.packagebuilder.conf
Modified:
labs/jbossrules/branches/uncDrools5x/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
labs/jbossrules/branches/uncDrools5x/drools-compiler/src/test/java/org/drools/testframework/RuleCoverageListenerTest.java
labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/common/AgendaItem.java
labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/spi/Activation.java
labs/jbossrules/branches/uncDrools5x/drools-core/src/test/java/org/drools/util/BaseQueueable.java
Log:
New branch for uncertainty support in 5.x
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/.classpath
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/.classpath (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/.classpath 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/Essence"/>
+ <classpathentry kind="lib" path="lib/jogl.jar">
+ <attributes>
+ <attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="LogicSOM/lib"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="lib" path="lib/gluegen-rt.jar">
+ <attributes>
+ <attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="LogicSOM/lib"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="lib" path="lib/jgeom-core_beta.jar"/>
+ <classpathentry kind="lib" path="lib/vecmath.jar"/>
+ <classpathentry kind="lib" path="lib/VisualNumerics.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/drools-compiler"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/drools-core"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/.project
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/.project (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/.project 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>LogicSOM</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/DroolSOM$1.class
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/DroolSOM$1.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/DroolSOM$2.class
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/DroolSOM$2.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/DroolSOM.class
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/DroolSOM.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/LogicSOM08$1.class
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/LogicSOM08$1.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/LogicSOM08$2.class
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/LogicSOM08$2.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/LogicSOM08.class
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/LogicSOM08.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/SOM.drl
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/SOM.drl (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/SOM.drl 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,71 @@
+#created on: 01-Aug-2008
+package test;
+
+#list any import classes here.
+
+import java.util.Hashtable;
+import uncertainty.truthvals.IUncertainDegree;
+import org.drools.rule.ConstraintSignature;
+import org.drools.rule.ClassConstraint;
+
+
+import data.Sample;
+import data.Neuron;
+import data.Acknowledge;
+
+
+#declare any global variables here
+
+global uncertainty.factory.IDegreeFactory factory;
+global org.drools.base.evaluators.EvaluatorRegistry registry;
+global java.io.PrintWriter logger;
+
+
+
+
+
+rule "Insert"
+
+ salience 9999
+
+
+ when
+ $p : Sample( )
+ then
+ logger.println("Asserted " + $p );
+
+end
+
+
+
+rule "Recall"
+
+ salience 1000
+
+
+ when
+ $p : Sample( )
+ $n : Neuron( position `near[0.45] $p.position )
+ then
+
+ logger.println("Neuron " + $n.getId() + " recalls point at degree "+ drools.getActivationDegree() );
+ Hashtable<ConstraintSignature, IUncertainDegree> priors = new Hashtable<ConstraintSignature, IUncertainDegree>();
+ priors.put(ClassConstraint.buildSignature(Acknowledge.class),drools.getActivationDegree());
+ insertLogical(new Acknowledge($n,$p),priors);
+end
+
+
+
+rule "Acknowledge"
+
+ salience 900
+
+
+ when
+ Train()
+ exists $ack : Acknowledge()
+ then
+ logger.println("Ack inserted at "+drools.getActivationDegree());
+ System.out.println("***********************************************++++++++++++++++++++++++++++++++****************************");
+end
+
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/Train.class
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/Train.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/data/Acknowledge.class
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/data/Acknowledge.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/data/Neuron.class
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/data/Neuron.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/data/Point2Dim.class
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/data/Point2Dim.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/data/Sample.class
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/data/Sample.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/evaluators/NearEvaluatorDefinition$NearEvaluator.class
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/evaluators/NearEvaluatorDefinition$NearEvaluator.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/evaluators/NearEvaluatorDefinition.class
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/evaluators/NearEvaluatorDefinition.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/som.packagebuilder.conf
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/som.packagebuilder.conf (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/bin/som.packagebuilder.conf 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,38 @@
+drools.dialect.default = java
+drools.dialect.java = org.drools.rule.builder.dialect.java.JavaDialectConfiguration
+drools.dialect.java.compiler = ECLIPSE
+
+drools.dialect.mvel = org.drools.rule.builder.dialect.mvel.MVELDialectConfiguration
+drools.dialect.mvel.strict = true
+drools.dialect.mvel.langLevel = 4
+
+drools.accumulate.function.average = org.drools.base.accumulators.AverageAccumulateFunction
+drools.accumulate.function.max = org.drools.base.accumulators.MaxAccumulateFunction
+drools.accumulate.function.min = org.drools.base.accumulators.MinAccumulateFunction
+drools.accumulate.function.count = org.drools.base.accumulators.CountAccumulateFunction
+drools.accumulate.function.sum = org.drools.base.accumulators.SumAccumulateFunction
+
+drools.evaluator.coincides = org.drools.base.evaluators.CoincidesEvaluatorDefinition
+drools.evaluator.before = org.drools.base.evaluators.BeforeEvaluatorDefinition
+drools.evaluator.after = org.drools.base.evaluators.AfterEvaluatorDefinition
+drools.evaluator.meets = org.drools.base.evaluators.MeetsEvaluatorDefinition
+drools.evaluator.metby = org.drools.base.evaluators.MetByEvaluatorDefinition
+drools.evaluator.overlaps = org.drools.base.evaluators.OverlapsEvaluatorDefinition
+drools.evaluator.overlappedby = org.drools.base.evaluators.OverlappedByEvaluatorDefinition
+drools.evaluator.during = org.drools.base.evaluators.DuringEvaluatorDefinition
+drools.evaluator.includes = org.drools.base.evaluators.IncludesEvaluatorDefinition
+drools.evaluator.starts = org.drools.base.evaluators.StartsEvaluatorDefinition
+drools.evaluator.startedby = org.drools.base.evaluators.StartedByEvaluatorDefinition
+drools.evaluator.finishes = org.drools.base.evaluators.FinishesEvaluatorDefinition
+drools.evaluator.finishedby = org.drools.base.evaluators.FinishedByEvaluatorDefinition
+drools.evaluator.equality = org.drools.base.evaluators.EqualityEvaluatorsDefinition
+drools.evaluator.comparable = org.drools.base.evaluators.ComparableEvaluatorsDefinition
+drools.evaluator.set = org.drools.base.evaluators.SetEvaluatorsDefinition
+drools.evaluator.matches = org.drools.base.evaluators.MatchesEvaluatorsDefinition
+drools.evaluator.soundslike = org.drools.base.evaluators.SoundslikeEvaluatorsDefinition
+
+drools.evaluator.young = org.drools.base.evaluators.YoungEvaluatorDefinition
+drools.evaluator.heavy = org.drools.base.evaluators.HeavyEvaluatorDefinition
+drools.evaluator.nearly = org.drools.base.evaluators.NearlyEvaluatorDefinition
+drools.evaluator.near = evaluators.NearEvaluatorDefinition
+
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/Jama-1.0.2.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/Jama-1.0.2.jar
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/VisualNumerics.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/VisualNumerics.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/gluegen-rt.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/gluegen-rt.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/jgeom-core_beta.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/jgeom-core_beta.jar
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/jogl.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/jogl.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/libgluegen-rt.so
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/libgluegen-rt.so
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/libjogl.so
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/libjogl.so
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/libjogl_awt.so
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/libjogl_awt.so
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/libjogl_cg.so
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/libjogl_cg.so
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/vecmath.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/lib/vecmath.jar
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/log.log
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/log.log (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/log.log 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1 @@
+<object-stream>
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/logSOM.txt
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/logSOM.txt (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/logSOM.txt 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,26 @@
+Asserted Point at [0.1911380389195778 ; 0.3860345022419014]
+Neuron 3 recalls point at degree 78%
+Neuron 2 recalls point at degree 55%
+Neuron 1 recalls point at degree 54%
+Ack inserted at 78%
+Asserted Point at [0.7994969849224257 ; 0.5292688209832086]
+Neuron 5 recalls point at degree 63%
+Neuron 4 recalls point at degree 74%
+Neuron 0 recalls point at degree 80%
+Ack inserted at 80%
+Asserted Point at [0.6278293747100708 ; 0.11656753917059243]
+Neuron 8 recalls point at degree 70%
+Ack inserted at 70%
+Asserted Point at [0.2087127955091438 ; 0.5634838324346664]
+Neuron 7 recalls point at degree 67%
+Neuron 3 recalls point at degree 77%
+Neuron 2 recalls point at degree 79%
+Neuron 1 recalls point at degree 62%
+Ack inserted at 79%
+Asserted Point at [0.9136950078609032 ; 0.7934950374860625]
+Neuron 5 recalls point at degree 59%
+Neuron 4 recalls point at degree 57%
+Ack inserted at 59%
+Asserted Point at [0.018916126229418517 ; 0.6974653360955604]
+Neuron 2 recalls point at degree 53%
+Ack inserted at 53%
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/native/jogl.dll
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/native/jogl.dll
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/native/jogl_awt.dll
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/native/jogl_awt.dll
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/native/jogl_cg.dll
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/native/jogl_cg.dll
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/oxDur2.txt
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/oxDur2.txt (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/oxDur2.txt 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,482 @@
+0.00 0.23
+0.00 0.30
+0.01 0.22
+0.01 0.29
+0.01 0.29
+0.01 0.25
+0.01 0.29
+0.01 0.30
+0.02 0.27
+0.02 0.31
+0.02 0.29
+0.02 0.12
+0.03 0.29
+0.03 0.32
+0.03 0.26
+0.03 0.33
+0.03 0.40
+0.04 0.30
+0.04 0.31
+0.04 0.34
+0.04 0.30
+0.04 0.33
+0.04 0.40
+0.05 0.32
+0.05 0.33
+0.05 0.35
+0.05 0.31
+0.05 0.38
+0.05 0.35
+0.06 0.30
+0.06 0.39
+0.06 0.37
+0.06 0.30
+0.06 0.29
+0.07 0.31
+0.07 0.32
+0.07 0.11
+0.07 0.30
+0.07 0.21
+0.07 0.23
+0.08 0.48
+0.08 0.30
+0.08 0.33
+0.08 0.28
+0.08 0.34
+0.08 0.32
+0.08 0.25
+0.09 0.42
+0.09 0.34
+0.09 0.32
+0.09 0.30
+0.09 0.38
+0.09 0.38
+0.09 0.32
+0.10 0.31
+0.10 0.34
+0.10 0.26
+0.10 0.06
+0.10 0.08
+0.10 0.08
+0.10 0.11
+0.11 0.40
+0.11 0.22
+0.11 0.24
+0.11 0.41
+0.11 0.25
+0.11 0.28
+0.11 0.14
+0.12 0.21
+0.13 0.01
+0.13 0.25
+0.13 0.40
+0.14 0.20
+0.14 0.24
+0.14 0.42
+0.15 0.19
+0.15 0.22
+0.15 0.14
+0.15 0.38
+0.15 0.20
+0.15 0.24
+0.15 0.20
+0.15 0.45
+0.16 0.30
+0.16 0.29
+0.16 0.22
+0.16 0.41
+0.16 0.28
+0.16 0.31
+0.16 0.23
+0.16 0.48
+0.17 0.30
+0.17 0.38
+0.17 0.25
+0.17 0.24
+0.17 0.29
+0.17 0.17
+0.18 0.29
+0.18 0.32
+0.18 0.26
+0.18 0.09
+0.18 0.33
+0.18 0.27
+0.18 0.16
+0.19 0.27
+0.19 0.49
+0.19 0.35
+0.19 0.26
+0.19 0.17
+0.19 0.42
+0.19 0.30
+0.20 0.29
+0.20 0.15
+0.20 0.29
+0.20 0.28
+0.20 0.26
+0.20 0.28
+0.21 0.30
+0.21 0.23
+0.21 0.30
+0.21 0.30
+0.21 0.23
+0.22 0.31
+0.22 0.32
+0.22 0.22
+0.22 0.44
+0.22 0.29
+0.23 0.26
+0.23 0.26
+0.23 0.43
+0.23 0.37
+0.23 0.30
+0.23 0.34
+0.24 0.35
+0.24 0.23
+0.24 0.32
+0.24 0.36
+0.24 0.26
+0.24 0.45
+0.24 0.30
+0.25 0.36
+0.25 0.26
+0.25 0.18
+0.25 0.33
+0.25 0.27
+0.25 0.46
+0.25 0.32
+0.25 0.29
+0.26 0.26
+0.26 0.48
+0.26 0.33
+0.26 0.33
+0.26 0.23
+0.26 0.36
+0.26 0.32
+0.26 0.34
+0.27 0.26
+0.27 0.30
+0.27 0.37
+0.27 0.25
+0.27 0.30
+0.28 0.25
+0.28 0.27
+0.28 0.32
+0.28 0.25
+0.28 0.47
+0.28 0.27
+0.28 0.23
+0.29 0.15
+0.29 0.31
+0.29 0.25
+0.29 0.25
+0.29 0.22
+0.29 0.45
+0.29 0.29
+0.29 0.30
+0.30 0.24
+0.30 0.40
+0.30 0.38
+0.30 0.30
+0.30 0.28
+0.30 0.28
+0.30 0.39
+0.31 0.26
+0.31 0.33
+0.31 0.36
+0.31 0.26
+0.31 0.33
+0.31 0.36
+0.31 0.26
+0.32 0.32
+0.32 0.41
+0.32 0.26
+0.32 0.34
+0.32 0.34
+0.32 0.28
+0.33 0.37
+0.33 0.35
+0.33 0.24
+0.33 0.44
+0.33 0.09
+0.33 0.41
+0.33 0.26
+0.34 0.03
+0.34 0.26
+0.34 0.34
+0.34 0.37
+0.34 0.28
+0.35 0.04
+0.35 0.38
+0.35 0.25
+0.35 0.24
+0.35 0.37
+0.35 0.04
+0.36 0.24
+0.36 0.01
+0.36 0.37
+0.36 0.39
+0.37 0.26
+0.37 0.31
+0.37 0.36
+0.37 0.27
+0.38 0.34
+0.38 0.39
+0.38 0.27
+0.42 0.18
+0.42 0.24
+0.43 0.31
+0.43 0.30
+0.43 0.42
+0.43 0.35
+0.51 0.74
+0.52 0.27
+0.52 0.34
+0.52 0.42
+0.52 0.42
+0.53 0.38
+0.53 0.35
+0.53 0.25
+0.53 0.33
+0.53 0.34
+0.53 0.35
+0.54 0.26
+0.54 0.35
+0.55 0.25
+0.55 0.46
+0.55 0.33
+0.55 0.31
+0.55 0.25
+0.55 0.40
+0.55 0.30
+0.55 0.31
+0.56 0.26
+0.56 0.48
+0.56 0.32
+0.56 0.34
+0.59 0.44
+0.59 0.42
+0.59 0.38
+0.59 0.45
+0.59 0.39
+0.60 0.28
+0.60 0.25
+0.60 0.60
+0.60 0.44
+0.60 0.33
+0.61 0.49
+0.61 0.46
+0.61 0.48
+0.61 0.38
+0.62 0.75
+0.62 0.45
+0.62 0.47
+0.62 0.38
+0.62 0.69
+0.62 0.50
+0.62 0.47
+0.62 0.75
+0.63 0.21
+0.63 0.49
+0.63 0.36
+0.63 0.42
+0.63 0.33
+0.63 0.65
+0.64 0.61
+0.65 0.39
+0.65 0.41
+0.65 0.73
+0.65 0.43
+0.65 0.41
+0.65 0.39
+0.65 0.73
+0.66 0.51
+0.66 0.49
+0.66 0.39
+0.66 0.77
+0.66 0.48
+0.66 0.52
+0.66 0.79
+0.67 0.54
+0.67 0.48
+0.67 0.39
+0.67 0.77
+0.67 0.53
+0.67 0.37
+0.67 0.40
+0.67 0.65
+0.68 0.49
+0.68 0.53
+0.69 0.51
+0.69 0.33
+0.69 0.43
+0.69 0.31
+0.69 0.40
+0.70 0.48
+0.70 0.43
+0.70 0.83
+0.70 0.48
+0.70 0.54
+0.70 0.42
+0.70 0.82
+0.70 0.58
+0.71 0.43
+0.71 0.46
+0.71 0.70
+0.71 0.69
+0.71 0.49
+0.71 0.87
+0.72 0.87
+0.72 0.69
+0.72 0.51
+0.72 0.37
+0.72 0.83
+0.72 0.58
+0.73 0.43
+0.73 0.43
+0.73 0.41
+0.73 0.52
+0.74 0.47
+0.74 0.34
+0.74 0.63
+0.74 0.50
+0.74 0.42
+0.74 0.35
+0.74 0.56
+0.74 0.49
+0.75 0.51
+0.75 0.47
+0.75 0.54
+0.75 0.47
+0.75 0.36
+0.75 0.23
+0.75 0.49
+0.76 0.40
+0.76 0.88
+0.76 0.53
+0.76 0.43
+0.76 0.78
+0.76 0.50
+0.76 0.49
+0.77 0.77
+0.77 0.53
+0.77 0.50
+0.77 0.43
+0.77 0.68
+0.77 0.60
+0.77 0.40
+0.78 0.37
+0.78 0.55
+0.78 0.59
+0.78 0.48
+0.78 0.46
+0.78 0.50
+0.79 0.40
+0.79 0.50
+0.79 0.41
+0.79 0.80
+0.79 0.50
+0.79 0.49
+0.80 0.40
+0.80 0.67
+0.80 0.52
+0.80 0.50
+0.80 0.70
+0.80 0.51
+0.80 0.47
+0.81 0.38
+0.81 0.70
+0.81 0.38
+0.81 0.40
+0.81 0.50
+0.81 0.53
+0.81 0.53
+0.82 0.97
+0.82 0.58
+0.82 0.55
+0.82 0.59
+0.82 0.53
+0.82 0.47
+0.83 0.54
+0.83 0.58
+0.83 0.47
+0.83 0.89
+0.83 0.46
+0.84 0.94
+0.84 0.49
+0.84 0.48
+0.84 0.77
+0.85 0.42
+0.85 0.40
+0.86 0.73
+0.86 0.43
+0.86 0.44
+0.86 0.27
+0.86 0.36
+0.86 0.49
+0.86 0.49
+0.86 0.43
+0.87 0.51
+0.87 0.44
+0.87 0.36
+0.87 0.55
+0.87 0.40
+0.87 0.38
+0.87 0.32
+0.88 0.40
+0.88 0.41
+0.88 0.39
+0.88 0.27
+0.88 0.42
+0.88 0.60
+0.89 0.42
+0.89 0.32
+0.89 0.37
+0.89 0.40
+0.89 0.45
+0.89 0.33
+0.89 0.70
+0.90 0.51
+0.90 0.48
+0.90 0.35
+0.90 0.69
+0.90 0.41
+0.90 0.47
+0.90 0.71
+0.91 0.43
+0.91 0.46
+0.91 0.38
+0.91 0.51
+0.91 0.44
+0.91 0.49
+0.91 0.45
+0.91 0.42
+0.92 0.53
+0.92 0.51
+0.92 0.42
+0.92 0.65
+0.92 0.52
+0.92 0.48
+0.92 0.40
+0.92 0.60
+0.93 0.48
+0.93 0.50
+0.93 0.38
+0.93 0.63
+0.93 0.51
+0.93 0.61
+0.93 0.45
+0.93 0.71
+0.94 0.46
+0.94 0.49
+0.94 0.76
+0.94 0.46
+0.94 0.53
+0.94 0.52
+0.94 0.52
+0.94 0.58
+0.95 0.21
+0.95 0.32
+0.95 0.33
+0.99 0.55
+1.00 0.45
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/oxDuration.txt
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/oxDuration.txt (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/oxDuration.txt 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,255 @@
+0.92 0.74
+0.17 0.27
+0.92 0.34
+0.42 0.42
+0.67 0.42
+0.42 0.38
+0.92 0.35
+0.17 0.25
+0.42 0.33
+0.67 0.34
+0.92 0.35
+0.17 0.26
+0.42 0.11
+0.92 0.35
+0.17 0.25
+0.42 0.46
+0.67 0.33
+0.92 0.31
+0.17 0.25
+0.42 0.40
+0.67 0.30
+0.92 0.31
+0.17 0.26
+0.42 0.48
+0.67 0.32
+0.92 0.34
+0.67 0.44
+0.92 0.42
+0.67 0.38
+0.92 0.45
+0.17 0.39
+0.67 0.28
+0.92 0.25
+0.42 0.60
+0.67 0.44
+0.17 0.33
+0.42 0.49
+0.67 0.46
+0.92 0.48
+0.17 0.38
+0.42 0.75
+0.67 0.45
+0.92 0.47
+0.17 0.38
+0.42 0.69
+0.67 0.50
+0.92 0.47
+0.42 0.75
+0.92 0.21
+0.42 0.49
+0.67 0.36
+0.92 0.42
+0.17 0.33
+0.42 0.65
+0.42 0.18
+0.42 0.61
+0.67 0.39
+0.92 0.41
+0.42 0.73
+0.67 0.43
+0.92 0.41
+0.17 0.39
+0.42 0.73
+0.67 0.51
+0.92 0.49
+0.17 0.39
+0.42 0.77
+0.67 0.48
+0.92 0.52
+0.42 0.79
+0.67 0.54
+0.92 0.48
+0.17 0.39
+0.42 0.77
+0.67 0.53
+0.92 0.37
+0.17 0.40
+0.42 0.65
+0.67 0.49
+0.17 0.53
+0.42 0.51
+0.67 0.33
+0.92 0.43
+0.17 0.31
+0.67 0.40
+0.92 0.48
+0.17 0.43
+0.42 0.83
+0.67 0.48
+0.92 0.54
+0.17 0.42
+0.42 0.82
+0.67 0.58
+0.92 0.43
+0.17 0.46
+0.42 0.70
+0.67 0.69
+0.17 0.49
+0.42 0.87
+0.42 0.87
+0.67 0.69
+0.92 0.51
+0.17 0.37
+0.42 0.83
+0.67 0.58
+0.92 0.43
+0.92 0.43
+0.17 0.41
+0.67 0.52
+0.92 0.47
+0.17 0.34
+0.42 0.63
+0.67 0.50
+0.92 0.42
+0.17 0.35
+0.42 0.56
+0.67 0.49
+0.92 0.51
+0.17 0.47
+0.67 0.54
+0.92 0.47
+0.17 0.36
+0.67 0.23
+0.92 0.49
+0.17 0.40
+0.42 0.88
+0.67 0.53
+0.17 0.43
+0.42 0.78
+0.67 0.50
+0.92 0.49
+0.42 0.77
+0.67 0.53
+0.92 0.50
+0.17 0.43
+0.42 0.68
+0.67 0.60
+0.92 0.40
+0.17 0.37
+0.42 0.55
+0.67 0.59
+0.92 0.48
+0.17 0.46
+0.67 0.50
+0.17 0.40
+0.92 0.50
+0.17 0.41
+0.42 0.80
+0.67 0.50
+0.92 0.49
+0.17 0.40
+0.42 0.67
+0.67 0.52
+0.92 0.50
+0.17 0.14
+0.42 0.70
+0.67 0.51
+0.92 0.47
+0.17 0.38
+0.42 0.70
+0.67 0.16
+0.92 0.38
+0.17 0.40
+0.42 0.50
+0.67 0.53
+0.92 0.53
+0.42 0.97
+0.67 0.58
+0.92 0.55
+0.67 0.59
+0.92 0.53
+0.17 0.47
+0.67 0.54
+0.92 0.58
+0.17 0.47
+0.42 0.89
+0.17 0.46
+0.42 0.94
+0.67 0.49
+0.92 0.48
+0.42 0.77
+0.92 0.42
+0.17 0.40
+0.42 0.73
+0.67 0.43
+0.92 0.44
+0.17 0.27
+0.42 0.36
+0.67 0.49
+0.92 0.49
+0.17 0.43
+0.67 0.51
+0.92 0.44
+0.17 0.36
+0.42 0.55
+0.67 0.40
+0.92 0.38
+0.17 0.32
+0.42 0.40
+0.67 0.41
+0.92 0.39
+0.42 0.27
+0.92 0.42
+0.42 0.60
+0.67 0.42
+0.17 0.32
+0.42 0.37
+0.67 0.40
+0.92 0.45
+0.17 0.33
+0.42 0.70
+0.67 0.51
+0.92 0.48
+0.17 0.35
+0.42 0.69
+0.67 0.41
+0.92 0.47
+0.42 0.71
+0.67 0.43
+0.92 0.46
+0.17 0.38
+0.42 0.51
+0.67 0.44
+0.92 0.49
+0.17 0.45
+0.42 0.42
+0.67 0.53
+0.92 0.51
+0.17 0.42
+0.42 0.65
+0.67 0.52
+0.92 0.48
+0.17 0.40
+0.42 0.60
+0.67 0.48
+0.92 0.50
+0.17 0.38
+0.42 0.63
+0.67 0.51
+0.92 0.61
+0.17 0.45
+0.42 0.71
+0.67 0.46
+0.17 0.49
+0.42 0.76
+0.67 0.46
+0.92 0.53
+0.17 0.52
+0.42 0.52
+0.67 0.58
+0.92 0.21
+0.17 0.32
+0.42 0.33
+0.67 0.55
+0.92 0.45
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/rbfinterp.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/branches/uncDrools5x/LogicSOM/rbfinterp.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/src/DroolSOM.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/src/DroolSOM.java (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/src/DroolSOM.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,413 @@
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Vector;
+
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+import org.drools.FactHandle;
+import org.drools.IUncertainRuleBase;
+import org.drools.ObjectFilter;
+import org.drools.RuleBase;
+import org.drools.RuleBaseFactory;
+import org.drools.StatefulSession;
+import org.drools.WorkingMemory;
+import org.drools.audit.WorkingMemoryFileLogger;
+import org.drools.base.ClassFieldReader;
+import org.drools.base.ClassObjectFilter;
+import org.drools.base.ValueType;
+import org.drools.base.evaluators.EvaluatorRegistry;
+import org.drools.base.evaluators.Operator;
+import org.drools.base.evaluators.YoungEvaluatorDefinition;
+import org.drools.base.evaluators.YoungEvaluatorDefinition.YoungEvaluator;
+import org.drools.base.field.LongFieldImpl;
+import org.drools.compiler.DroolsParserException;
+import org.drools.compiler.PackageBuilder;
+import org.drools.compiler.PackageBuilderConfiguration;
+import org.drools.event.DebugAgendaEventListener;
+import org.drools.event.DebugWorkingMemoryEventListener;
+import org.drools.reteoo.ReteooRuleBase;
+import org.drools.reteoo.ReteooWorkingMemory;
+import org.drools.rule.ClassConstraint;
+import org.drools.rule.ConstraintSignature;
+import org.drools.rule.LiteralConstraint;
+import org.drools.rule.Package;
+import org.drools.spi.AgendaFilter;
+import org.drools.spi.Constraint;
+import org.drools.spi.FalseAgendaFilter;
+
+import data.Neuron;
+import data.Point2Dim;
+import data.Sample;
+
+import uncertainty.factory.IDegreeFactory;
+import uncertainty.truthvals.Essence;
+import uncertainty.truthvals.IUncertainDegree;
+
+
+public class DroolSOM extends JFrame {
+
+
+
+
+
+ public final int S = 250;
+ public final int N = 10;
+ public final double T = 0.025;
+ public final int rounds = 1;
+
+ int x, winIdx;
+
+ double[][] data = new double[2][S];
+ double[][] neur = new double[2][N];
+ Vector<Integer> bag = new Vector<Integer>(S);
+
+ Essence[] trainData = new Essence[S];
+ Essence[] neuron = new Essence[N];
+
+ Essence acknow = Essence.True(Essence.L0_BASIC);
+
+ Essence[] recognize = new Essence[N];
+ Essence[] winner = new Essence[N];
+
+ Essence[] move = new Essence[N];
+
+ Essence[] far = new Essence[N];
+ Essence[] near = new Essence[N];
+
+ Essence[] posit = new Essence[N];
+ Essence winEx;
+ int t = 0;
+
+
+
+ Essence coverage = null;
+ Essence waste = null;
+ Essence[] mirror = new Essence[N];
+ Essence[] useful = new Essence[N];
+ Essence[] important = new Essence[N];
+
+
+
+
+ private StatefulSession session;
+ private IDegreeFactory factory;
+
+ private PrintWriter logger;
+
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private static final double sigma = 0.2;
+
+ public DroolSOM() {
+
+ try {
+ initDrools();
+ } catch (Exception e) {
+ System.out.println("Unable to start the rule engine : " + e.toString());
+ }
+
+
+
+
+ for (int j = 0; j < S; j++) {
+ data[0][j] = Math.random();
+ double x = data[0][j];
+ data[1][j] = (x+0.2*Math.random());
+ data[1][j] = 3*(x-0.5)*(x-0.5)+0.32*Math.random();
+
+ trainData[j] = Essence.True(Essence.L0_BASIC);
+ }
+
+
+
+ for (int j = 0; j < N; j++) {
+
+ neur[1][j] = 0.25+0.5*Math.random();
+ neur[0][j] = 0.25+0.5*Math.random();
+
+ session.insert(new Neuron(j, neur[0][j],neur[1][j]),null);
+
+ }
+
+
+ }
+
+
+
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ final DroolSOM m = new DroolSOM();
+ m.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ m.logger.flush();
+ m.logger.close();
+ System.exit(0);
+ }
+ });
+
+ m.addKeyListener(new KeyAdapter() {
+ public void keyPressed(KeyEvent e) {
+ e.getComponent().repaint();
+
+ }
+ });
+
+ JPanel pan = new JPanel(true);
+ m.setContentPane(pan);
+
+ m.display();
+
+ }
+
+ public void display() {
+ setSize(800,800);
+ setVisible(true);
+ repaint();
+
+ }
+
+
+
+ public void paint(Graphics graphics) {
+ super.paint(graphics);
+
+
+
+ if (bag.size() == 0) {
+ System.out.println("REGENERATE THE BAG .....................");
+ for (int j = 0; j < S; j++)
+ bag.add(j);
+ }
+
+
+ t++;
+ for (int i = 0; i < rounds; i++) {
+
+ x = (int) Math.floor(Math.random()*bag.size());
+ x = bag.remove(x);
+ //System.out.println(t+" extracted "+x+ ", left "+bag.size());
+ train(x,t);
+ }
+
+
+ Graphics gr = this.getContentPane().getGraphics();
+ int Xmax = this.getContentPane().getBounds().width;
+ int Ymax = this.getContentPane().getBounds().height;
+
+ this.getContentPane().setBackground(Color.LIGHT_GRAY);
+
+
+ //data points
+ for (int j = 0; j < S; j++)
+ gr.drawOval(spaceToPixelX(data[0][j],Xmax)-1, spaceToPixelY(data[1][j],Ymax)-1, 2,2);
+ // neurons
+
+
+ ObjectFilter filter = new ClassObjectFilter(Neuron.class);
+ Iterator<Neuron> iter = session.iterateObjects(filter);
+
+ while (iter.hasNext()) {
+ Neuron n = iter.next();
+
+ int nx = spaceToPixelX(n.getX(),Xmax);
+ int ny = spaceToPixelY(n.getY(),Ymax);
+ gr.fillOval(nx-5, ny-5, 10,10);
+ int r09 = (int) -Math.floor((Xmax*sigma*Math.log(0.9)));
+ int r05 = (int) -Math.floor((Xmax*sigma*Math.log(0.5)));
+ int r01 = (int) -Math.floor((Xmax*sigma*Math.log(0.1)));
+ //gr.drawOval(nx-r09, ny-r09,2*r09 ,2*r09);
+ gr.drawOval(nx-r05, ny-r05,2*r05 ,2*r05);
+ //gr.drawOval(nx-r01, ny-r01,2*r01 ,2*r01);
+
+ gr.drawString(""+n.getId(), nx+5, ny+5);
+
+ }
+
+
+ for (int j = 0; j < N; j++) {
+// int nx = spaceToPixelX(neur[0][j],Xmax);
+// int ny = spaceToPixelY(neur[1][j],Ymax);
+// gr.fillOval(nx-5, ny-5, 10,10);
+// int r09 = (int) -Math.floor((Xmax*sigma*Math.log(0.9)));
+// int r05 = (int) -Math.floor((Xmax*sigma*Math.log(0.5)));
+// int r01 = (int) -Math.floor((Xmax*sigma*Math.log(0.1)));
+// //gr.drawOval(nx-r09, ny-r09,2*r09 ,2*r09);
+// gr.drawOval(nx-r05, ny-r05,2*r05 ,2*r05);
+// //gr.drawOval(nx-r01, ny-r01,2*r01 ,2*r01);
+//
+// gr.drawString(""+j, nx+5, ny+5);
+
+
+ }
+
+
+
+
+
+ // last training point
+ gr.setColor(Color.RED);
+ gr.fillOval(spaceToPixelX(data[0][x],Xmax)-10, spaceToPixelY(data[1][x],Ymax)-10, 20,20);
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+ /**
+ * @param x sample index
+ * @param t epoch
+ */
+ private void train(int x, int t) {
+ Point2Dim trainPoint = new Sample(data[0][x],data[1][x]);
+ System.out.println("Chosen "+trainPoint);
+ FactHandle trainPointHandle = session.insert(trainPoint, null);
+
+
+ session.fireAllRules(new FalseAgendaFilter());
+
+
+ FactHandle trainToken = session.insert(new Train(), null);
+ session.fireAllRules(new FalseAgendaFilter());
+
+ session.retract(trainToken);
+ session.retract(trainPointHandle);
+
+
+
+ }
+
+
+
+
+ protected int spaceToPixelX(double x, int max) {
+ return (int) Math.round(x*max);
+ }
+
+ protected int spaceToPixelY(double y, int max) {
+ return (int) Math.round((1-y)*max);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /**
+ * @param args
+ * @throws IOException
+ * @throws DroolsParserException
+ */
+ public void initDrools() throws DroolsParserException, IOException {
+
+ Reader source = null;
+ source = new InputStreamReader(
+ //HelloWorldExample.class.getResourceAsStream( "HelloWorld.drl" )
+ new FileInputStream("src/SOM.drl")
+ );
+
+ Properties props = new Properties();
+ props.load(new FileInputStream("src/som.packagebuilder.conf"));
+ PackageBuilderConfiguration conf = new PackageBuilderConfiguration(props);
+ final PackageBuilder builder = new PackageBuilder(conf);
+
+ EvaluatorRegistry registry = builder.getPackageBuilderConfiguration().getEvaluatorRegistry();
+
+ //this will parse and compile in one step
+ builder.addPackageFromDrl( source );
+
+ // Check the builder for errors
+ if ( builder.hasErrors() ) {
+ System.out.println( builder.getErrors().toString() );
+ throw new RuntimeException( "Unable to compile drl");
+ }
+
+ //get the compiled package (which is serializable)
+ final Package pkg = builder.getPackage();
+
+ //add the package to a rulebase (deploy the rule package).
+ final RuleBase ruleBase = RuleBaseFactory.newRuleBase(IUncertainRuleBase.RETEOO_UNCERTAIN);
+ this.factory = ((IUncertainRuleBase) ruleBase).getTruthFactory();
+ ruleBase.addPackage( pkg );
+
+ this.session = ruleBase.newStatefulSession();
+
+
+
+// session.addEventListener( new DebugAgendaEventListener() );
+// session.addEventListener( new DebugWorkingMemoryEventListener() );
+
+ try {
+ logger = new PrintWriter("logSOM.txt");
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ session.setGlobal("registry", registry);
+ session.setGlobal("factory", factory);
+ session.setGlobal("logger", logger);
+
+// final WorkingMemoryFileLogger logger = new WorkingMemoryFileLogger( session );
+// logger.setFileName( "log" );
+
+
+
+// logger.writeToDisk();
+
+ }
+
+
+
+
+
+
+
+
+
+
+}
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/src/LogicSOM08.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/src/LogicSOM08.java (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/src/LogicSOM08.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,586 @@
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+import uncertainty.measures.belief.ImpreciseDistribution;
+import uncertainty.measures.probability.ImpreciseProbability;
+import uncertainty.measures.probability.conversion.TauPignisticStrategy;
+import uncertainty.predicates.BRPLOperator;
+import uncertainty.predicates.BRPLPredicate;
+import uncertainty.predicates.IArg;
+import uncertainty.predicates.IUncertainPredicate;
+import uncertainty.truthvals.Essence;
+import uncertainty.truthvals.IUncertainDegree;
+import uncertainty.truthvals.operators.ModusPonensOp;
+import uncertainty.truthvals.operators.NegOp;
+import uncertainty.truthvals.operators.Lukas.DotAnd;
+import uncertainty.truthvals.operators.Lukas.Equiv;
+import uncertainty.truthvals.operators.Lukas.LukasAnd;
+import uncertainty.truthvals.operators.Lukas.LukasNeg;
+import uncertainty.truthvals.operators.Lukas.LukasOr;
+import uncertainty.truthvals.operators.Lukas.MaxOr;
+import uncertainty.truthvals.operators.Lukas.MinAnd;
+import uncertainty.truthvals.operators.aggregators.DempsterShaferAggStrat;
+
+/*
+ * Created on 19/set/07
+ *
+ */
+
+public class LogicSOM08 extends JFrame {
+
+ public final int S = 250;
+ public final int N = 10;
+ public final double T = 0.025;
+ public final int rounds = 10;
+
+ int x, winIdx;
+
+ double[][] data = new double[2][S];
+ double[][] neur = new double[2][N];
+ Vector<Integer> bag = new Vector<Integer>(S);
+
+ Essence[] trainData = new Essence[S];
+ Essence[] neuron = new Essence[N];
+
+ Essence acknow = Essence.True(Essence.L0_BASIC);
+
+ Essence[] recognize = new Essence[N];
+ Essence[] winner = new Essence[N];
+
+ Essence[] move = new Essence[N];
+
+ Essence[] far = new Essence[N];
+ Essence[] near = new Essence[N];
+
+ Essence[] posit = new Essence[N];
+ Essence winEx;
+ int t = 0;
+
+
+
+ Essence coverage = null;
+ Essence waste = null;
+ Essence[] mirror = new Essence[N];
+ Essence[] useful = new Essence[N];
+ Essence[] important = new Essence[N];
+
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private static final double sigma = 0.2;
+
+ public LogicSOM08() {
+ for (int j = 0; j < S; j++) {
+ data[0][j] = Math.random();
+ double x = data[0][j];
+ data[1][j] = (x+0.2*Math.random());
+ data[1][j] = 3*(x-0.5)*(x-0.5)+0.32*Math.random();
+
+ trainData[j] = Essence.True(Essence.L0_BASIC);
+ }
+
+ for (int j = 0; j < N; j++) {
+ //neur[0][j] = (1.0*j)/N + (1.0/N)*Math.random();
+
+ //neur[1][j] = (1.0*j)/N + (1.0/N)*Math.random();
+
+ int y = (int) Math.floor(Math.random()*S);
+ neur[1][j] = 0.25+0.5*Math.random();
+ neur[0][j] = 0.25+0.5*Math.random();
+ //neur[0][j] = data[0][y];
+ //neur[1][j] = data[1][y];
+
+
+ double x = 1.0*j / N;
+// neur[0][j] = x;
+// neur[1][j] = 3*(x-0.5)*(x-0.5);
+
+ neuron[j] = Essence.True(Essence.L0_BASIC);
+ recognize[j] = Essence.True(Essence.L0_BASIC);
+ winner[j] = Essence.True(Essence.L0_BASIC);
+
+ far[j] = Essence.spike(10*j/N,Essence.L0_BASIC);
+ }
+
+
+ }
+
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ LogicSOM08 m = new LogicSOM08();
+ m.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) { System.exit(0); }
+ });
+
+ m.addKeyListener(new KeyAdapter() {
+ public void keyPressed(KeyEvent e) {
+ e.getComponent().repaint();
+
+ }
+ });
+
+ JPanel pan = new JPanel(true);
+ m.setContentPane(pan);
+
+ m.display();
+
+ }
+
+ public void display() {
+ setSize(800,800);
+ setVisible(true);
+
+ }
+
+
+
+ protected int train(int x, int t) {
+
+
+ for (int j = 0; j < N; j++) {
+ recognize[j] = recall(j,x);
+ }
+
+
+
+ acknow = recognize[0];
+ MaxOr mor = new MaxOr();
+ for (int j = 1; j < N; j++) {
+ acknow = (Essence) mor.eval(new Essence[] {acknow, recognize[j]});
+ }
+
+
+ Equiv eqv = new Equiv();
+ LukasAnd and = new LukasAnd();
+ int winIdx = -1;
+ double winScore = -1.0;
+ for (int j = 0; j < N; j++) {
+ winner[j] = (Essence) eqv.eval(new Essence[] {recognize[j],acknow});
+ //winner[j] = (Essence) and.eval(new Essence[] {winner[j],recognize[j]});
+ double score = winner[j].getAverageDegree().getValue();
+ if (score > winScore) {
+ winScore = score;
+ winIdx = j;
+ }
+
+ }
+
+
+ Essence[] posit2 = new Essence[N];
+ winEx = new Essence(Essence.L0_BASIC);
+ LukasNeg not = new LukasNeg();
+ MinAnd mand9 = new MinAnd();
+ for (int j = 0; j < N; j++) {
+ LukasAnd land = new LukasAnd();
+ //Essence filter = (Essence) land.eval(new Essence[] {winner[j],recognize[j]});
+ Essence filter = winner[j];
+
+
+
+ IArg[] args = new IArg[2];
+
+ IUncertainPredicate prem = new BRPLPredicate("far",null,far[j]);
+ IUncertainPredicate nprem = new BRPLPredicate("far",null,not.eval(new Essence[] {far[j]}));
+ posit[j] = new Essence(Essence.L0_BASIC);
+ posit2[j] = new Essence(Essence.L0_BASIC);
+ IUncertainPredicate conc = new BRPLPredicate("conclus",null,posit[j]);
+ IUncertainPredicate nconc = new BRPLPredicate("conclus",null,posit2[j]);
+
+ args[0] = prem;
+ args[1] = conc;
+ BRPLOperator implic = new BRPLOperator("testMP",args,filter);
+ ModusPonensOp mop = new ModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
+ mop.updateConclusion();
+
+ posit[j] = (Essence) conc.getDegree();
+
+ args[0] = nprem;
+ args[1] = nconc;
+ implic = new BRPLOperator("testMP",args,filter);
+ mop = new ModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
+ mop.updateConclusion();
+
+ posit2[j] = (Essence) nconc.getDegree();
+ posit2[j] = (Essence) not.eval( new Essence[] {posit2[j]});
+
+ ImpreciseProbability ipr = (ImpreciseProbability) new DempsterShaferAggStrat().eval(new ImpreciseProbability[] {posit[j],posit2[j]});
+
+ posit[j] = new Essence(ipr,winner[j].getConfidenceFactor()*far[j].getConfidenceFactor(),Essence.L0_BASIC);
+ //System.out.println("Posit "+j+" obs "+ posit[j].getBtot() +": "+posit[j]);
+
+ }
+ double[] obs = new double[Essence.DEF_N];
+ /*
+ double sum = 0;
+ for (int j = 0; j < Essence.DEF_N; j++) {
+ sum = 0;
+ for (int k = 0; k < N; k++) {
+ double wgt = Math.max(1e-6,posit[k].getCertainty());
+ obs[j] += ((posit[k].getBeta(j)))*wgt*wgt;
+ sum += wgt;
+ }
+ obs[j] = obs[j] /(sum);
+ }
+ */
+ double sum = 0;
+ double[] wgt = new double[N];
+ for (int j = 0; j < N; j++) {
+ //wgt[j] = Math.max(1e-6,posit[j].getCertainty());
+
+ wgt[j] = Math.max(1e-6,recognize[j].getAverageDegree().getValue());
+ //wgt[j] = wgt[j] * wgt[j];
+ sum += wgt[j];
+ }
+
+ for (int j = 0; j < N; j++) {
+ for (int k = 0; k < Essence.DEF_N; k++) {
+ obs[k] += ((posit[j].getBeta(k)))*wgt[j];
+ }
+ }
+
+ for (int k = 0; k < N; k++) {
+ obs[k] = obs[k] /(sum);
+ }
+
+
+ double[] prior = new double[Essence.DEF_N];
+ for (int j = 0; j < Essence.DEF_N; j++) {
+ prior[j] = 0.1;
+ }
+
+
+
+ winEx = new Essence(0.001,prior,obs,1,Essence.L0_BASIC);
+ System.out.println("wexconf"+winEx.getBtot()+" lds2 "+winEx);
+
+ //winEx = new Essence(0,prior,obs,90000,20);
+
+ //System.out.println("Wex\n"+winEx);
+// for (int j = 0; j < Essence.DEF_N; j++) {
+// System.out.println(winEx.getBetaL(j) + " " + winEx.getBetaU(j));
+// }
+
+
+
+
+
+
+
+
+
+
+
+
+ //double age = Math.max((1.0*(T-t))/T,0);
+ double age = (1.0/(T*t+1));
+ System.out.println("Age os" +age);
+ int iage = Math.max(0,(int) Math.floor(10*age));
+
+ Essence young = Essence.spike(iage, Essence.L0_BASIC);
+ Essence fastLearner = Essence.spike(2, Essence.L0_BASIC);
+
+ MinAnd mand = new MinAnd();
+ DotAnd dand = new DotAnd();
+ LukasAnd cand = new LukasAnd();
+ MaxOr maxor = new MaxOr();
+ LukasOr luxor = new LukasOr();
+ for (int j = 0; j < N; j++) {
+
+ //move[j] = (Essence) mand.eval(new Essence[] {young, winner[j]});
+ //move[j] = (Essence) mand.eval(new Essence[] {recognize[j], move[j]});
+ //move[j] = (Essence) dand.eval(new Essence[] {fastLearner, move[j]});
+
+
+
+
+
+
+ int nbr = 0;
+ int tDist = Math.abs(j-5);
+ if (tDist == 0) nbr = 9;
+ else if (tDist == 1) nbr = 7;
+ else if (tDist == 2) nbr = 4;
+ //System.out.println("Neuron "+j+" is near to "+winIdx+" in deg "+nbr);
+ //Essence near = Essence.spike(nbr, Essence.L0_BASIC);
+ Equiv eqPos = new Equiv();
+ MinAnd mand2 = new MinAnd();
+ Essence temp;
+
+ near[j] = (Essence) eqPos.eval(new Essence[] {winEx,far[j]});
+ //temp = near[j];
+//
+ //if (near[j].getAverageDegree().getValue() < 0.5)
+ //near[j] = Essence.spike(0,0);
+
+ near[j] = (Essence) cand.eval(new Essence[] {near[j],near[j]});
+
+
+ near[j] = (Essence) cand.eval(new Essence[] {young,near[j]});
+
+ //near[j] = Essence.spike(0,0);
+
+
+
+ Essence recon = (Essence) mand.eval(new Essence[] {near[j], (Essence) not.eval(new Essence[] {acknow})});
+ //Essence shift = recon;//(Essence) luxor.eval(new Essence[] {recon,near[j]}) ;
+ Essence shift = near[j] ;
+
+
+
+ move[j] = (Essence) cand.eval(new Essence[] {winner[j], shift});
+ move[j] = shift;
+ //
+
+
+
+ //move[j] = (Essence) dand.eval(new Essence[] {move[j], near});
+
+ double alfa = move[j].getAverageDegree().getValue()*move[j].getConfidenceFactor();
+
+ double newx = neur[0][j]*(1-alfa) + alfa*data[0][x];
+ double newy = neur[1][j]*(1-alfa) + alfa*data[1][x];
+
+ neur[0][j] = newx;
+ neur[1][j] = newy;
+
+ }
+ // System.out.println();
+ //System.out.println(young.getAverageDegree().toString());
+ //return winIdx;
+
+ if (age < 0.2 && coverage == null) evalPerformance();
+
+
+
+ return 0;
+ }
+
+
+ private void evalPerformance() {
+ double[] obs = new double[Essence.DEF_N];
+ for (int k = 0; k < S; k++) {
+
+ for (int j = 0; j < N; j++) {
+ recognize[j] = recall(j,k);
+
+
+ }
+ acknow = recognize[0];
+ MaxOr mor = new MaxOr();
+ for (int j = 1; j < N; j++) {
+ acknow = (Essence) mor.eval(new Essence[] {acknow, recognize[j]});
+ } //Exists N: recognize(X)
+
+ for (int i = 0; i < Essence.DEF_N; i++) {
+ obs[i] += acknow.getBeta(i) / S;
+ }
+ }
+ coverage = new Essence(0,new double[Essence.DEF_N],obs,S,Essence.L0_BASIC);
+ System.out.println("COVER\n"+coverage);
+
+
+ MaxOr mor = new MaxOr();
+ MinAnd mand = new MinAnd();
+ for (int j = 0; j < N; j++) {
+
+ for (int k = 0; k < S; k++) {
+ recognize[j] = recall(j,k);
+ useful[j]= (useful[j]== null) ? recognize[j]: (Essence) mor.eval(new Essence[] {useful[j], recognize[j]});
+ }
+
+ waste = (waste == null) ? useful[j] : (Essence) mand.eval(new Essence[]{useful[j],waste});
+ }
+
+ System.out.println("WASTE\n"+waste);
+
+
+ Equiv eqOp = new Equiv();
+ for (int j = 0; j < N; j++){
+ obs = new double[Essence.DEF_N];
+ for (int k = 0; k < S; k++) {
+ Essence recN = recall(j,k);
+ int j2 = (j+1) % N;
+ Essence recM = recall(j2,k);
+ Essence sim = (Essence) eqOp.eval(new Essence[] {recN,recM});
+ for (int i = 0; i < sim.getN(); i++) {
+ obs[i] += sim.getBeta(i)*recN.getAverageDegree().getValue() / S;
+ }
+ }
+ mirror[j] = new Essence(0,new double[Essence.DEF_N],obs,S,Essence.L0_BASIC);
+ }
+
+
+ LukasNeg notOp = new LukasNeg();
+ for (int j = 0; j < N; j++){
+
+ for (int k = 0; k < S; k++) {
+ Essence rec = recall(j, k);
+
+ Essence otRec = null;
+ Essence otCumulRec = null;
+ for (int j2 = 0; j2 < N; j2++) {
+ if (j == j2) continue;
+ otRec = (Essence) notOp.eval(new Essence[] {recall(j2,k)});
+ otCumulRec = (Essence) ((otCumulRec == null) ? otRec : mand.eval(new Essence[] {otCumulRec,otRec}));
+ }
+ Essence contrib = (Essence) mand.eval(new Essence[]{otCumulRec,rec});
+
+ important[j] = (Essence) ((important[j] == null) ? contrib : mor.eval(new Essence[] {important[j], contrib}));
+ }
+
+ }
+
+
+ }
+
+ public void paint(Graphics graphics) {
+ super.paint(graphics);
+
+
+
+ if (bag.size() == 0) {
+ System.out.println("REGENERATE THE BAG .....................");
+ for (int j = 0; j < S; j++)
+ bag.add(j);
+ }
+
+
+ t++;
+ for (int i = 0; i < rounds; i++) {
+
+ x = (int) Math.floor(Math.random()*bag.size());
+ x = bag.remove(x);
+ System.out.println(t+" extracted "+x+ ", left "+bag.size());
+ train(x,t);
+ }
+
+
+ Graphics gr = this.getContentPane().getGraphics();
+ int Xmax = this.getContentPane().getBounds().width;
+ int Ymax = this.getContentPane().getBounds().height;
+
+ this.getContentPane().setBackground(Color.LIGHT_GRAY);
+
+
+ //data points
+ for (int j = 0; j < S; j++)
+ gr.drawOval(spaceToPixelX(data[0][j],Xmax)-1, spaceToPixelY(data[1][j],Ymax)-1, 2,2);
+ // neurons
+ for (int j = 0; j < N; j++) {
+ int nx = spaceToPixelX(neur[0][j],Xmax);
+ int ny = spaceToPixelY(neur[1][j],Ymax);
+ gr.fillOval(nx-5, ny-5, 10,10);
+ int r09 = (int) -Math.floor((Xmax*sigma*Math.log(0.9)));
+ int r05 = (int) -Math.floor((Xmax*sigma*Math.log(0.5)));
+ int r01 = (int) -Math.floor((Xmax*sigma*Math.log(0.1)));
+ //gr.drawOval(nx-r09, ny-r09,2*r09 ,2*r09);
+ gr.drawOval(nx-r05, ny-r05,2*r05 ,2*r05);
+ //gr.drawOval(nx-r01, ny-r01,2*r01 ,2*r01);
+
+ gr.drawString(""+j, nx+5, ny+5);
+
+
+ }
+ // last training point
+ gr.setColor(Color.RED);
+ gr.fillOval(spaceToPixelX(data[0][x],Xmax)-10, spaceToPixelY(data[1][x],Ymax)-10, 20,20);
+
+ // recon degree from the whole net
+ //winEx.renderCompact(new Rectangle(spaceToPixelX(data[0][x],Xmax), spaceToPixelY(data[1][x],Ymax), 30,30),gr);
+ //acknow.renderCompact(new Rectangle(spaceToPixelX(data[0][x],Xmax), spaceToPixelY(data[1][x],Ymax)+30, 30,30),gr);
+
+ if (coverage != null) coverage.renderCompact(new Rectangle(spaceToPixelX(data[0][x],Xmax), spaceToPixelY(data[1][x],Ymax), 30,30),gr);
+ if (waste != null) waste.renderCompact(new Rectangle(spaceToPixelX(data[0][x],Xmax), spaceToPixelY(data[1][x],Ymax)+30, 30,30),gr);
+
+
+
+ for (int j = 0; j < N; j++) {
+ int xn = spaceToPixelX(neur[0][j],Xmax)-10;
+ int yn = spaceToPixelY(neur[1][j],Ymax)+10;
+
+
+ gr.setColor(Color.BLUE);
+ if (j == winIdx) {
+ gr.fillOval(spaceToPixelX(neur[0][j],Xmax)-7, spaceToPixelY(neur[1][j],Ymax)-7, 15,15);
+
+// double dx = neur[0][j]-data[0][x];
+// double dy = neur[1][j]-data[1][x];
+// double d = Math.sqrt(dx*dx+dy*dy);
+//
+// System.out.println("Neur at "+neur[0][j]+";"+neur[1][j]);
+// System.out.println("Data at "+data[0][x]+";"+data[1][x]);
+// System.out.println("Delta is "+dx+" ; "+dy);
+// System.out.println("Distance is "+d +" for activ "+Math.exp(-d/sigma));
+
+ }
+
+ //neuron[j].renderCompact(new Rectangle(xn,yn,30,30),gr);
+ //recognize[j].renderCompact(new Rectangle(xn,yn,25,25),gr);
+ //posit[j].renderCompact(new Rectangle(xn,yn,25,25),gr);
+
+ yn = spaceToPixelY(neur[1][j],Ymax)+35;
+ winner[j].renderCompact(new Rectangle(xn,yn,25,25),gr);
+
+ yn = spaceToPixelY(neur[1][j],Ymax)+10;
+ near[j].renderCompact(new Rectangle(xn,yn,25,25),gr);
+
+
+ yn = spaceToPixelY(neur[1][j],Ymax)+10;
+ if (mirror[j] != null) mirror[j].renderCompact(new Rectangle(xn,yn,25,25),gr);
+
+ yn = spaceToPixelY(neur[1][j],Ymax)+35;
+ if (useful[j] != null) useful[j].renderCompact(new Rectangle(xn,yn,25,25),gr);
+
+ yn = spaceToPixelY(neur[1][j],Ymax)+60;
+ if (important[j] != null) important[j].renderCompact(new Rectangle(xn,yn,25,25),gr);
+
+
+ }
+
+
+
+ }
+
+
+
+
+
+ protected Essence recall(int j, int x) {
+ double dx = (data[0][x]-neur[0][j]);
+ double dy = (data[1][x]-neur[1][j]);
+ double dist = 1*Math.sqrt(dx*dx+dy*dy);
+ int eps = (int) Math.min(9,Math.floor(10*Math.exp(-dist/sigma)));
+ return Essence.spike(eps,Essence.L0_BASIC);
+ }
+
+ protected int spaceToPixelX(double x, int max) {
+ return (int) Math.round(x*max);
+ }
+
+ protected int spaceToPixelY(double y, int max) {
+ return (int) Math.round((1-y)*max);
+ }
+
+
+
+
+
+}
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/src/SOM.drl
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/src/SOM.drl (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/src/SOM.drl 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,71 @@
+#created on: 01-Aug-2008
+package test;
+
+#list any import classes here.
+
+import java.util.Hashtable;
+import uncertainty.truthvals.IUncertainDegree;
+import org.drools.rule.ConstraintSignature;
+import org.drools.rule.ClassConstraint;
+
+
+import data.Sample;
+import data.Neuron;
+import data.Acknowledge;
+
+
+#declare any global variables here
+
+global uncertainty.factory.IDegreeFactory factory;
+global org.drools.base.evaluators.EvaluatorRegistry registry;
+global java.io.PrintWriter logger;
+
+
+
+
+
+rule "Insert"
+
+ salience 9999
+
+
+ when
+ $p : Sample( )
+ then
+ logger.println("Asserted " + $p );
+
+end
+
+
+
+rule "Recall"
+
+ salience 1000
+
+
+ when
+ $p : Sample( )
+ $n : Neuron( position `near[0.45] $p.position )
+ then
+
+ logger.println("Neuron " + $n.getId() + " recalls point at degree "+ drools.getActivationDegree() );
+ Hashtable<ConstraintSignature, IUncertainDegree> priors = new Hashtable<ConstraintSignature, IUncertainDegree>();
+ priors.put(ClassConstraint.buildSignature(Acknowledge.class),drools.getActivationDegree());
+ insertLogical(new Acknowledge($n,$p),priors);
+end
+
+
+
+rule "Acknowledge"
+
+ salience 900
+
+
+ when
+ Train()
+ exists $ack : Acknowledge()
+ then
+ logger.println("Ack inserted at "+drools.getActivationDegree());
+ System.out.println("***********************************************++++++++++++++++++++++++++++++++****************************");
+end
+
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/src/Train.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/src/Train.java (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/src/Train.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,4 @@
+
+public class Train {
+
+}
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Acknowledge.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Acknowledge.java (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Acknowledge.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,33 @@
+package data;
+
+public class Acknowledge {
+
+
+ private Neuron n;
+
+ private Sample s;
+
+ public void setNeuron(Neuron n) {
+ this.n = n;
+ }
+
+ public Neuron getNeuron() {
+ return n;
+ }
+
+ public void setSample(Sample s) {
+ this.s = s;
+ }
+
+ public Sample getSample() {
+ return s;
+ }
+
+ public Acknowledge(Neuron n, Sample s) {
+ this.n = n;
+ this.s = s;
+ }
+
+
+
+}
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Neuron.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Neuron.java (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Neuron.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,49 @@
+/**
+ *
+ */
+package data;
+
+/**
+ * @author davide
+ *
+ */
+public class Neuron extends Point2Dim {
+
+ private int id;
+
+
+ /**
+ * @param x
+ * @param y
+ */
+ public Neuron(int id, Double x, Double y) {
+ super(x, y);
+ this.setId(id);
+ // TODO Auto-generated constructor stub
+ }
+
+ public void moveTo(Point2Dim tgt, double alfa) {
+ setX(this.getX() + alfa*(tgt.getX()-this.getX()));
+ setY(this.getY() + alfa*(tgt.getY()-this.getY()));
+ }
+
+
+ public String toString() {
+ return "Neuron "+ id +" at [" + getX() + " | " + getY() + "]";
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the id
+ */
+ public int getId() {
+ return id;
+ }
+
+}
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Point2Dim.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Point2Dim.java (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Point2Dim.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,59 @@
+/**
+ *
+ */
+package data;
+
+/**
+ * @author davide
+ *
+ */
+public class Point2Dim {
+
+ private Double x;
+
+ private Double y;
+
+ /**
+ * @param x the x to set
+ */
+ public void setX(Double x) {
+ this.x = x;
+ }
+
+ /**
+ * @return the x
+ */
+ public Double getX() {
+ return x;
+ }
+
+ /**
+ * @param y the y to set
+ */
+ public void setY(Double y) {
+ this.y = y;
+ }
+
+ /**
+ * @return the y
+ */
+ public Double getY() {
+ return y;
+ }
+
+
+ public Point2Dim(Double x, Double y) {
+ setX(x);
+ setY(y);
+ }
+
+
+ public String toString() {
+ return "Point at ["+x+" ; " + y + "]";
+ }
+
+ public Double[] getPosition() {
+ return new Double[] {x, y};
+ }
+
+}
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Sample.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Sample.java (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/src/data/Sample.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,21 @@
+/**
+ *
+ */
+package data;
+
+/**
+ * @author davide
+ *
+ */
+public class Sample extends Point2Dim {
+
+ /**
+ * @param x
+ * @param y
+ */
+ public Sample(Double x, Double y) {
+ super(x, y);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/src/evaluators/NearEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/src/evaluators/NearEvaluatorDefinition.java (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/src/evaluators/NearEvaluatorDefinition.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,449 @@
+package evaluators;
+
+import uncertainty.factory.IDegreeFactory;
+
+
+import java.awt.geom.Point2D;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.IUncertainRuleBase;
+import org.drools.RuntimeDroolsException;
+import org.drools.WorkingMemory;
+import org.drools.base.BaseEvaluator;
+import org.drools.base.BaseUncertainEvaluator;
+import org.drools.base.ValueType;
+import org.drools.base.evaluators.IUncertainBinaryEvaluatorDefinition;
+import org.drools.base.evaluators.Operator;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
+import org.drools.rule.VariableRestriction.VariableContextEntry;
+import org.drools.spi.Evaluator;
+import org.drools.spi.FieldValue;
+import org.drools.spi.IUncertainEvaluator;
+import org.drools.spi.InternalReadAccessor;
+
+import data.Point2Dim;
+
+import uncertainty.truthvals.IUncertainDegree;
+
+
+
+
+/**
+ *
+ * @author sotty
+
+ *
+ */
+public class NearEvaluatorDefinition implements IUncertainBinaryEvaluatorDefinition {
+
+
+
+ public class NearEvaluator extends BaseUncertainEvaluator implements IUncertainEvaluator {
+
+ private Double sigma;
+ //private Double mu;
+
+
+ public NearEvaluator(final ValueType type,
+ final boolean isNegated,
+ final String parameters) {
+ super( type,
+ isNegated ? NOT_NEAR : NEAR );
+ this.parseParameters( parameters );
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ super.readExternal(in);
+// mu = in.readDouble();
+ sigma = in.readDouble();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ super.writeExternal(out);
+// out.writeDouble(mu);
+ out.writeDouble(sigma);
+ }
+
+
+ /**
+ * Evaluator membership function definition
+ *
+ * @param age
+ * @return (age - min) / (max - min) clamped between 0 and 1.
+ */
+ protected IUncertainDegree eval(Double[] x, Double[] mu, IDegreeFactory factory) {
+ return evalMu(x, mu, factory);
+ }
+
+
+
+
+ protected IUncertainDegree evalMu(Double x[], Double mu[], IDegreeFactory factory) {
+
+ Double dist = 0.0;
+ for (int j = 0; j < x.length; j++) {
+ dist += Math.pow(x[j] - mu[j],2);
+ }
+
+ dist = Math.sqrt(dist);
+
+ Double val = Math.exp( - dist/(sigma) );
+
+ return factory.buildDegree(val);
+ }
+
+
+
+
+
+
+ public IUncertainDegree evaluateUncertain(WorkingMemory workingMemory,
+ InternalReadAccessor extractor, Object object1, FieldValue value) {
+
+
+ if (! (workingMemory.getRuleBase() instanceof IUncertainRuleBase)) {
+ throw new RuntimeDroolsException("Near Evaluator : Uncertainty has not been enabled in the current Rule Base");
+ }
+
+
+
+ IDegreeFactory factory = ((IUncertainRuleBase) workingMemory.getRuleBase()).getTruthFactory();
+
+
+ Object field = extractor.getValue(object1);
+ if (field == null)
+ return factory.Unknown();
+
+
+
+
+
+ return evalMu((Double[]) field,(Double[]) value.getValue(),factory);
+
+
+
+
+ }
+
+
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ InternalReadAccessor extractor, Object object1, FieldValue value) {
+ return evaluateUncertain(workingMemory, extractor, object1, value).toBoolean();
+ }
+
+
+
+
+ public IUncertainDegree evaluateUncertain(WorkingMemory workingMemory,
+ InternalReadAccessor leftExtractor, Object left,
+ InternalReadAccessor rightExtractor, Object right) {
+
+ if (! (workingMemory.getRuleBase() instanceof IUncertainRuleBase)) {
+ throw new RuntimeDroolsException("Near Evaluator : Uncertainty has not been enabled in the current Rule Base");
+ }
+
+ IDegreeFactory factory = ((IUncertainRuleBase) workingMemory.getRuleBase()).getTruthFactory();
+
+
+ Object field1 = leftExtractor.getValue(left);
+ if (field1 == null)
+ return factory.Unknown();
+
+
+
+ Object field2 = rightExtractor.getValue(right);
+ if (field2 == null)
+ return factory.Unknown();
+
+
+
+ return evalMu((Double[]) field1,(Double[]) field2,factory);
+
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ InternalReadAccessor leftExtractor, Object left,
+ InternalReadAccessor rightExtractor, Object right) {
+ return evaluateUncertain(workingMemory, leftExtractor, left, rightExtractor, right).toBoolean();
+ }
+
+
+ public IUncertainDegree evaluateUncertainCachedLeft(WorkingMemory workingMemory,
+ VariableContextEntry context, Object object1) {
+
+ if (! (workingMemory.getRuleBase() instanceof IUncertainRuleBase)) {
+ throw new RuntimeDroolsException("Near Evaluator : Uncertainty has not been enabled in the current Rule Base");
+ }
+ IDegreeFactory factory = ((IUncertainRuleBase) workingMemory.getRuleBase()).getTruthFactory();
+
+ Double[] v1 = (Double[]) ((ObjectVariableContextEntry) context).left;
+ Double[] v2 = ((Point2Dim) object1).getPosition();
+
+ return eval(v1,v2,factory);
+ }
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ VariableContextEntry context, Object object1) {
+ return this.evaluateUncertainCachedLeft((WorkingMemory)workingMemory, context, object1).toBoolean();
+ }
+
+
+ public IUncertainDegree evaluateUncertainCachedRight(WorkingMemory workingMemory,
+ VariableContextEntry context, Object object2) {
+
+ if (! (workingMemory.getRuleBase() instanceof IUncertainRuleBase)) {
+ throw new RuntimeDroolsException("Near Evaluator : Uncertainty has not been enabled in the current Rule Base");
+ }
+
+ IDegreeFactory factory = ((IUncertainRuleBase) workingMemory.getRuleBase()).getTruthFactory();
+
+ Double[] v1 = (Double[]) object2;
+ Double[] v2 = (Double[]) ((ObjectVariableContextEntry) context).right;
+
+ return eval(v1,v2,factory);
+
+// Object field1 = leftExtractor.getValue(left);
+// if (field1 == null)
+// return factory.Unknown();
+//
+//
+//
+// Object field2 = rightExtractor.getValue(right);
+// if (field2 == null)
+// return factory.Unknown();
+//
+//
+//
+// return evalMu((Double[]) field1,(Double[]) field2,factory);
+//
+
+ }
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ VariableContextEntry context, Object object2) {
+ return evaluateUncertainCachedRight(workingMemory, context, object2).toBoolean();
+ }
+
+
+
+
+
+
+
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = super.hashCode();
+ result = PRIME * result + (int) (sigma.longValue() ^ (sigma.longValue() >>> 32));
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( !super.equals( obj ) ) return false;
+ if ( getClass() != obj.getClass() ) return false;
+ final NearEvaluator other = (NearEvaluator) obj;
+ return sigma == other.sigma;
+ }
+
+ /**
+ * This methods tries to parse the string of parameters to customize
+ * the evaluator.
+ *
+ * @param parameters
+ */
+ private void parseParameters(String parameters) {
+ if ( parameters == null || parameters.trim().length() == 0 ) {
+ // open bounded range
+ this.sigma = new Double(1);
+ return;
+ }
+
+ try {
+
+ this.sigma = Double.parseDouble( parameters );
+
+ } catch ( NumberFormatException e ) {
+ throw new RuntimeDroolsException( "[Young Evaluator]: Not possible to parse parameters: '" + parameters + "'",
+ e );
+ }
+ }
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ public static final Operator NEAR = Operator.addOperatorToRegistry( "near",
+ false );
+
+ public static final Operator NOT_NEAR = Operator.addOperatorToRegistry( "near",
+ true );
+
+ private static final String[] SUPPORTED_IDS = {NEAR.getOperatorString()};
+
+ private Map<String, Evaluator> cache = Collections.emptyMap();
+
+
+
+
+
+
+ public Evaluator getEvaluator(ValueType type, String operatorId,
+ boolean isNegated, String parameterText) {
+
+
+ if ( this.cache == Collections.EMPTY_MAP ) {
+ this.cache = new HashMap<String, Evaluator>();
+ }
+ String key = isNegated + ":" + parameterText;
+ Evaluator eval = this.cache.get( key );
+ if ( eval == null ) {
+ eval = new NearEvaluator( type,
+ isNegated,
+ parameterText );
+ this.cache.put( key,
+ eval );
+ }
+ return eval;
+
+
+
+ }
+
+ public Evaluator getEvaluator(ValueType type, Operator operator,
+ String parameterText) {
+ return getEvaluator(type,operator.getOperatorString(),false,parameterText);
+ }
+
+ public Evaluator getEvaluator(ValueType type, Operator operator) {
+ return getEvaluator(type,operator.getOperatorString(),false,"");
+ }
+
+
+
+
+
+ /**
+ * Operator is known as "young"ValueType type, Operator op
+ */
+ public String[] getEvaluatorIds() {
+ return SUPPORTED_IDS;
+ }
+
+
+
+
+
+
+
+ /**
+ * Young can be negated
+ * It is only by chance that "not young" coincides with the concept "old".
+ */
+ public boolean isNegatable() {
+ return true;
+ }
+
+
+
+ /**
+ * This evaluator operates on fact properties (i.e. age)
+ * and not on factHandles.
+ * So this returns false
+ */
+ public boolean operatesOnFactHandles() {
+ return false;
+ }
+
+
+
+
+
+ /**
+ *
+ */
+ public boolean supportsType(ValueType type) {
+ return type.isNumber();
+ }
+
+
+
+
+
+
+
+ /*
+ * TODO: Try and understand what this means. Copied from AfterEvalDef.
+ */
+
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ cache = (Map<String, Evaluator>) in.readObject();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(cache);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
Added: labs/jbossrules/branches/uncDrools5x/LogicSOM/src/som.packagebuilder.conf
===================================================================
--- labs/jbossrules/branches/uncDrools5x/LogicSOM/src/som.packagebuilder.conf (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/LogicSOM/src/som.packagebuilder.conf 2008-08-18 12:12:30 UTC (rev 21600)
@@ -0,0 +1,38 @@
+drools.dialect.default = java
+drools.dialect.java = org.drools.rule.builder.dialect.java.JavaDialectConfiguration
+drools.dialect.java.compiler = ECLIPSE
+
+drools.dialect.mvel = org.drools.rule.builder.dialect.mvel.MVELDialectConfiguration
+drools.dialect.mvel.strict = true
+drools.dialect.mvel.langLevel = 4
+
+drools.accumulate.function.average = org.drools.base.accumulators.AverageAccumulateFunction
+drools.accumulate.function.max = org.drools.base.accumulators.MaxAccumulateFunction
+drools.accumulate.function.min = org.drools.base.accumulators.MinAccumulateFunction
+drools.accumulate.function.count = org.drools.base.accumulators.CountAccumulateFunction
+drools.accumulate.function.sum = org.drools.base.accumulators.SumAccumulateFunction
+
+drools.evaluator.coincides = org.drools.base.evaluators.CoincidesEvaluatorDefinition
+drools.evaluator.before = org.drools.base.evaluators.BeforeEvaluatorDefinition
+drools.evaluator.after = org.drools.base.evaluators.AfterEvaluatorDefinition
+drools.evaluator.meets = org.drools.base.evaluators.MeetsEvaluatorDefinition
+drools.evaluator.metby = org.drools.base.evaluators.MetByEvaluatorDefinition
+drools.evaluator.overlaps = org.drools.base.evaluators.OverlapsEvaluatorDefinition
+drools.evaluator.overlappedby = org.drools.base.evaluators.OverlappedByEvaluatorDefinition
+drools.evaluator.during = org.drools.base.evaluators.DuringEvaluatorDefinition
+drools.evaluator.includes = org.drools.base.evaluators.IncludesEvaluatorDefinition
+drools.evaluator.starts = org.drools.base.evaluators.StartsEvaluatorDefinition
+drools.evaluator.startedby = org.drools.base.evaluators.StartedByEvaluatorDefinition
+drools.evaluator.finishes = org.drools.base.evaluators.FinishesEvaluatorDefinition
+drools.evaluator.finishedby = org.drools.base.evaluators.FinishedByEvaluatorDefinition
+drools.evaluator.equality = org.drools.base.evaluators.EqualityEvaluatorsDefinition
+drools.evaluator.comparable = org.drools.base.evaluators.ComparableEvaluatorsDefinition
+drools.evaluator.set = org.drools.base.evaluators.SetEvaluatorsDefinition
+drools.evaluator.matches = org.drools.base.evaluators.MatchesEvaluatorsDefinition
+drools.evaluator.soundslike = org.drools.base.evaluators.SoundslikeEvaluatorsDefinition
+
+drools.evaluator.young = org.drools.base.evaluators.YoungEvaluatorDefinition
+drools.evaluator.heavy = org.drools.base.evaluators.HeavyEvaluatorDefinition
+drools.evaluator.nearly = org.drools.base.evaluators.NearlyEvaluatorDefinition
+drools.evaluator.near = evaluators.NearEvaluatorDefinition
+
Modified: labs/jbossrules/branches/uncDrools5x/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java 2008-08-18 10:42:14 UTC (rev 21599)
+++ labs/jbossrules/branches/uncDrools5x/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -1551,6 +1551,12 @@
// TODO Auto-generated method stub
}
+
+ @Override
+ public boolean isNotFalse() {
+ // TODO Auto-generated method stub
+ return true;
+ }
}
class MockTuple
Modified: labs/jbossrules/branches/uncDrools5x/drools-compiler/src/test/java/org/drools/testframework/RuleCoverageListenerTest.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/drools-compiler/src/test/java/org/drools/testframework/RuleCoverageListenerTest.java 2008-08-18 10:42:14 UTC (rev 21599)
+++ labs/jbossrules/branches/uncDrools5x/drools-compiler/src/test/java/org/drools/testframework/RuleCoverageListenerTest.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -126,4 +126,9 @@
public void setRuleFlowGroupNode(RuleFlowGroupNode ruleFlowGroupNode) {
}
+ @Override
+ public boolean isNotFalse() {
+ return true;
+ }
+
}
Modified: labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/common/AgendaItem.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/common/AgendaItem.java 2008-08-18 10:42:14 UTC (rev 21599)
+++ labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/common/AgendaItem.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -299,4 +299,10 @@
public GroupElement getSubRule() {
return this.subrule;
}
+
+ @Override
+ public boolean isNotFalse() {
+ // TODO Auto-generated method stub
+ return true;
+ }
}
Modified: labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java 2008-08-18 10:42:14 UTC (rev 21599)
+++ labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -17,7 +17,11 @@
package org.drools.reteoo;
import java.util.Deque;
+import java.util.LinkedList;
+import java.util.Vector;
+import org.drools.IUncertainRuleBase;
+import org.drools.RuntimeDroolsException;
import org.drools.common.BetaConstraints;
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
@@ -25,6 +29,7 @@
import org.drools.rule.Behavior;
import org.drools.spi.PropagationContext;
+import uncertainty.factory.IDegreeFactory;
import uncertainty.truthvals.IUncertainDegree;
/**
@@ -97,14 +102,25 @@
public void assertLeftTuple(final LeftTuple leftTuple,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
+
+ if (workingMemory.getRuleBase() instanceof IUncertainRuleBase) {
+ assertUncertainLeftTuple(leftTuple,context,workingMemory);
+ return;
+ }
+
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
this.constraints.updateFromTuple( memory.getContext(),
workingMemory,
leftTuple );
+
+
+
for ( RightTuple rightTuple = memory.getRightTupleMemory().getLast( leftTuple ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getPrevious() ) {
- if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
+
+
+ if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
rightTuple.getFactHandle() ) ) {
leftTuple.setBlocker( rightTuple );
@@ -112,6 +128,8 @@
break;
}
+
+
}
this.constraints.resetTuple( memory.getContext() );
@@ -131,11 +149,164 @@
- public void assertObject(final InternalFactHandle factHandle,
+
+
+ private void assertUncertainLeftTuple(LeftTuple leftTuple,
+ PropagationContext context, InternalWorkingMemory workingMemory) {
+
+ IDegreeFactory factory = ((IUncertainRuleBase) workingMemory.getRuleBase()).getTruthFactory();
+
+ final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
+
+ this.constraints.updateFromTuple( memory.getContext(),
+ workingMemory,
+ leftTuple );
+
+
+
+ Vector<IUncertainDegree> degrees = new Vector<IUncertainDegree>();
+ for ( RightTuple rightTuple = memory.getRightTupleMemory().getLast( leftTuple ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getPrevious() ) {
+ IUncertainDegree mDeg = this.constraints.matchesCachedLeft(memory.getContext(), rightTuple.getFactHandle(), factory);
+
+ //TODO : Creare una sorta di "resetTupleDegree"
+ ((UncertainRightTuple) rightTuple).setDegree(mDeg);
+
+
+ IUncertainDegree joinVal = factory.getAndOperator().eval(((UncertainRightTuple) rightTuple).getTruthVal().toArray(new IUncertainDegree[1]));
+ degrees.add(joinVal);
+ ((UncertainRightTuple) rightTuple).resetDegree();
+
+
+ }
+ IUncertainDegree[] degsArray = new IUncertainDegree[degrees.size()];
+ IUncertainDegree existDegree = factory.getOrOperator().eval(degrees.toArray(degsArray));
+
+
+ if ( existDegree.toBoolean() ) {
+ RightTuple rightTuple = memory.getRightTupleMemory().getLast(leftTuple);
+ leftTuple.setBlocker( rightTuple );
+ rightTuple.setBlocked( leftTuple );
+ }
+
+
+ this.constraints.resetTuple( memory.getContext() );
+
+
+ if ( leftTuple.getBlocker() != null ) {
+ // tuple is not blocked to propagate
+ Deque<IUncertainDegree> degList = new LinkedList<IUncertainDegree>();
+ degList.add(existDegree);
+ RightTuple exisTuple = new UncertainRightTuple(leftTuple.getBlocker().getFactHandle(),degList,this);
+ this.sink.propagateAssertLeftTuple( leftTuple,
+ exisTuple,
+ context,
+ workingMemory,
+ this.tupleMemoryEnabled);
+ } else if ( this.tupleMemoryEnabled ) {
+ // LeftTuple is not blocked, so add to memory so other RightTuples can match
+ memory.getLeftTupleMemory().add( leftTuple );
+ }
+
+ }
+
+
+
+
+ public void assertObject(final InternalFactHandle factHandle,
Deque<IUncertainDegree> tVal,
final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- assertObject(factHandle,context,workingMemory);
+ final InternalWorkingMemory workingMemory) {
+
+
+ IDegreeFactory factory = ((IUncertainRuleBase) workingMemory.getRuleBase()).getTruthFactory();
+ final RightTuple rightTuple = new UncertainRightTuple( factHandle,
+ tVal,
+ this );
+
+ final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
+ if ( !behavior.assertRightTuple( memory.getBehaviorContext(),
+ rightTuple,
+ workingMemory ) ) {
+ // destroy right tuple
+ rightTuple.unlinkFromRightParent();
+ return;
+ }
+
+ memory.getRightTupleMemory().add( rightTuple );
+
+ if ( !this.tupleMemoryEnabled ) {
+ // do nothing here, as we know there are no left tuples at this stage in sequential mode.
+ return;
+ }
+
+ this.constraints.updateFromFactHandle( memory.getContext(),
+ workingMemory,
+ factHandle );
+
+
+
+
+
+ for ( LeftTuple leftTuple = memory.getLeftTupleMemory().getFirst( rightTuple ); leftTuple != null; ) {
+ // preserve next now, in case we remove this leftTuple
+ LeftTuple temp = (LeftTuple) leftTuple.getNext();
+
+
+
+ Vector<IUncertainDegree> degrees = new Vector<IUncertainDegree>();
+ for ( RightTuple right = memory.getRightTupleMemory().getLast( leftTuple ); right != null; right = (RightTuple) right.getPrevious() ) {
+
+ IUncertainDegree mDeg = this.constraints.matchesCachedLeft(memory.getContext(), right.getFactHandle(), factory);
+
+ //TODO : Creare una sorta di "resetTupleDegree"
+ ((UncertainRightTuple) right).setDegree(mDeg);
+
+
+ IUncertainDegree joinVal = factory.getAndOperator().eval(((UncertainRightTuple) right).getTruthVal().toArray(new IUncertainDegree[1]));
+ degrees.add(joinVal);
+ ((UncertainRightTuple) rightTuple).resetDegree();
+
+ }
+ IUncertainDegree[] degsArray = new IUncertainDegree[degrees.size()];
+ IUncertainDegree existDegree = factory.getOrOperator().eval(degrees.toArray(degsArray));
+
+
+ if ( existDegree.toBoolean() ) {
+ leftTuple.setBlocker( rightTuple );
+ rightTuple.setBlocked( leftTuple );
+ }
+
+
+ if ( this.tupleMemoryEnabled ) {
+ // this is now blocked so remove it from memory
+ memory.getLeftTupleMemory().remove( leftTuple );
+ }
+
+ Deque<IUncertainDegree> degList = new LinkedList<IUncertainDegree>();
+ degList.add(existDegree);
+ RightTuple exisTuple = new UncertainRightTuple(rightTuple.getFactHandle(),degList,this);
+ this.sink.propagateAssertLeftTuple( leftTuple,
+ exisTuple,
+ context,
+ workingMemory,
+ this.tupleMemoryEnabled );
+
+
+
+
+
+
+
+
+ leftTuple = temp;
+ }
+
+
+
+
+ this.constraints.resetFactHandle( memory.getContext() );
+
+
}
/**
@@ -202,6 +373,8 @@
this.constraints.updateFromFactHandle( memory.getContext(),
workingMemory,
factHandle );
+
+
for ( LeftTuple leftTuple = memory.getLeftTupleMemory().getFirst( rightTuple ); leftTuple != null; ) {
// preserve next now, in case we remove this leftTuple
LeftTuple temp = (LeftTuple) leftTuple.getNext();
Modified: labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2008-08-18 10:42:14 UTC (rev 21599)
+++ labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -113,15 +113,37 @@
this.constraints.updateFromTuple( memory.getContext(),
workingMemory,
leftTuple );
+
+
+
for ( RightTuple rightTuple = memory.getRightTupleMemory().getFirst( leftTuple ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
final InternalFactHandle handle = rightTuple.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
- handle ) ) {
- this.sink.propagateAssertLeftTuple( leftTuple,
- rightTuple,
- context,
- workingMemory,
- this.tupleMemoryEnabled );
+
+
+ if (leftTuple instanceof UncertainLeftTuple) {
+
+ UncertainRightTuple uRightTuple = (UncertainRightTuple) rightTuple;
+ IUncertainDegree deg = this.constraints.matchesCachedLeft(memory.getContext(), handle, ((IUncertainRuleBase) workingMemory.getRuleBase()).getTruthFactory());
+ uRightTuple.setDegree(deg);
+
+ this.sink.propagateAssertLeftTuple( leftTuple,
+ rightTuple,
+ context,
+ workingMemory,
+ this.tupleMemoryEnabled );
+ uRightTuple.resetDegree();
+
+
+ } else {
+
+ if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
+ handle ) ) {
+ this.sink.propagateAssertLeftTuple( leftTuple,
+ rightTuple,
+ context,
+ workingMemory,
+ this.tupleMemoryEnabled );
+ }
}
}
@@ -341,8 +363,10 @@
i++;
+ rightTuple.resetDegree();
}
this.constraints.resetFactHandle( memory.getContext() );
+
}
}
Modified: labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2008-08-18 10:42:14 UTC (rev 21599)
+++ labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -255,7 +255,11 @@
// No external priors, combine class and object compatibility, then set it
IUncertainDegree objPost = isAn(object, factory);
System.out.println("\t ObjectTypeNode : Object vs class match "+objPost);
- posterior = factory.mergeIntersect(objPost, classPrior);
+ /*
+ * TODO: see below
+ * posterior = factory.mergeIntersect(objPost, classPrior);
+ */
+ posterior = factory.getAndOperator().eval(new IUncertainDegree[] {objPost,classPrior});
} else {
if (uncHandle.isOverruling()) {
System.out.println("\t ObjectTypeNode : Keep priors from table");
@@ -266,8 +270,13 @@
System.out.println("\t ObjectTypeNode : Prior info "+objectPrior);
IUncertainDegree objPost = isAn(object, factory);
System.out.println("\t ObjectTypeNode : Object vs class match "+objPost);
- posterior = factory.mergeIntersect(objPost, classPrior);
- posterior = factory.mergeIntersect(objectPrior, posterior);
+ /*
+ * TODO : debate if and-merge or intersect!!!
+ * posterior = factory.mergeIntersect(objPost, classPrior);
+ * posterior = factory.mergeIntersect(objectPrior, posterior);
+ *
+ */
+ posterior = factory.getAndOperator().eval(new IUncertainDegree[] {objPost,objectPrior,classPrior});
}
}
Modified: labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/spi/Activation.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/spi/Activation.java 2008-08-18 10:42:14 UTC (rev 21599)
+++ labs/jbossrules/branches/uncDrools5x/drools-core/src/main/java/org/drools/spi/Activation.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -98,5 +98,7 @@
public RuleFlowGroupNode getRuleFlowGroupNode();
public void setRuleFlowGroupNode(RuleFlowGroupNode ruleFlowGroupNode);
+
+ boolean isNotFalse();
}
\ No newline at end of file
Modified: labs/jbossrules/branches/uncDrools5x/drools-core/src/test/java/org/drools/util/BaseQueueable.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/drools-core/src/test/java/org/drools/util/BaseQueueable.java 2008-08-18 10:42:14 UTC (rev 21599)
+++ labs/jbossrules/branches/uncDrools5x/drools-core/src/test/java/org/drools/util/BaseQueueable.java 2008-08-18 12:12:30 UTC (rev 21600)
@@ -125,4 +125,10 @@
// TODO Auto-generated method stub
}
+
+ @Override
+ public boolean isNotFalse() {
+ // TODO Auto-generated method stub
+ return true;
+ }
}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list