RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package rlpark.plugin.rltoys.algorithms.traces; 00002 00003 import rlpark.plugin.rltoys.math.vector.MutableVector; 00004 import rlpark.plugin.rltoys.math.vector.implementations.SVector; 00005 00009 public class AMaxTraces extends ATraces { 00010 private static final long serialVersionUID = 8063854269195146376L; 00011 final static public double DefaultMaximumValue = 1.0; 00012 private final double maximumValue; 00013 00014 public AMaxTraces() { 00015 this(DefaultPrototype); 00016 } 00017 00018 public AMaxTraces(MutableVector prototype) { 00019 this(prototype, DefaultMaximumValue); 00020 } 00021 00022 public AMaxTraces(double maximumValue) { 00023 this(DefaultPrototype, maximumValue, DefaultThreshold); 00024 } 00025 00026 public AMaxTraces(MutableVector prototype, double maximumValue) { 00027 this(prototype, maximumValue, DefaultThreshold); 00028 } 00029 00030 public AMaxTraces(MutableVector prototype, double maximumValue, double threshold) { 00031 this(prototype, maximumValue, threshold, 0); 00032 } 00033 00034 protected AMaxTraces(MutableVector prototype, double maximumValue, double threshold, int size) { 00035 super(prototype, threshold, size); 00036 this.maximumValue = maximumValue; 00037 } 00038 00039 @Override 00040 public AMaxTraces newTraces(int size) { 00041 return new AMaxTraces(prototype, maximumValue, threshold, size); 00042 } 00043 00044 @Override 00045 protected void adjustUpdate() { 00046 final boolean isSVector = vector instanceof SVector; 00047 double[] data = isSVector ? ((SVector) vector).values : vector.accessData(); 00048 int length = isSVector ? ((SVector) vector).nonZeroElements() : vector.getDimension(); 00049 adjustValues(data, length); 00050 } 00051 00052 private void adjustValues(double[] data, int length) { 00053 for (int i = 0; i < length; i++) 00054 data[i] = adjustValue(data[i]); 00055 } 00056 00057 private double adjustValue(double value) { 00058 if (Math.abs(value) <= maximumValue) 00059 return value; 00060 return Math.signum(value) * maximumValue; 00061 } 00062 }