[jboss-svn-commits] JBL Code SVN: r21944 - in labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty: truthvals/operators/Lukas and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Aug 27 18:05:57 EDT 2008


Author: dsotty
Date: 2008-08-27 18:05:57 -0400 (Wed, 27 Aug 2008)
New Revision: 21944

Added:
   labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/predicates/IInducible.java
   labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/predicates/IInductor.java
   labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/AvgInductionOp.java
   labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasEquivModusPonensOp.java
   labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasModusPonensOp.java
   labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/simple/SimpleAverage.java
   labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/simple/SimpleEquiv.java
Log:
New branch for uncertainty support in 5.x

Added: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/predicates/IInducible.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/predicates/IInducible.java	                        (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/predicates/IInducible.java	2008-08-27 22:05:57 UTC (rev 21944)
@@ -0,0 +1,9 @@
+package uncertainty.predicates;
+
+import uncertainty.truthvals.IUncertainDegree;
+
+public interface IInducible {
+	
+	public IUncertainDegree getWeight();
+
+}

Added: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/predicates/IInductor.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/predicates/IInductor.java	                        (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/predicates/IInductor.java	2008-08-27 22:05:57 UTC (rev 21944)
@@ -0,0 +1,8 @@
+package uncertainty.predicates;
+
+import uncertainty.truthvals.IUncertainDegree;
+
+public interface IInductor {
+		
+
+}

Added: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/AvgInductionOp.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/AvgInductionOp.java	                        (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/AvgInductionOp.java	2008-08-27 22:05:57 UTC (rev 21944)
@@ -0,0 +1,92 @@
+/*
+ * Created on 21/giu/07
+ *
+ */
+package uncertainty.truthvals.operators.Lukas;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import uncertainty.measures.belief.ImpreciseDistribution;
+import uncertainty.truthvals.Essence;
+import uncertainty.truthvals.IUncertainDegree;
+import uncertainty.truthvals.operators.BRPLOp;
+import uncertainty.truthvals.operators.TCoNormOp;;
+
+/**
+ * @author Sotty
+ *
+ */
+public class AvgInductionOp extends BRPLOp {
+
+    @Override
+    public IUncertainDegree evaluate(Essence[] args) {
+        
+    	//TODO: Use the bounds...
+    	if (args.length == 0) return Essence.Unknown(Essence.DEF_N, Essence.L0_BASIC);
+    	
+    	int N = args[0].getN();
+    	double[][] masses = new double[3][N];
+    	int level = args[0].getSpecLevel();
+    	double wtot = 0;
+    	double conf = 0;
+    	
+    	for (int j = 0; j < args.length; j = j+3) {
+    		Essence integrand = args[j];
+    		Essence constraint = args[j+1];
+    		Essence weight = args[j+2];
+    		
+    		
+    		Essence inductVal = (Essence) new LukasEquivModusPonensOp().eval(new IUncertainDegree[] {integrand, constraint});
+    		
+    		double wgt = weight.getDegree().getValue();
+    		
+    		for (int k = 0; k < N; k++) {
+    			masses[1][k] += inductVal.getMass()[k]*wgt;
+    			
+    			if (inductVal.getSpecLevel() >= Essence.L30_GLOBAL_BOUNDS) {
+    				masses[0][k] += inductVal.getMassL()[k]*wgt;    			
+    				masses[2][k] += inductVal.getMassU()[k]*wgt;    	
+    			}
+    		}
+    		wtot += wgt;
+    		conf += inductVal.getConfidenceFactor()*wgt;
+    		
+    		if (level > integrand.getSpecLevel())
+    			level = integrand.getSpecLevel();
+    		
+    	}
+    	
+    	
+    	for (int k = 0; k < N; k++) {
+    		masses[1][k] /= wtot;
+    		
+    		if (level >= Essence.L30_GLOBAL_BOUNDS) {
+    			masses[0][k] /= wtot;			
+				masses[2][k] /= wtot;    			
+    		}
+		}
+    	conf /= wtot;
+    	
+        return new Essence(new ImpreciseDistribution(masses),conf,level);
+        
+    }
+    
+   /*
+    protected Set<List<Integer>>[] buildMapBinary(Essence[] args) {
+    	throw new RuntimeException("AvgInductionOp: Meaningless operation");
+    }
+    
+    
+   
+    
+    
+    protected static Set<List<Integer>>[] buildStandardMapBinary() {
+        throw new RuntimeException("AvgInductionOp: Meaningless operation");
+    }
+    */
+    
+    
+}

Added: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasEquivModusPonensOp.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasEquivModusPonensOp.java	                        (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasEquivModusPonensOp.java	2008-08-27 22:05:57 UTC (rev 21944)
@@ -0,0 +1,192 @@
+/*
+ * Created on 21/giu/07
+ *
+ */
+package uncertainty.truthvals.operators.Lukas;
+
+import uncertainty.measures.belief.IMassFunction;
+import uncertainty.measures.belief.ImpreciseDistribution;
+import uncertainty.measures.probability.ImpreciseProbability;
+import uncertainty.measures.probability.conversion.IAssignmentStrategy;
+import uncertainty.measures.probability.conversion.TauPignisticStrategy;
+import uncertainty.predicates.IUncertainOperator;
+import uncertainty.predicates.IUncertainPredicate;
+import uncertainty.truthvals.Essence;
+import uncertainty.truthvals.IUncertainDegree;
+import uncertainty.truthvals.operators.AggregationStrat;
+import uncertainty.truthvals.operators.BRPLOp;
+import uncertainty.truthvals.operators.ModusPonensOp;
+import uncertainty.truthvals.operators.NegOp;
+import uncertainty.truthvals.operators.aggregators.DempsterShaferAggStrat;
+
+/**
+ * Modus Ponens
+ * given A/a, A->B/i, computes B/b'
+ *  with b' = f(a,i)
+ *  
+ * More precisely, the computation steps are:
+ *      - compute tau(b) via t-norm composition a x i
+ *      - project tau into a bayesian distribution
+ *      - merge b' with already-known info b 
+ * 
+ * This Op is not to be included in an Operator, since
+ * there is no actual logical symbol for it.
+ * Rather, it is to be applied to have information
+ * flow from premises to conclusions via implications.
+ * 
+ * @author Sotty
+ *
+ */
+public class LukasEquivModusPonensOp extends ModusPonensOp {
+
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    /**
+     * Constructor
+     * Ghost Ops (not attached to predicates) must
+     * be built from scratch
+     * @param implic
+     */
+    public LukasEquivModusPonensOp(IUncertainOperator implic, IAssignmentStrategy projStrat, AggregationStrat mergeStrat) {
+        this.implication = implic;
+            this.iTV = (Essence) implication.getDegree();
+        this.premise = implic.getOperand(0);
+            this.pTV = (Essence) premise.getDegree();
+        this.conclusion = implic.getOperand(1);
+            this.cTV =  (Essence) conclusion.getDegree();
+            
+        this.asStrat = projStrat;
+        this.mgStrat = mergeStrat;
+    }
+    
+    
+    /**
+     * Default Constructor,
+     * for evaluation only.
+     * (No predicates are attached, only truth values)
+     * 
+     * Applies single Modus Ponens (using Lukas And)
+     * Projection is Pignistic
+     * Aggregation is Dempster-Shafer
+     * 
+     */    
+    public LukasEquivModusPonensOp() {    
+    	this.asStrat = new TauPignisticStrategy();
+    	this.mgStrat = new DempsterShaferAggStrat();    	
+    }
+    
+    
+    
+    
+    
+    
+    protected ImpreciseProbability combine() {
+    	NegOp non = new LukasNeg();
+    	
+    	Essence[] mass = new Essence[2];
+    	mass[0] = pTV;
+    	mass[1] = iTV;
+    	
+    	Essence[] massN = new Essence[2];
+    	massN[0] = (Essence) non.eval(new Essence[] {pTV});
+    	massN[1] = iTV;
+    	
+    	boolean withBounds = pTV.getSpecLevel() >= Essence.L20_BOUNDS && iTV.getSpecLevel() >= Essence.L20_BOUNDS;
+
+    	ImpreciseDistribution tau = new ImpreciseDistribution(mass,new LukasAnd().buildMapBinary(mass),withBounds);
+    	ImpreciseDistribution tauN = new ImpreciseDistribution(massN,new LukasAnd().buildMapBinary(massN),withBounds);
+    	
+    	
+    	
+    	
+    	//System.out.println("Tau:\n" + tau);
+
+    	tau.setAssignmentStrategy(this.asStrat);
+    	ImpreciseProbability eps = (ImpreciseProbability) tau.toBayesianMassFunction(withBounds);
+    	
+    	tauN.setAssignmentStrategy(this.asStrat);
+    	ImpreciseProbability epsN = (ImpreciseProbability) tauN.toBayesianMassFunction(withBounds);
+    	epsN = (ImpreciseProbability) non.eval(new Essence[] {new Essence(epsN,pTV.getConfidenceFactor(),pTV.getSpecLevel())});
+    	
+    	//System.out.println("Bayesian eps\n"+eps);
+
+    	//now! discount...
+    	double conf = pTV.getConfidenceFactor()*iTV.getConfidenceFactor();            	                	     	    
+    	eps.discount(conf,-1);
+    	epsN.discount(conf,-1);
+    	
+
+    	return (ImpreciseProbability) this.mgStrat.eval(new IMassFunction[] {eps, epsN});
+    	//System.out.println("Conclusion\n"+cTV);
+    	
+
+    }
+    
+    
+    protected Essence evaluate() {
+    	    	
+    	int level = Math.min(pTV.getSpecLevel(),iTV.getSpecLevel());
+    	double conf = pTV.getConfidenceFactor()*iTV.getConfidenceFactor();
+    	
+    	LukasModusPonensOp mop = new LukasModusPonensOp();
+    	NegOp non = new LukasNeg();
+    		Essence fwd = (Essence) mop.eval(new Essence[] {pTV, iTV});
+    		
+    		Essence nTV = (Essence) non.eval(new Essence[] {pTV});
+    		Essence bkw = (Essence) mop.eval(new Essence[] {nTV, iTV});
+    		bkw = (Essence) non.eval(new Essence[] {bkw});
+    	//TODO: Use combine() instead of MP twice...
+    		
+    	ImpreciseProbability sum = (ImpreciseProbability) this.mgStrat.eval(new ImpreciseProbability[] {fwd, bkw});
+    	    	        
+        return new Essence(sum, conf, level);
+    	    	
+    }
+    
+    
+    /**
+     * Inference mechanism
+     * Updates conclusion from premise and implication
+     *
+     */
+    public void updateConclusion() {
+        // x prod
+    	
+    	double conf = pTV.getConfidenceFactor()*iTV.getConfidenceFactor();
+    	
+    	ImpreciseProbability[] mergeArgs = new ImpreciseProbability[2];
+    	mergeArgs[0] = cTV;
+    	mergeArgs[1] = this.combine();
+//  	... and dempster-merge!
+    	ImpreciseProbability jnt = (ImpreciseProbability) this.mgStrat.eval(mergeArgs);
+
+
+    	// now, an Essence is built!!
+    	conf = conf + cTV.getConfidenceFactor() - conf*cTV.getConfidenceFactor();
+    	Essence concl =  new Essence(jnt,conf,cTV.getSpecLevel());
+
+    	
+        conclusion.setDegree(concl);
+            //System.out.println("Answer definite\n"+ans);              
+    }
+
+    
+    
+
+}

Added: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasModusPonensOp.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasModusPonensOp.java	                        (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasModusPonensOp.java	2008-08-27 22:05:57 UTC (rev 21944)
@@ -0,0 +1,158 @@
+/*
+ * Created on 21/giu/07
+ *
+ */
+package uncertainty.truthvals.operators.Lukas;
+
+import uncertainty.measures.belief.ImpreciseDistribution;
+import uncertainty.measures.probability.ImpreciseProbability;
+import uncertainty.measures.probability.conversion.IAssignmentStrategy;
+import uncertainty.measures.probability.conversion.TauPignisticStrategy;
+import uncertainty.predicates.IUncertainOperator;
+import uncertainty.predicates.IUncertainPredicate;
+import uncertainty.truthvals.Essence;
+import uncertainty.truthvals.IUncertainDegree;
+import uncertainty.truthvals.operators.AggregationStrat;
+import uncertainty.truthvals.operators.BRPLOp;
+import uncertainty.truthvals.operators.ModusPonensOp;
+import uncertainty.truthvals.operators.aggregators.DempsterShaferAggStrat;
+
+/**
+ * Modus Ponens
+ * given A/a, A->B/i, computes B/b'
+ *  with b' = f(a,i)
+ *  
+ * More precisely, the computation steps are:
+ *      - compute tau(b) via t-norm composition a x i
+ *      - project tau into a bayesian distribution
+ *      - merge b' with already-known info b 
+ * 
+ * This Op is not to be included in an Operator, since
+ * there is no actual logical symbol for it.
+ * Rather, it is to be applied to have information
+ * flow from premises to conclusions via implications.
+ * 
+ * @author Sotty
+ *
+ */
+public class LukasModusPonensOp extends ModusPonensOp {
+
+    
+    
+    
+    
+
+    
+    
+    
+    
+    
+    
+    
+    /**
+     * Constructor
+     * Ghost Ops (not attached to predicates) must
+     * be built from scratch
+     * @param implic
+     */
+    public LukasModusPonensOp(IUncertainOperator implic, IAssignmentStrategy projStrat, AggregationStrat mergeStrat) {
+        this.implication = implic;
+            this.iTV = (Essence) implication.getDegree();
+        this.premise = implic.getOperand(0);
+            this.pTV = (Essence) premise.getDegree();
+        this.conclusion = implic.getOperand(1);
+            this.cTV =  (Essence) conclusion.getDegree();
+            
+        this.asStrat = projStrat;
+        this.mgStrat = mergeStrat;
+    }
+    
+    
+    /**
+     * Default Constructor,
+     * for evaluation only.
+     * (No predicates are attached, only truth values)
+     * 
+     * Applies single Modus Ponens (using Lukas And)
+     * Projection is Pignistic
+     * Aggregation is Dempster-Shafer
+     * 
+     */    
+    public LukasModusPonensOp() {    
+    	this.asStrat = new TauPignisticStrategy();
+    	this.mgStrat = new DempsterShaferAggStrat();    	
+    }
+    
+    
+    
+    
+    
+    
+    protected ImpreciseProbability combine() {
+    	
+    	Essence[] mass = new Essence[2];
+    	mass[0] = pTV;
+    	mass[1] = iTV;
+    	boolean withBounds = pTV.getSpecLevel() >= Essence.L20_BOUNDS && iTV.getSpecLevel() >= Essence.L20_BOUNDS;
+
+    	ImpreciseDistribution tau = new ImpreciseDistribution(mass,new LukasAnd().buildMapBinary(mass),withBounds);
+    	//System.out.println("Tau:\n" + tau);
+
+    	tau.setAssignmentStrategy(this.asStrat);
+    	ImpreciseProbability eps = (ImpreciseProbability) tau.toBayesianMassFunction(withBounds);            
+    	//System.out.println("Bayesian eps\n"+eps);
+
+    	//now! discount...
+    	double conf = pTV.getConfidenceFactor()*iTV.getConfidenceFactor();        
+    	//System.out.println("Confidence:" + conf);                    
+    	     	    	
+    	eps.discount(conf,-1);       
+    	//System.out.println("Discounted eps\n:"+eps);
+
+    	//System.out.println("Conclusion\n"+cTV);
+    	return eps;
+
+    }
+    
+    
+    protected Essence evaluate() {
+    	
+    	ImpreciseProbability combo = combine();
+    	int level = Math.min(pTV.getSpecLevel(),iTV.getSpecLevel());
+    	double conf = pTV.getConfidenceFactor()*iTV.getConfidenceFactor();
+    	
+    	return new Essence(combo,conf,level);
+    	    	
+    }
+    
+    
+    /**
+     * Inference mechanism
+     * Updates conclusion from premise and implication
+     *
+     */
+    public void updateConclusion() {
+        // x prod
+    	
+    	double conf = pTV.getConfidenceFactor()*iTV.getConfidenceFactor();
+    	
+    	ImpreciseProbability[] mergeArgs = new ImpreciseProbability[2];
+    	mergeArgs[0] = cTV;
+    	mergeArgs[1] = this.combine();
+//  	... and dempster-merge!
+    	ImpreciseProbability jnt = (ImpreciseProbability) this.mgStrat.eval(mergeArgs);
+
+
+    	// now, an Essence is built!!
+    	conf = conf + cTV.getConfidenceFactor() - conf*cTV.getConfidenceFactor();
+    	Essence concl =  new Essence(jnt,conf,cTV.getSpecLevel());
+
+    	
+        conclusion.setDegree(concl);
+            //System.out.println("Answer definite\n"+ans);              
+    }
+
+    
+    
+
+}


Property changes on: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasModusPonensOp.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/simple/SimpleAverage.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/simple/SimpleAverage.java	                        (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/simple/SimpleAverage.java	2008-08-27 22:05:57 UTC (rev 21944)
@@ -0,0 +1,35 @@
+package uncertainty.truthvals.operators.simple;
+
+import uncertainty.truthvals.Degree;
+import uncertainty.truthvals.Essence;
+import uncertainty.truthvals.IUncertainDegree;
+import uncertainty.truthvals.operators.IUncDegCombiner;
+import uncertainty.truthvals.operators.Lukas.LukasEquivModusPonensOp;
+
+public final class SimpleAverage implements IUncDegCombiner {
+
+	// Args are in sequence <integrand1, weight1>,<integrand2, weight2> ... 
+
+	
+	@Override
+	public IUncertainDegree eval(IUncertainDegree[] args) {
+		double acc = 0;
+		double wgts = 0;
+		SimpleDotAnd op = new SimpleDotAnd();
+
+		// So the number of elements is actually twice		
+		for (int j = 0; j < args.length; j = j+3) {
+			Degree integrand = (Degree) args[j];
+			Degree constraint = (Degree) args[j+1];
+			Degree weight = (Degree) args[j+2];
+    		
+			IUncertainDegree inductVal = op.eval(new IUncertainDegree[] {integrand, constraint});
+			
+			acc += inductVal.getDegree().getValue()*weight.getDegree().getValue();
+			wgts += weight.getDegree().getValue();
+    	}
+										
+		return new Degree(acc / wgts);
+	}
+
+}

Added: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/simple/SimpleEquiv.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/simple/SimpleEquiv.java	                        (rev 0)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/simple/SimpleEquiv.java	2008-08-27 22:05:57 UTC (rev 21944)
@@ -0,0 +1,16 @@
+package uncertainty.truthvals.operators.simple;
+
+import uncertainty.truthvals.Degree;
+import uncertainty.truthvals.IUncertainDegree;
+import uncertainty.truthvals.operators.IUncDegCombiner;
+
+public class SimpleEquiv implements IUncDegCombiner {
+
+	@Override
+	public IUncertainDegree eval(IUncertainDegree[] args) {
+		
+		
+		return new Degree(1 - Math.abs(args[0].getDegree().getValue() - args[1].getDegree().getValue()));
+	}
+
+}




More information about the jboss-svn-commits mailing list