protected boolean initializeAlgorithm() { if (this.getData() == null) { // Error: No data to learn on. return false; } // Count the number of valid examples. int validCount = 0; for (InputOutputPair<? extends InputType, Double> example : this.getData()) { if (example != null) { validCount++; } } if (validCount <= 0) { // Nothing to perform learning on. return false; } // Set up the learning variables. this.setErrorCount( validCount ); this.setSupportsMap( new LinkedHashMap<InputOutputPair<? extends InputType, Double>, DefaultWeightedValue<InputType>>() ); this.setResult( new KernelScalarFunction<InputType>( this.getKernel(), this.getSupportsMap().values(), 0.0 ) ); return true; }
@Override public KernelBasedIterativeRegression<InputType> clone() { KernelBasedIterativeRegression<InputType> clone = (KernelBasedIterativeRegression<InputType>) super.clone(); clone.setKernel( ObjectUtil.cloneSmart( this.getKernel() ) ); clone.setResult( ObjectUtil.cloneSafe( this.getResult() ) ); clone.setSupportsMap( ObjectUtil.cloneSmart( this.getSupportsMap() ) ); return clone; }
/** * Creates a new KernelBasedIterativeRegression with the given kernel and * maximum number of iterations. * * @param kernel The kernel to use. * @param minSensitivity The minimum sensitivity to errors. * @param maxIterations The maximum number of iterations. */ public KernelBasedIterativeRegression( final Kernel<? super InputType> kernel, final double minSensitivity, final int maxIterations ) { super( maxIterations ); this.setKernel( kernel ); this.setMinSensitivity( minSensitivity ); this.setResult( null ); this.setErrorCount( 0 ); this.setSupportsMap( null ); }
protected void cleanupAlgorithm() { if (this.getSupportsMap() != null) { // Make the result object have a more efficient backing collection // at the end. this.getResult().setExamples( new ArrayList<WeightedValue<InputType>>( this.getSupportsMap().values() ) ); this.setSupportsMap( null ); } }
protected boolean step() this.setErrorCount( 0 ); if (this.getData().size() == 1) this.getData().iterator().next(); this.getResult().getExamples().clear(); this.getResult().setBias( first.getOutput() ); return false; for (InputOutputPair<? extends InputType, Double> example : this.getData()) this.setErrorCount( this.getErrorCount() + 1 ); return this.getErrorCount() > 0;
/** * Gets the performance, which is the error count on the last iteration. * * @return The performance of the algorithm. */ public NamedValue<Integer> getPerformance() { return new DefaultNamedValue<Integer>("error count", this.getErrorCount()); } }
protected boolean step() this.setErrorCount( 0 ); if (this.getData().size() == 1) this.getData().iterator().next(); this.getResult().getExamples().clear(); this.getResult().setBias( first.getOutput() ); return false; for (InputOutputPair<? extends InputType, Double> example : this.getData()) this.setErrorCount( this.getErrorCount() + 1 ); return this.getErrorCount() > 0;
protected void cleanupAlgorithm() { if (this.getSupportsMap() != null) { // Make the result object have a more efficient backing collection // at the end. this.getResult().setExamples( new ArrayList<WeightedValue<InputType>>( this.getSupportsMap().values() ) ); this.setSupportsMap( null ); } }
/** * Gets the performance, which is the error count on the last iteration. * * @return The performance of the algorithm. */ public NamedValue<Integer> getPerformance() { return new DefaultNamedValue<Integer>("error count", this.getErrorCount()); } }
@Override public KernelBasedIterativeRegression<InputType> clone() { KernelBasedIterativeRegression<InputType> clone = (KernelBasedIterativeRegression<InputType>) super.clone(); clone.setKernel( ObjectUtil.cloneSmart( this.getKernel() ) ); clone.setResult( ObjectUtil.cloneSafe( this.getResult() ) ); clone.setSupportsMap( ObjectUtil.cloneSmart( this.getSupportsMap() ) ); return clone; }
protected boolean initializeAlgorithm() { if (this.getData() == null) { // Error: No data to learn on. return false; } // Count the number of valid examples. int validCount = 0; for (InputOutputPair<? extends InputType, Double> example : this.getData()) { if (example != null) { validCount++; } } if (validCount <= 0) { // Nothing to perform learning on. return false; } // Set up the learning variables. this.setErrorCount( validCount ); this.setSupportsMap( new LinkedHashMap<InputOutputPair<? extends InputType, Double>, DefaultWeightedValue<InputType>>() ); this.setResult( new KernelScalarFunction<InputType>( this.getKernel(), this.getSupportsMap().values(), 0.0 ) ); return true; }
/** * Creates a new KernelBasedIterativeRegression with the given kernel and * maximum number of iterations. * * @param kernel The kernel to use. * @param minSensitivity The minimum sensitivity to errors. * @param maxIterations The maximum number of iterations. */ public KernelBasedIterativeRegression( final Kernel<? super InputType> kernel, final double minSensitivity, final int maxIterations ) { super( maxIterations ); this.setKernel( kernel ); this.setMinSensitivity( minSensitivity ); this.setResult( null ); this.setErrorCount( 0 ); this.setSupportsMap( null ); }
protected boolean step() this.setErrorCount( 0 ); if (this.getData().size() == 1) this.getData().iterator().next(); this.getResult().getExamples().clear(); this.getResult().setBias( first.getOutput() ); return false; for (InputOutputPair<? extends InputType, Double> example : this.getData()) this.setErrorCount( this.getErrorCount() + 1 ); return this.getErrorCount() > 0;
protected void cleanupAlgorithm() { if (this.getSupportsMap() != null) { // Make the result object have a more efficient backing collection // at the end. this.getResult().setExamples( new ArrayList<WeightedValue<InputType>>( this.getSupportsMap().values() ) ); this.setSupportsMap( null ); } }
/** * Gets the performance, which is the error count on the last iteration. * * @return The performance of the algorithm. */ public NamedValue<Integer> getPerformance() { return new DefaultNamedValue<Integer>("error count", this.getErrorCount()); } }
@Override public KernelBasedIterativeRegression<InputType> clone() { KernelBasedIterativeRegression<InputType> clone = (KernelBasedIterativeRegression<InputType>) super.clone(); clone.setKernel( ObjectUtil.cloneSmart( this.getKernel() ) ); clone.setResult( ObjectUtil.cloneSafe( this.getResult() ) ); clone.setSupportsMap( ObjectUtil.cloneSmart( this.getSupportsMap() ) ); return clone; }
protected boolean initializeAlgorithm() { if (this.getData() == null) { // Error: No data to learn on. return false; } // Count the number of valid examples. int validCount = 0; for (InputOutputPair<? extends InputType, Double> example : this.getData()) { if (example != null) { validCount++; } } if (validCount <= 0) { // Nothing to perform learning on. return false; } // Set up the learning variables. this.setErrorCount( validCount ); this.setSupportsMap( new LinkedHashMap<InputOutputPair<? extends InputType, Double>, DefaultWeightedValue<InputType>>() ); this.setResult( new KernelScalarFunction<InputType>( this.getKernel(), this.getSupportsMap().values(), 0.0 ) ); return true; }
/** * Creates a new KernelBasedIterativeRegression with the given kernel and * maximum number of iterations. * * @param kernel The kernel to use. * @param minSensitivity The minimum sensitivity to errors. * @param maxIterations The maximum number of iterations. */ public KernelBasedIterativeRegression( final Kernel<? super InputType> kernel, final double minSensitivity, final int maxIterations ) { super( maxIterations ); this.setKernel( kernel ); this.setMinSensitivity( minSensitivity ); this.setResult( null ); this.setErrorCount( 0 ); this.setSupportsMap( null ); }