00001
00002
00003
00004
00005
00006
00007 package edu.tum.cs.srl.bayesnets;
00008
00009 import java.util.Vector;
00010
00011 public enum CombiningRule {
00012 NoisyOr("noisy-or", true) {
00013 @Override
00014 public double compute(Vector<Double> values) {
00015 double prod = 0.0;
00016 for(Double v : values)
00017 prod += Math.log(1.0 - v);
00018 return 1.0 - Math.exp(prod);
00019 }
00020 },
00021
00022 NoisyAnd("noisy-and", true) {
00023 @Override
00024 public double compute(Vector<Double> values) {
00025 double prod = 1.0;
00026 for(Double v : values)
00027 prod *= v;
00028 return prod;
00029 }
00030 },
00031
00032 Average("average", true) {
00033 @Override
00034 public double compute(Vector<Double> values) {
00035 double sum = 0.0;
00036 for(Double v : values)
00037 sum += v;
00038 return sum / values.size();
00039 }
00040 },
00041
00042 Maximum("max", true) {
00043 @Override
00044 public double compute(Vector<Double> values) {
00045 double max = 0.0;
00046 for(Double v : values)
00047 max = Math.max(max, v);
00048 return max;
00049 }
00050 },
00051
00052 Minimum("min", true) {
00053 @Override
00054 public double compute(Vector<Double> values) {
00055 double min = 1.0;
00056 for(Double v : values)
00057 min = Math.min(min, v);
00058 return min;
00059 }
00060 },
00061
00062 NoisyOrNormalized("noisy-or-n", false) {
00063 @Override
00064 public double compute(Vector<Double> values) {
00065 double prod = 0.0;
00066 for(Double v : values)
00067 prod += Math.log(1.0 - v);
00068 return 1.0 - Math.exp(prod);
00069 }
00070 },
00071
00072 NoisyAndNormalized("noisy-and-n", false) {
00073 @Override
00074 public double compute(Vector<Double> values) {
00075 double prod = 1.0;
00076 for(Double v : values)
00077 prod *= v;
00078 return prod;
00079 }
00080 };
00081
00082 public String stringRepresention;
00083 public boolean booleanSemantics;
00084
00085 private CombiningRule(String stringRepresentation, boolean booleanSemantics) {
00086 this.stringRepresention = stringRepresentation;
00087 this.booleanSemantics = booleanSemantics;
00088 }
00089
00090 public static CombiningRule fromString(String s) {
00091 for(CombiningRule r : CombiningRule.values())
00092 if(r.stringRepresention.equals(s))
00093 return r;
00094 throw new IllegalArgumentException("No such combining rule");
00095 }
00096
00097 public abstract double compute(Vector<Double> values);
00098 }