RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package rlpark.plugin.rltoys.agents.functions; 00002 00003 00004 import java.awt.geom.Point2D; 00005 00006 import rlpark.plugin.rltoys.algorithms.functions.Predictor; 00007 import rlpark.plugin.rltoys.algorithms.functions.states.Projector; 00008 import rlpark.plugin.rltoys.envio.rl.TRStep; 00009 import rlpark.plugin.rltoys.problems.ProblemBounded; 00010 import zephyr.plugin.core.api.viewable.ContinuousFunction2D; 00011 import zephyr.plugin.core.api.viewable.PositionFunction2D; 00012 00013 public class ValueFunction2D extends FunctionProjected2D implements ContinuousFunction2D, PositionFunction2D { 00014 final Predictor predictor; 00015 final ProblemBounded problem; 00016 00017 public ValueFunction2D(Projector projector, ProblemBounded problem, Predictor predictor) { 00018 super(projector, problem.getObservationRanges()[0], problem.getObservationRanges()[1]); 00019 assert problem.getObservationRanges().length == 2; 00020 this.predictor = predictor; 00021 this.problem = problem; 00022 } 00023 00024 @Override 00025 public Point2D position() { 00026 TRStep step = problem.lastStep(); 00027 if (step == null || step.o_tp1 == null) 00028 return null; 00029 return new Point2D.Double(step.o_tp1[0], step.o_tp1[1]); 00030 } 00031 00032 @Override 00033 public double value(double x, double y) { 00034 return predictor.predict(projector.project(new double[] { x, y })); 00035 } 00036 }