RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package rlpark.plugin.rltoys.algorithms.traces; 00002 00003 import rlpark.plugin.rltoys.math.vector.BinaryVector; 00004 import rlpark.plugin.rltoys.math.vector.MutableVector; 00005 import rlpark.plugin.rltoys.math.vector.RealVector; 00006 import rlpark.plugin.rltoys.math.vector.SparseVector; 00007 import rlpark.plugin.rltoys.math.vector.implementations.SVector; 00008 00009 00013 public class RTraces extends ATraces { 00014 private static final long serialVersionUID = -324210619484987917L; 00015 00016 public RTraces() { 00017 this(DefaultPrototype); 00018 } 00019 00020 public RTraces(MutableVector prototype) { 00021 this(prototype, DefaultThreshold); 00022 } 00023 00024 protected RTraces(MutableVector prototype, double threshold) { 00025 super(prototype, threshold); 00026 } 00027 00028 protected RTraces(MutableVector prototype, double threshold, int size) { 00029 super(prototype, threshold, size); 00030 } 00031 00032 @Override 00033 public RTraces newTraces(int size) { 00034 return new RTraces(prototype, threshold, size); 00035 } 00036 00037 @Override 00038 protected void updateVector(double lambda, RealVector phi) { 00039 vector.mapMultiplyToSelf(lambda); 00040 if (phi instanceof BinaryVector) 00041 replaceWith((BinaryVector) phi); 00042 else 00043 replaceWith((SparseVector) phi); 00044 } 00045 00046 private void replaceWith(SparseVector phi) { 00047 int[] indexes = phi.nonZeroIndexes(); 00048 for (int position = 0; position < phi.nonZeroElements(); position++) { 00049 int index = indexes[position]; 00050 vector.setEntry(index, phi.getEntry(index)); 00051 } 00052 } 00053 00054 private void replaceWith(BinaryVector phi) { 00055 SVector vector = vect(); 00056 int[] indexes = phi.getActiveIndexes(); 00057 for (int index : indexes) 00058 vector.setEntry(index, 1.0); 00059 } 00060 00061 @Override 00062 public SVector vect() { 00063 return (SVector) vector; 00064 } 00065 }