[jboss-svn-commits] JBL Code SVN: r21943 - in labs/jbossrules/branches/uncDrools5x/Essence/src/main/java: uncertainty/factory and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Aug 27 18:05:03 EDT 2008
Author: dsotty
Date: 2008-08-27 18:05:03 -0400 (Wed, 27 Aug 2008)
New Revision: 21943
Modified:
labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/Main.java
labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/factory/EssenceDegreeFactory.java
labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/factory/IDegreeFactory.java
labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/factory/SimpleDegreeFactory.java
labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/Degree.java
labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/DegreeInterval.java
labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/Essence.java
labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/IUncertainDegree.java
labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasAnd.java
labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasOr.java
labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/MaxOr.java
labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/MinAnd.java
labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/ModusPonensOp.java
Log:
New branch for uncertainty support in 5.x
Modified: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/Main.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/Main.java 2008-08-27 22:04:49 UTC (rev 21942)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/Main.java 2008-08-27 22:05:03 UTC (rev 21943)
@@ -24,10 +24,10 @@
import uncertainty.truthvals.DegreeInterval;
import uncertainty.truthvals.Essence;
import uncertainty.truthvals.operators.BRPLOp;
-import uncertainty.truthvals.operators.ModusPonensOp;
import uncertainty.truthvals.operators.TNormOp;
import uncertainty.truthvals.operators.Lukas.LukasAnd;
import uncertainty.truthvals.operators.Lukas.LukasImply;
+import uncertainty.truthvals.operators.Lukas.LukasModusPonensOp;
import uncertainty.truthvals.operators.Lukas.LukasNeg;
import uncertainty.truthvals.operators.aggregators.DempsterShaferAggStrat;
@@ -248,7 +248,7 @@
args[0] = prem;
args[1] = conc;
BRPLOperator implic = new BRPLOperator("testMP",args,e2);
- ModusPonensOp mop = new ModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
+ LukasModusPonensOp mop = new LukasModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
mop.updateConclusion();
@@ -267,7 +267,7 @@
args[0] = prem;
args[1] = conc;
implic = new BRPLOperator("testMP",args,h2h);
- mop = new ModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
+ mop = new LukasModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
mop.updateConclusion();
@@ -281,7 +281,7 @@
args[0] = prem;
args[1] = conc;
implic = new BRPLOperator("testMP",args,r2h);
- mop = new ModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
+ mop = new LukasModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
mop.updateConclusion();
@@ -295,7 +295,7 @@
args[0] = prem;
args[1] = conc;
implic = new BRPLOperator("testMP",args,r2h);
- mop = new ModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
+ mop = new LukasModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
mop.updateConclusion();
prem = new BRPLPredicate("premise",null,heal);
@@ -303,7 +303,7 @@
args[0] = prem;
args[1] = conc;
implic = new BRPLOperator("testMP",args,h2h);
- mop = new ModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
+ mop = new LukasModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
mop.updateConclusion();
happyBob = (Essence) conc.getDegree();
@@ -327,7 +327,7 @@
args[0] = prem;
args[1] = conc;
implic = new BRPLOperator("testMP",args,e2);
- mop = new ModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
+ mop = new LukasModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
mop.updateConclusion();
@@ -342,7 +342,7 @@
args[0] = prem;
args[1] = conc;
implic = new BRPLOperator("testMP",args,e2);
- mop = new ModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
+ mop = new LukasModusPonensOp(implic,new TauPignisticStrategy(),new DempsterShaferAggStrat());
mop.updateConclusion();
Modified: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/factory/EssenceDegreeFactory.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/factory/EssenceDegreeFactory.java 2008-08-27 22:04:49 UTC (rev 21942)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/factory/EssenceDegreeFactory.java 2008-08-27 22:05:03 UTC (rev 21943)
@@ -3,16 +3,21 @@
import uncertainty.truthvals.Essence;
import uncertainty.truthvals.IUncertainDegree;
import uncertainty.truthvals.operators.IUncDegCombiner;
-import uncertainty.truthvals.operators.ModusPonensOp;
+import uncertainty.truthvals.operators.Lukas.AvgInductionOp;
+import uncertainty.truthvals.operators.Lukas.Equiv;
import uncertainty.truthvals.operators.Lukas.LukasAnd;
+import uncertainty.truthvals.operators.Lukas.LukasEquivModusPonensOp;
+import uncertainty.truthvals.operators.Lukas.LukasModusPonensOp;
import uncertainty.truthvals.operators.Lukas.LukasOr;
+import uncertainty.truthvals.operators.Lukas.MaxOr;
+import uncertainty.truthvals.operators.Lukas.MinAnd;
import uncertainty.truthvals.operators.aggregators.DempsterShaferAggStrat;
//TODO : To be specified in much greater detail...
public class EssenceDegreeFactory implements IDegreeFactory {
- private int level = Essence.L20_BOUNDS;
+ private int level = Essence.L0_BASIC;
private int N = Essence.DEF_N;
@@ -34,7 +39,7 @@
public IUncertainDegree buildDegree(double val) {
if (val == 1) return True();
- Essence ans = new Essence(val,1,level);
+ Essence ans = new Essence(val,val,level);
// System.out.println("Factory.degree" + ans);
return ans;
@@ -54,6 +59,11 @@
public IUncDegCombiner getAndOperator() {
return new LukasAnd();
}
+
+ @Override
+ public IUncDegCombiner getEquivOperator() {
+ return new Equiv();
+ }
@Override
public IUncDegCombiner getOrOperator() {
@@ -67,7 +77,7 @@
@Override
public IUncDegCombiner getModusPonensOp() {
- return new ModusPonensOp();
+ return new LukasModusPonensOp();
}
/* (non-Javadoc)
@@ -79,4 +89,24 @@
return getAggregator().eval(new IUncertainDegree[] {d1,d2});
}
+ @Override
+ public IUncDegCombiner getEquivModusPonensOp() {
+ return new LukasEquivModusPonensOp();
+ }
+
+ @Override
+ public IUncDegCombiner getInductionOperator() {
+ return new AvgInductionOp();
+ }
+
+ @Override
+ public IUncDegCombiner getMaxOrOperator() {
+ return new MaxOr();
+ }
+
+ @Override
+ public IUncDegCombiner getMinAndOperator() {
+ return new MinAnd();
+ }
+
}
Modified: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/factory/IDegreeFactory.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/factory/IDegreeFactory.java 2008-08-27 22:04:49 UTC (rev 21942)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/factory/IDegreeFactory.java 2008-08-27 22:05:03 UTC (rev 21943)
@@ -6,6 +6,11 @@
public interface IDegreeFactory {
+
+
+
+
+
public IUncertainDegree buildDegree(double val);
@@ -19,15 +24,27 @@
public IUncDegCombiner getAndOperator();
+ public IUncDegCombiner getMinAndOperator();
+
public IUncDegCombiner getOrOperator();
+ public IUncDegCombiner getMaxOrOperator();
+
+ public IUncDegCombiner getEquivOperator();
+
+
public IUncDegCombiner getAggregator();
public IUncDegCombiner getModusPonensOp();
+ public IUncDegCombiner getEquivModusPonensOp();
+
public IUncertainDegree mergeIntersect(IUncertainDegree d1, IUncertainDegree d2);
+
+
+ public IUncDegCombiner getInductionOperator();
Modified: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/factory/SimpleDegreeFactory.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/factory/SimpleDegreeFactory.java 2008-08-27 22:04:49 UTC (rev 21942)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/factory/SimpleDegreeFactory.java 2008-08-27 22:05:03 UTC (rev 21943)
@@ -3,7 +3,9 @@
import uncertainty.truthvals.Degree;
import uncertainty.truthvals.IUncertainDegree;
import uncertainty.truthvals.operators.IUncDegCombiner;
+import uncertainty.truthvals.operators.simple.SimpleAverage;
import uncertainty.truthvals.operators.simple.SimpleDotAnd;
+import uncertainty.truthvals.operators.simple.SimpleEquiv;
import uncertainty.truthvals.operators.simple.SimpleMaxOr;
import uncertainty.truthvals.operators.simple.SimpleMinAnd;
@@ -39,6 +41,10 @@
return new SimpleMaxOr();
}
+ public IUncDegCombiner getEquivOperator() {
+ return new SimpleEquiv();
+ }
+
@Override
public IUncDegCombiner getAggregator() {
return new SimpleMaxOr();
@@ -63,4 +69,26 @@
return getAggregator().eval(new IUncertainDegree[] {d1,d2});
}
+ @Override
+ public IUncDegCombiner getEquivModusPonensOp() {
+ // TODO Auto-generated method stub
+ return new SimpleDotAnd();
+ }
+
+ @Override
+ public IUncDegCombiner getInductionOperator() {
+ // TODO Auto-generated method stub
+ return new SimpleAverage() ;
+ }
+
+ @Override
+ public IUncDegCombiner getMaxOrOperator() {
+ return new SimpleMaxOr();
+ }
+
+ @Override
+ public IUncDegCombiner getMinAndOperator() {
+ return new SimpleMinAnd();
+ }
+
}
Modified: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/Degree.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/Degree.java 2008-08-27 22:04:49 UTC (rev 21942)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/Degree.java 2008-08-27 22:05:03 UTC (rev 21943)
@@ -93,6 +93,15 @@
public boolean toBoolean() {
return this.value >= 0.5;
}
+
+ @Override
+ public IUncertainDegree pow(double exp) {
+
+ return new Degree(Math.pow(value, exp));
+ }
+ public IUncertainDegree very() {
+ return new Degree(this.value*this.value);
+ }
}
Modified: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/DegreeInterval.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/DegreeInterval.java 2008-08-27 22:04:49 UTC (rev 21942)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/DegreeInterval.java 2008-08-27 22:05:03 UTC (rev 21943)
@@ -59,6 +59,17 @@
this.inf = new Degree(inf);
this.sup = new Degree(sup);
}
+
+
+ /**
+ * Constructor
+ * @param inf lower bound
+ * @param sup upper bound
+ */
+ public DegreeInterval(Degree inf, Degree sup) {
+ this.inf = inf;
+ this.sup = sup;
+ }
/**
* @return
@@ -71,7 +82,15 @@
// return inf >= 0.5;
// ...
}
+
+ @Override
+ public IUncertainDegree pow(double exp) {
+ return new DegreeInterval((Degree) this.inf.pow(exp), (Degree) this.sup.pow(exp));
+ }
+ public IUncertainDegree very() {
+ return new DegreeInterval((Degree) this.inf.very(), (Degree) this.sup.very());
+ }
}
Modified: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/Essence.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/Essence.java 2008-08-27 22:04:49 UTC (rev 21942)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/Essence.java 2008-08-27 22:05:03 UTC (rev 21943)
@@ -24,6 +24,7 @@
import uncertainty.domains.IDomain;
import uncertainty.measures.belief.ImpreciseDistribution;
import uncertainty.measures.probability.ImpreciseProbability;
+import uncertainty.truthvals.operators.Lukas.LukasAnd;
/**
* @author Sotty
@@ -1480,11 +1481,12 @@
* @return The most likely degree (ties broken by choosing lower)
*/
public Degree getDegree() {
- double pmax = p[0];
- int jmax = 0;
- for (int j = 1; j < N; j++)
- if (p[j] > pmax) jmax = j;
- return new Degree(1.0*jmax/N);
+// double pmax = p[0];
+// int jmax = 0;
+// for (int j = 1; j < N; j++)
+// if (p[j] > pmax) jmax = j;
+// return new Degree(1.0*jmax/N);
+ return getAverageDegree();
}
/**
@@ -1662,24 +1664,27 @@
public String toString() {
- StringBuilder s = new StringBuilder("");
- int n = p.length;
+
+// StringBuilder s = new StringBuilder("");
+// int n = p.length;
+//
+// if (pL != null) {
+// for (int j = 0; j < n; j++)
+// s.append(formatt(pL[j],3)).append(" ");
+// s.append("\n");
+// }
+// for (int j = 0; j < n; j++)
+// s.append(formatt(p[j],3)).append(" ");
+// s.append("\t | conf = "+this.getConfidenceFactor());
+// if (pU != null) {
+// s.append("\n");
+// for (int j = 0; j < n; j++)
+// s.append(formatt(pU[j],3)).append(" ");
+// s.append("\n");
+// }
+// return s.toString();
- if (pL != null) {
- for (int j = 0; j < n; j++)
- s.append(formatt(pL[j],3)).append(" ");
- s.append("\n");
- }
- for (int j = 0; j < n; j++)
- s.append(formatt(p[j],3)).append(" ");
- s.append("\t | conf = "+this.getConfidenceFactor());
- if (pU != null) {
- s.append("\n");
- for (int j = 0; j < n; j++)
- s.append(formatt(pU[j],3)).append(" ");
- s.append("\n");
- }
- return s.toString();
+ return this.getAverageDegree().toString();
}
@@ -2208,11 +2213,39 @@
public boolean toBoolean() {
return this.getAverageDegree().toBoolean();
}
+
+
+
+ @Override
+ /**
+ * TODO : Test for correctness
+ */
+ public IUncertainDegree pow(double exp) {
+
+ double[] obs = new double[this.N];
+ double[] priors = new double[this.N];
+
+ for (int j = 0; j < this.N; j++) {
+
+ double x = exp*j - (exp-1)*(N-1);
+ x = Math.max(x, 0);
+ obs[(int) Math.round(x)] += this.beta[j];
+
+ priors[j] = 1.0/this.N;
+ }
+
+
+ Essence ans = new Essence(0.0, priors, obs, this.expCardinality, this.specLevel);
+
+ return ans;
+ }
+ public IUncertainDegree very() {
+ return (Essence) new LukasAnd().eval(new Essence[] {this, this});
+ }
-
Modified: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/IUncertainDegree.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/IUncertainDegree.java 2008-08-27 22:04:49 UTC (rev 21942)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/IUncertainDegree.java 2008-08-27 22:05:03 UTC (rev 21943)
@@ -24,5 +24,16 @@
* @return The most accurate boolean representation of this truth degree
*/
public boolean toBoolean();
+
+
+ /**
+ * Modifier
+ * @param exp
+ * @return The degree, to the power of exp
+ */
+ public IUncertainDegree pow(double exp);
+
+ public IUncertainDegree very();
+
}
Modified: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasAnd.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasAnd.java 2008-08-27 22:04:49 UTC (rev 21942)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasAnd.java 2008-08-27 22:05:03 UTC (rev 21943)
@@ -21,20 +21,17 @@
@Override
public IUncertainDegree evaluate(Essence[] args) {
- Set<List<Integer>>[] map = buildMapBinary(args);
-
-
-// for (int j = 0; j < map.length; j++) {
-// Set<List<Integer>> coups = map[j];
-// System.out.println("Map into "+j);
-// for (List<Integer> c : coups) {
-// System.out.print("<"+c.get(0)+","+c.get(1)+">");
-// System.out.print(" ");
-// }
-// System.out.println();
-// }
-
- return new Essence(args,map);
+
+ Essence ans = args[0];
+ for (int j = 0; j < args.length -1; j++) {
+ Essence[] arg2 = new Essence[] {ans, args[j+1]};
+ Set<List<Integer>>[] map = buildMapBinary(arg2);
+
+ ans = new Essence(arg2,map);
+ }
+
+ return ans;
+
}
/**
Modified: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasOr.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasOr.java 2008-08-27 22:04:49 UTC (rev 21942)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/LukasOr.java 2008-08-27 22:05:03 UTC (rev 21943)
@@ -21,20 +21,16 @@
@Override
public IUncertainDegree evaluate(Essence[] args) {
- Set<List<Integer>>[] map = buildMapBinary(args);
-
-
-// for (int j = 0; j < map.length; j++) {
-// Set<List<Integer>> coups = map[j];
-// System.out.println("Map into "+j);
-// for (List<Integer> c : coups) {
-// System.out.print("<"+c.get(0)+","+c.get(1)+">");
-// System.out.print(" ");
-// }
-// System.out.println();
-// }
-
- return new Essence(args,map);
+
+ Essence ans = args[0];
+ for (int j = 0; j < args.length -1; j++) {
+ Essence[] arg2 = new Essence[] {ans, args[j+1]};
+ Set<List<Integer>>[] map = buildMapBinary(arg2);
+
+ ans = new Essence(arg2,map);
+ }
+
+ return ans;
}
/**
Modified: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/MaxOr.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/MaxOr.java 2008-08-27 22:04:49 UTC (rev 21942)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/MaxOr.java 2008-08-27 22:05:03 UTC (rev 21943)
@@ -21,20 +21,15 @@
@Override
public IUncertainDegree evaluate(Essence[] args) {
- Set<List<Integer>>[] map = buildMapBinary(args);
-
-
-// for (int j = 0; j < map.length; j++) {
-// Set<List<Integer>> coups = map[j];
-// System.out.println("Map into "+j);
-// for (List<Integer> c : coups) {
-// System.out.print("<"+c.get(0)+","+c.get(1)+">");
-// System.out.print(" ");
-// }
-// System.out.println();
-// }
-
- return new Essence(args,map);
+ Essence ans = args[0];
+ for (int j = 0; j < args.length -1; j++) {
+ Essence[] arg2 = new Essence[] {ans, args[j+1]};
+ Set<List<Integer>>[] map = buildMapBinary(arg2);
+
+ ans = new Essence(arg2,map);
+ }
+
+ return ans;
}
/**
Modified: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/MinAnd.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/MinAnd.java 2008-08-27 22:04:49 UTC (rev 21942)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/Lukas/MinAnd.java 2008-08-27 22:05:03 UTC (rev 21943)
@@ -21,20 +21,15 @@
@Override
public IUncertainDegree evaluate(Essence[] args) {
- Set<List<Integer>>[] map = buildMapBinary(args);
-
-
-// for (int j = 0; j < map.length; j++) {
-// Set<List<Integer>> coups = map[j];
-// System.out.println("Map into "+j);
-// for (List<Integer> c : coups) {
-// System.out.print("<"+c.get(0)+","+c.get(1)+">");
-// System.out.print(" ");
-// }
-// System.out.println();
-// }
-
- return new Essence(args,map);
+ Essence ans = args[0];
+ for (int j = 0; j < args.length -1; j++) {
+ Essence[] arg2 = new Essence[] {ans, args[j+1]};
+ Set<List<Integer>>[] map = buildMapBinary(arg2);
+
+ ans = new Essence(arg2,map);
+ }
+
+ return ans;
}
/**
Modified: labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/ModusPonensOp.java
===================================================================
--- labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/ModusPonensOp.java 2008-08-27 22:04:49 UTC (rev 21942)
+++ labs/jbossrules/branches/uncDrools5x/Essence/src/main/java/uncertainty/truthvals/operators/ModusPonensOp.java 2008-08-27 22:05:03 UTC (rev 21943)
@@ -1,222 +1,80 @@
-/*
- * Created on 21/giu/07
- *
- */
-package uncertainty.truthvals.operators;
-
-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.Lukas.LukasAnd;
-import uncertainty.truthvals.operators.Lukas.LukasImply;
-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 ModusPonensOp extends BRPLOp {
-
- /**
- * Reference to the premise
- */
- protected IUncertainPredicate premise;
- /**
- * Getter
- * @return The premise
- */
- public IUncertainPredicate getPremise() { return premise; }
-
-
- /**
- * Reference to the conclusion
- */
- protected IUncertainPredicate conclusion;
- /**
- * Getter
- * @return The conclusion
- */
- public IUncertainPredicate getConclusion() { return conclusion; }
-
-
- /**
- * Reference to the implication operator
- */
- protected IUncertainOperator implication;
- /**
- * Getter
- * @return The implication operator
- */
- protected IUncertainOperator getImplication() { return implication; }
-
- /**
- * Premise Truth value
- */
- protected Essence pTV;
- /**
- * Conclusion Truth value
- */
- protected Essence cTV;
- /**
- * Implication Truth value
- */
- protected Essence iTV;
-
-
- protected IAssignmentStrategy asStrat;
- protected AggregationStrat mgStrat;
-
-
- @Override
-
- /**
- * Evaluation of PxI -> C (single Essence Modus Ponens)
- * Premise truth degree is args[0]
- * Implication truth degree is args[1]
- *
- */
- protected IUncertainDegree evaluate(Essence[] args) {
- this.pTV = args[0];
- this.iTV = args[1];
- return evaluate();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /**
- * Constructor
- * Ghost Ops (not attached to predicates) must
- * be built from scratch
- * @param implic
- */
- public ModusPonensOp(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 ModusPonensOp() {
- 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);
- }
-
-
-
-
-}
+package uncertainty.truthvals.operators;
+
+import uncertainty.measures.probability.conversion.IAssignmentStrategy;
+import uncertainty.predicates.IUncertainOperator;
+import uncertainty.predicates.IUncertainPredicate;
+import uncertainty.truthvals.Essence;
+import uncertainty.truthvals.IUncertainDegree;
+
+public abstract class ModusPonensOp extends BRPLOp {
+
+
+ /**
+ * Reference to the premise
+ */
+ protected IUncertainPredicate premise;
+ /**
+ * Getter
+ * @return The premise
+ */
+ public IUncertainPredicate getPremise() { return premise; }
+
+
+ /**
+ * Reference to the conclusion
+ */
+ protected IUncertainPredicate conclusion;
+ /**
+ * Getter
+ * @return The conclusion
+ */
+ public IUncertainPredicate getConclusion() { return conclusion; }
+
+
+ /**
+ * Reference to the implication operator
+ */
+ protected IUncertainOperator implication;
+ /**
+ * Getter
+ * @return The implication operator
+ */
+ protected IUncertainOperator getImplication() { return implication; }
+
+
+ /**
+ * Premise Truth value
+ */
+ protected Essence pTV;
+ /**
+ * Conclusion Truth value
+ */
+ protected Essence cTV;
+ /**
+ * Implication Truth value
+ */
+ protected Essence iTV;
+
+
+ protected IAssignmentStrategy asStrat;
+ protected AggregationStrat mgStrat;
+
+
+
+
+ /**
+ * Evaluation of PxI -> C (single Essence Modus Ponens)
+ * Premise truth degree is args[0]
+ * Implication truth degree is args[1]
+ *
+ */
+ protected IUncertainDegree evaluate(Essence[] args) {
+ this.pTV = args[0];
+ this.iTV = args[1];
+ return evaluate();
+ }
+
+
+ protected abstract Essence evaluate();
+
+}
More information about the jboss-svn-commits
mailing list