RLPark 1.0.0
Reinforcement Learning Framework in Java

TabularActionDiscretizer.java

Go to the documentation of this file.
00001 package rlpark.plugin.rltoys.algorithms.representations.discretizer;
00002 
00003 import java.util.LinkedHashMap;
00004 import java.util.Map;
00005 
00006 import rlpark.plugin.rltoys.envio.actions.Action;
00007 
00008 public class TabularActionDiscretizer implements ActionDiscretizer {
00009   private static final long serialVersionUID = 9160060017385719505L;
00010   protected final Map<Action, Double> actionToDouble = new LinkedHashMap<Action, Double>();
00011 
00012   public TabularActionDiscretizer(Action[] actions) {
00013     for (int i = 0; i < actions.length; i++)
00014       actionToDouble.put(actions[i], (double) i);
00015   }
00016 
00017   @Override
00018   public double[] discretize(Action action) {
00019     return new double[] { actionToDouble.get(action) };
00020   }
00021 
00022   @Override
00023   public int nbOutput() {
00024     return 1;
00025   }
00026 
00027   @Override
00028   public Discretizer[] actionDiscretizers() {
00029     return new Discretizer[] { new Discretizer() {
00030       private static final long serialVersionUID = -1484841782654103099L;
00031 
00032       @Override
00033       public int resolution() {
00034         return actionToDouble.size();
00035       }
00036 
00037       @Override
00038       public int discretize(double input) {
00039         return (int) input;
00040       }
00041     } };
00042   }
00043 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark