RLPark 1.0.0
Reinforcement Learning Framework in Java

RunInfo.java

Go to the documentation of this file.
00001 package rlpark.plugin.rltoys.experiments.parametersweep.parameters;
00002 
00003 import java.io.Serializable;
00004 import java.util.HashSet;
00005 import java.util.LinkedHashMap;
00006 import java.util.Map;
00007 import java.util.Set;
00008 
00009 public class RunInfo implements Serializable {
00010   private static final long serialVersionUID = 4114752829910485352L;
00011   private final Map<String, Double> infos = new LinkedHashMap<String, Double>();
00012 
00013   public void enableFlag(String flag) {
00014     infos.put(flag, 1.0);
00015   }
00016 
00017   public boolean hasFlag(String flag) {
00018     return infos.containsKey(flag);
00019   }
00020 
00021   public void put(String label, double value) {
00022     infos.put(label, value);
00023   }
00024 
00025   @Override
00026   public int hashCode() {
00027     return FrozenParameters.computeHashcode(infos);
00028   }
00029 
00030   @Override
00031   public boolean equals(Object other) {
00032     if (super.equals(other))
00033       return true;
00034     if (other == null)
00035       return false;
00036     RunInfo o = (RunInfo) other;
00037     Set<String> keysToCheck = new HashSet<String>();
00038     keysToCheck.addAll(o.infos.keySet());
00039     keysToCheck.retainAll(infos.keySet());
00040     for (String key : keysToCheck) {
00041       double thisValue = toDouble(infos.get(key));
00042       double otherValue = toDouble(o.infos.get(key));
00043       if (thisValue != otherValue)
00044         return false;
00045     }
00046     return true;
00047   }
00048 
00049   private double toDouble(Double value) {
00050     return value != null ? (double) value : Double.NaN;
00051   }
00052 
00053   public String[] infoLabels() {
00054     String[] result = new String[infos.size()];
00055     infos.keySet().toArray(result);
00056     return result;
00057   }
00058 
00059   public double[] infoValues() {
00060     double[] result = new double[infos.size()];
00061     int index = 0;
00062     for (Double value : infos.values()) {
00063       result[index] = value;
00064       index++;
00065     }
00066     return result;
00067   }
00068 
00069   public Double get(String name) {
00070     return infos.get(name);
00071   }
00072 
00073   public boolean hasKey(String key) {
00074     return infos.containsKey(key);
00075   }
00076 
00077   @Override
00078   public String toString() {
00079     return infos.toString();
00080   }
00081 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark