RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package rlpark.plugin.rltoys.problems.puddleworld; 00002 00003 public class TargetReachedL2NormTermination implements TerminationFunction { 00004 private final double[] target; 00005 private final double tolerance; 00006 00007 public TargetReachedL2NormTermination(double[] target, double tolerance) { 00008 assert tolerance > 0; 00009 this.target = target; 00010 this.tolerance = tolerance; 00011 } 00012 00013 @Override 00014 public boolean isTerminated(double[] position) { 00015 double distance = 0.0; 00016 assert position.length == target.length; 00017 for (int i = 0; i < position.length; i++) { 00018 double diff = target[i] - position[i]; 00019 distance += diff * diff; 00020 } 00021 distance = Math.sqrt(distance); 00022 return distance < tolerance; 00023 } 00024 }