00001
00002
00003
00004
00005
00006
00007 package edu.tum.cs.srl.bayesnets.inference;
00008
00009 import java.lang.reflect.Constructor;
00010
00011 import edu.tum.cs.bayesnets.core.BeliefNetworkEx;
00012 import edu.tum.cs.bayesnets.inference.BNJPearl;
00013 import edu.tum.cs.bayesnets.inference.BackwardSampling;
00014 import edu.tum.cs.bayesnets.inference.BackwardSamplingWithChildren;
00015 import edu.tum.cs.bayesnets.inference.BackwardSamplingWithPriors;
00016 import edu.tum.cs.bayesnets.inference.BeliefPropagation;
00017 import edu.tum.cs.bayesnets.inference.EnumerationAsk;
00018 import edu.tum.cs.bayesnets.inference.IJGP;
00019 import edu.tum.cs.bayesnets.inference.LikelihoodWeighting;
00020 import edu.tum.cs.bayesnets.inference.LikelihoodWeightingWithUncertainEvidence;
00021 import edu.tum.cs.bayesnets.inference.SampleSearch;
00022 import edu.tum.cs.bayesnets.inference.SmileBackwardSampling;
00023 import edu.tum.cs.bayesnets.inference.SmileEPIS;
00024 import edu.tum.cs.bayesnets.inference.SmilePearl;
00025 import edu.tum.cs.bayesnets.inference.VariableElimination;
00026 import edu.tum.cs.srl.bayesnets.bln.AbstractGroundBLN;
00027
00028 public enum Algorithm {
00029 LikelihoodWeighting("likelihood weighting", null, LikelihoodWeighting.class),
00030 LWU("likelihood weighting with uncertain evidence", null, LikelihoodWeightingWithUncertainEvidence.class),
00031 GibbsSampling("Gibbs sampling (MCMC)", GibbsSampling.class, null),
00032 EPIS("importance sampling based on evidence prepropagation [SMILE]", null, SmileEPIS.class),
00033 BackwardSampling("backward simulation", null, BackwardSampling.class),
00034 BackwardSamplingPriors("backward simulation with prior bias", null, BackwardSamplingWithPriors.class),
00035 BackwardSamplingChildren("backward simulation with extended context", null, BackwardSamplingWithChildren.class),
00036 LiftedBackwardSampling("a lifted version of backw. sampling with ext. context", LiftedBackwardSampling.class, null),
00037 SmileBackwardSampling("backward simulation [SMILE]", null, SmileBackwardSampling.class),
00038 SATIS("SAT-IS: satisfiability-based importance sampling", SATIS.class, null),
00039 SATISEx("SAT-IS, extended with constraints from CPDs", SATISEx.class, null),
00040 SATISExGibbs("SAT-IS extended with interspersed Gibbs Sampling steps", SATISExGibbs.class, null),
00041 SampleSearch("SampleSearch: backtracking search for satisfiable states", null, SampleSearch.class),
00042 MCSAT("MC-SAT (MCMC method based on SAT-solving)", MCSAT.class, null),
00043 IJGP("Iterative Join-Graph Propagation", null, IJGP.class),
00044 BeliefPropagation("Belief Propagation", null, BeliefPropagation.class),
00045 EnumerationAsk("Enumeration-Ask (exact, highly inefficient)", null, EnumerationAsk.class),
00046 Pearl("Pearl's algorithm for polytrees (exact)", null, BNJPearl.class),
00047 SmilePearl("Pearl's algorithm for polytrees (exact) [SMILE]", null, SmilePearl.class),
00048 VarElim("variable elimination (exact)", null, VariableElimination.class),
00049 Experimental("an experimental algorithm (usually beta)", "dev.SampleSearchIB"),
00050 Experimental2("an experimental algorithm (usually beta)", "dev.SampleSearchIBLearning"),
00051 Experimental3("an experimental algorithm (usually beta)", "dev.SampleSearch2");
00052
00053 protected String description;
00054 protected Class<? extends edu.tum.cs.bayesnets.inference.Sampler> bnClass;
00055 protected Class<? extends Sampler> blnClass;
00056
00057 private Algorithm(String description, Class<? extends Sampler> blnClass, Class<? extends edu.tum.cs.bayesnets.inference.Sampler> bnClass) {
00058 this.description = description;
00059 this.blnClass = blnClass;
00060 this.bnClass = bnClass;
00061 }
00062
00068 @SuppressWarnings("unchecked")
00069 private Algorithm(String description, String className) {
00070 this.description = description;
00071 try {
00072 Class<?> cl = Class.forName(className);
00073 try {
00074 cl.getConstructor(BeliefNetworkEx.class);
00075 bnClass = (Class<? extends edu.tum.cs.bayesnets.inference.Sampler>)cl;
00076 }
00077 catch(Exception e) {
00078 blnClass = (Class<? extends Sampler>)cl;
00079 }
00080 }
00081 catch(ClassNotFoundException e) {
00082 }
00083 }
00084
00085 public String getDescription() {
00086 return description;
00087 }
00088
00089 public Sampler createSampler(AbstractGroundBLN gbln) throws Exception {
00090 Sampler sampler = null;
00091 if(bnClass != null) {
00092 sampler = new BNSampler(gbln, bnClass);
00093 }
00094 else if(blnClass != null) {
00095 Constructor<? extends Sampler> constructor;
00096 try {
00097 constructor = blnClass.getConstructor(gbln.getClass());
00098 }
00099 catch(NoSuchMethodException e) {
00100 throw new Exception("Don't know how to instantiate a sampler for the algorithm '" + toString() + "'");
00101 }
00102 sampler = constructor.newInstance(gbln);
00103 }
00104 else
00105 throw new Exception("Cannot instantiate a sampler for the algorithm '" + toString() + "' - sampler class not given");
00106 return sampler;
00107 }
00108
00109 public static void printList(String indentation) {
00110 for(Algorithm a : Algorithm.values())
00111 System.out.printf("%s%-28s %s\n", indentation, a.toString(), a.getDescription());
00112 }
00113 }