/** * Gets all the points neighboring the given point. These will be points * that are at most eps (radius) away from the given point. Uses the spatial * index (KD tree) if the metric is a Metric and points are Vectorizable. * Otherwise, performs a brute-force search. * * @param point The point to get the neighborhood for. * @return */ private List<DataType> regionQuery(DataType point) { List<DataType> result; if (this.metric instanceof Metric) { result = this.spatialIndex.findNearestWithinRadius( point, this.eps, (Metric<? super DataType>) this.metric) .stream() .map(pair -> pair.getFirst()) .collect(Collectors.toList()); } else { result = this.points.stream() .filter((p) -> (this.metric.evaluate(p, point) <= this.eps)) .collect(Collectors.toList()); } return result; }
/** * Gets the target value of the given training example index, as a double. * * @param i * The training example index. Must be between 0 and dataSize - 1. * @return * The target value for that index represented as a double, which is * either +1.0 or -1.0. */ private double getTarget( final int i) { return this.dataList.get(i).getOutput() ? +1.0 : -1.0; }
/** * Gets the input value of the given training example index. * * @param i * The training example index. Must be between 0 and dataSize - 1. * @return * The input value for that index. */ private InputType getPoint( final int i) { return this.dataList.get(i).getInput(); }
/** * Gets the performance, which is the cost of the minimizer on the last * iteration. * * @return The performance of the algorithm. */ public NamedValue<Double> getPerformance() { Double performance = (this.getAlgorithm().getResult() != null) ? this.getAlgorithm().getResult().getSecond() : null; return new DefaultNamedValue<Double>( "cost", performance ); } }
/** * Gets the target value of the given training example index, as a double. * * @param i * The training example index. Must be between 0 and dataSize - 1. * @return * The target value for that index represented as a double, which is * either +1.0 or -1.0. */ private double getTarget( final int i) { return this.dataList.get(i).getOutput() ? +1.0 : -1.0; }
/** * Gets the input value of the given training example index. * * @param i * The training example index. Must be between 0 and dataSize - 1. * @return * The input value for that index. */ private InputType getPoint( final int i) { return this.dataList.get(i).getInput(); }
/** * Gets the performance, which is the cost of the minimizer on the last * iteration. * * @return The performance of the algorithm. */ public NamedValue<Double> getPerformance() { Double performance = (this.getAlgorithm().getResult() != null) ? this.getAlgorithm().getResult().getSecond() : null; return new DefaultNamedValue<Double>( "cost", performance ); } }
/** * Gets the target value of the given training example index, as a double. * * @param i * The training example index. Must be between 0 and dataSize - 1. * @return * The target value for that index represented as a double, which is * either +1.0 or -1.0. */ private double getTarget( final int i) { return this.dataList.get(i).getOutput() ? +1.0 : -1.0; }
/** * Sorts score estimates for the ROC create() method * * @param o1 First score * @param o2 Second score * @return -1 if o1<o2, +1 if o1>o2, 0 if o1=02 */ @Override public int compare( InputOutputPair<Double,? extends Object> o1, InputOutputPair<Double,? extends Object> o2) { if( o1.getInput() < o2.getInput() ) { return -1; } else if( o1.getInput() > o2.getInput() ) { return +1; } else { return 0; } } }
/** * Gets the performance, which is the cost of the minimizer on the last * iteration. * * @return The performance of the algorithm. */ public NamedValue<Double> getPerformance() { Double performance = (this.getAlgorithm().getResult() != null) ? this.getAlgorithm().getResult().getSecond() : null; return new DefaultNamedValue<Double>( "cost", performance ); } }
/** * Gets all the points neighboring the given point. These will be points * that are at most eps (radius) away from the given point. Uses the spatial * index (KD tree) if the metric is a Metric and points are Vectorizable. * Otherwise, performs a brute-force search. * * @param point The point to get the neighborhood for. * @return */ private List<DataType> regionQuery(DataType point) { List<DataType> result; if (this.metric instanceof Metric) { result = this.spatialIndex.findNearestWithinRadius( point, this.eps, (Metric<? super DataType>) this.metric) .stream() .map(pair -> pair.getFirst()) .collect(Collectors.toList()); } else { result = this.points.stream() .filter((p) -> (this.metric.evaluate(p, point) <= this.eps)) .collect(Collectors.toList()); } return result; }
/** * Returns a set of all the known categories. * * @return */ @Override public Set<? extends CategoryType> getCategories() { Set<CategoryType> cats = new HashSet<CategoryType>(); for (InputOutputPair<? extends Vector, CategoryType> pair : learner.trainingSet) { cats.add(pair.getOutput()); } return cats; }
/** * Gets the input value of the given training example index. * * @param i * The training example index. Must be between 0 and dataSize - 1. * @return * The input value for that index. */ private InputType getPoint( final int i) { return this.dataList.get(i).getInput(); }
/** * Gets all the points neighboring the given point. These will be points * that are at most eps (radius) away from the given point. Uses the spatial * index (KD tree) if the metric is a Metric and points are Vectorizable. * Otherwise, performs a brute-force search. * * @param point The point to get the neighborhood for. * @return */ private List<DataType> regionQuery(DataType point) { List<DataType> result; if (this.metric instanceof Metric) { result = this.spatialIndex.findNearestWithinRadius( point, this.eps, (Metric<? super DataType>) this.metric) .stream() .map(pair -> pair.getFirst()) .collect(Collectors.toList()); } else { result = this.points.stream() .filter((p) -> (this.metric.evaluate(p, point) <= this.eps)) .collect(Collectors.toList()); } return result; }
@Override public <InputType> void update( final DefaultKernelBinaryCategorizer<InputType> target, final InputType input, final Boolean output) { this.update(target, input, (boolean) output); }
/** * Returns a set of all the known categories. * * @return */ @Override public Set<? extends CategoryType> getCategories() { Set<CategoryType> cats = new HashSet<CategoryType>(); for (InputOutputPair<? extends Vector, CategoryType> pair : learner.trainingSet) { cats.add(pair.getOutput()); } return cats; }