package positronic.ai.learner.maip; import java.io.PrintStream; import java.util.HashMap; import java.util.Map; public class Maip { private Map backing; /** * Sets the lower limit on the size of the Maip's backing map. */ private int minPopulation; /** * The positive number which defines the desired probability of successful * performance by the Learner object. Note: in practice, there is no * point in specifying quality values of less than or equal to 0.5, or greater * than or equal to 1.0. Specifying a positive value less than 0.5 is * equivalent to specifying 0.5, and specifying a value greater than 1.0 is * practically equivalent to specifying 1.0. */ private double quality; /** * * The positive number defining successful performance by the learner object. * That is, if the distance between the correct answer and the learner's answer * is not greater than tolerance, then the learner's performance * in this case is considered successful. Otherwise, its performance is * considered unsuccessful. */ private double tolerance; /** * Constructs a new instance of the Learner class with * tolerance=.1 and quality=.9. */ public Maip() { this(.1,.9); } /** * Constructs a new instance of the Learner class with specified * values of tolerance and quality. */ public Maip(double tolerance, double quality) { backing=new HashMap(); this.tolerance=tolerance; this.quality=quality; } /** * Prints the underlying HashSet to System.out. */ public void print() { print(System.out); } /** * Prints the underlying HashSet to a PrintStream. */ public void print(PrintStream ps) { for(Metrizable p : backing.keySet()) ps.println(p+"\t->\t"+backing.get(p)); } public Metrizable get(Metrizable p) { Metrizable b=this.nearestPoint(p); return backing.get(b); } public Map getBacking() { return backing; } public int getMinPopulation() { return minPopulation; } public double getQuality() { return quality; } public double getTolerance() { return tolerance; } /** * Returns the Metrizable key object in Maip * which is closest to domainPoint. */ public Metrizable nearestPoint(Metrizable domainPoint) { Metrizable nearestPoint=null; double leastDistance=Double.POSITIVE_INFINITY; for(Metrizable point : backing.keySet()) { double distancePointToCurrent=domainPoint.distance(point); if(distancePointToCurrentthis.getTolerance()) { backing.put(d, r); return r; } else if(Math.random()<=1./this.getQuality()-1.) { backing.remove(res); } return null; } public void setMinPopulation(int minPopulation) { this.minPopulation = minPopulation; } public void setQuality(double quality) { this.quality = quality; } public void setTolerance(double tolerance) { this.tolerance = tolerance; } public int size() { return backing.size(); } }