RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package rlpark.plugin.rltoys.algorithms.representations.observations; 00002 00003 import rlpark.plugin.rltoys.envio.observations.Legend; 00004 import rlpark.plugin.rltoys.math.normalization.MinMaxNormalizer; 00005 import rlpark.plugin.rltoys.math.ranges.Range; 00006 import zephyr.plugin.core.api.monitoring.annotations.LabelProvider; 00007 import zephyr.plugin.core.api.monitoring.annotations.Monitor; 00008 00009 public class ObsNormalizers { 00010 private final MinMaxNormalizer[] normalizers; 00011 private final Legend legend; 00012 @Monitor(level = 1) 00013 private final double[] normalized; 00014 00015 public ObsNormalizers(Legend legend) { 00016 normalizers = new MinMaxNormalizer[legend.nbLabels()]; 00017 for (int i = 0; i < normalizers.length; i++) 00018 normalizers[i] = new MinMaxNormalizer(); 00019 normalized = new double[normalizers.length]; 00020 this.legend = legend; 00021 } 00022 00023 public Legend legend() { 00024 return legend; 00025 } 00026 00027 @LabelProvider(ids = { "normalized" }) 00028 protected String label(int index) { 00029 return legend.label(index); 00030 } 00031 00032 public Range[] getRanges() { 00033 Range[] ranges = new Range[normalizers.length]; 00034 for (int i = 0; i < ranges.length; i++) 00035 ranges[i] = normalizers[i].targetRange(); 00036 return ranges; 00037 } 00038 00039 public double[] update(double[] o) { 00040 if (o == null) 00041 return null; 00042 for (int i = 0; i < o.length; i++) { 00043 normalizers[i].update(o[i]); 00044 normalized[i] = normalizers[i].normalize(o[i]); 00045 } 00046 return normalized; 00047 } 00048 }