for (InputType input : inputs) result.add(create(input, output));
/** * Creates an ROC curve based on the scored data with target information. * * @param data * Collection of target/estimate-score pairs. The second element in * the pair is an estimated score, the first is a flag to determine * which group the score belongs to. For example: * {(true, 1.0), (false, 0.9)} * means that data1=1.0 and data2=0.9 and so forth. This is useful * for computing that classified data partitions data better than * chance. * @return * ROC Curve describing the scoring system versus the targets. */ public static ReceiverOperatingCharacteristic createFromTargetEstimatePairs( final Collection<? extends Pair<Boolean, ? extends Number>> data) { // Transform the data to input-output pairs. final ArrayList<InputOutputPair<Double, Boolean>> transformed = new ArrayList<InputOutputPair<Double, Boolean>>(data.size()); for (Pair<Boolean, ? extends Number> entry : data) { transformed.add(DefaultInputOutputPair.create( entry.getSecond().doubleValue(), entry.getFirst())); } return create(transformed); }
/** * Creates an ROC curve based on the scored data with target information. * * @param data * Collection of target/estimate-score pairs. The second element in * the pair is an estimated score, the first is a flag to determine * which group the score belongs to. For example: * {(true, 1.0), (false, 0.9)} * means that data1=1.0 and data2=0.9 and so forth. This is useful * for computing that classified data partitions data better than * chance. * @return * ROC Curve describing the scoring system versus the targets. */ public static ReceiverOperatingCharacteristic createFromTargetEstimatePairs( final Collection<? extends Pair<Boolean, ? extends Number>> data) { // Transform the data to input-output pairs. final ArrayList<InputOutputPair<Double, Boolean>> transformed = new ArrayList<InputOutputPair<Double, Boolean>>(data.size()); for (Pair<Boolean, ? extends Number> entry : data) { transformed.add(DefaultInputOutputPair.create( entry.getSecond().doubleValue(), entry.getFirst())); } return create(transformed); }
/** * Creates an ROC curve based on the scored data with target information. * * @param data * Collection of target/estimate-score pairs. The second element in * the pair is an estimated score, the first is a flag to determine * which group the score belongs to. For example: * {(true, 1.0), (false, 0.9)} * means that data1=1.0 and data2=0.9 and so forth. This is useful * for computing that classified data partitions data better than * chance. * @return * ROC Curve describing the scoring system versus the targets. */ public static ReceiverOperatingCharacteristic createFromTargetEstimatePairs( final Collection<? extends Pair<Boolean, ? extends Number>> data) { // Transform the data to input-output pairs. final ArrayList<InputOutputPair<Double, Boolean>> transformed = new ArrayList<InputOutputPair<Double, Boolean>>(data.size()); for (Pair<Boolean, ? extends Number> entry : data) { transformed.add(DefaultInputOutputPair.create( entry.getSecond().doubleValue(), entry.getFirst())); } return create(transformed); }
/** * {@inheritDoc} */ protected void cleanupAlgorithm() { double yhat = this.data.evaluate( this.result.getInput() ); this.result = DefaultInputOutputPair.create( this.result.getInput(), yhat); }
/** * {@inheritDoc} */ protected void cleanupAlgorithm() { double yhat = this.data.evaluate( this.result.getInput() ); this.result = DefaultInputOutputPair.create( this.result.getInput(), yhat); }
/** * {@inheritDoc} */ protected void cleanupAlgorithm() { double yhat = this.data.evaluate( this.result.getInput() ); this.result = DefaultInputOutputPair.create( this.result.getInput(), yhat); }
@Override public VectorFunctionLinearDiscriminant<Double> learn( final Collection<? extends InputOutputPair<? extends Double, Double>> data) { // The first task is to create the Vector-space representation ArrayList<InputOutputPair<Vector,Double>> vectorData = new ArrayList<InputOutputPair<Vector, Double>>( data.size() ); for( InputOutputPair<? extends Double,Double> pair : data ) { Vector phi = this.polynomials.evaluate( pair.getInput() ); vectorData.add( DefaultInputOutputPair.create( phi, pair.getOutput() ) ); } LinearRegression regression = new LinearRegression(); LinearDiscriminantWithBias linearResult = regression.learn(vectorData); return new VectorFunctionLinearDiscriminant<Double>( this.getPolynomials(), linearResult ); }
@Override public VectorFunctionLinearDiscriminant<Double> learn( final Collection<? extends InputOutputPair<? extends Double, Double>> data) { // The first task is to create the Vector-space representation ArrayList<InputOutputPair<Vector,Double>> vectorData = new ArrayList<InputOutputPair<Vector, Double>>( data.size() ); for( InputOutputPair<? extends Double,Double> pair : data ) { Vector phi = this.polynomials.evaluate( pair.getInput() ); vectorData.add( DefaultInputOutputPair.create( phi, pair.getOutput() ) ); } LinearRegression regression = new LinearRegression(); LinearDiscriminantWithBias linearResult = regression.learn(vectorData); return new VectorFunctionLinearDiscriminant<Double>( this.getPolynomials(), linearResult ); }
private static Collection<? extends InputOutputPair<? extends gov.sandia.cognition.math.matrix.Vector, Boolean>> createData() { final List<InputOutputPair<gov.sandia.cognition.math.matrix.Vector, Boolean>> ret = new ArrayList<InputOutputPair<gov.sandia.cognition.math.matrix.Vector, Boolean>>(); final LinearPerceptronDataGenerator dg = dataGen(); for (int i = 0; i < TOTAL_DATA_ITEMS; i++) { final IndependentPair<double[], PerceptronClass> pointClass = dg.generate(); final double[] pc = pointClass.firstObject(); final PerceptronClass pcc = pointClass.secondObject(); final boolean bool = pcc.equals(PerceptronClass.TRUE); final gov.sandia.cognition.math.matrix.Vector vec = VectorFactory.getDenseDefault().copyArray(pc); final InputOutputPair<gov.sandia.cognition.math.matrix.Vector, Boolean> item = DefaultInputOutputPair.create( vec, bool); ret.add(item); } System.out.println("Data created"); return ret; }
@Override public VectorFunctionLinearDiscriminant<Double> learn( final Collection<? extends InputOutputPair<? extends Double, Double>> data) { // The first task is to create the Vector-space representation ArrayList<InputOutputPair<Vector,Double>> vectorData = new ArrayList<InputOutputPair<Vector, Double>>( data.size() ); for( InputOutputPair<? extends Double,Double> pair : data ) { Vector phi = this.polynomials.evaluate( pair.getInput() ); vectorData.add( DefaultInputOutputPair.create( phi, pair.getOutput() ) ); } LinearRegression regression = new LinearRegression(); LinearDiscriminantWithBias linearResult = regression.learn(vectorData); return new VectorFunctionLinearDiscriminant<Double>( this.getPolynomials(), linearResult ); }
private static Collection<? extends InputOutputPair<? extends gov.sandia.cognition.math.matrix.Vector, Boolean>> createData() { final List<InputOutputPair<gov.sandia.cognition.math.matrix.Vector, Boolean>> ret = new ArrayList<InputOutputPair<gov.sandia.cognition.math.matrix.Vector, Boolean>>(); final LinearPerceptronDataGenerator dg = dataGen(); for (int i = 0; i < TOTAL_DATA_ITEMS; i++) { final IndependentPair<double[], PerceptronClass> pointClass = dg.generate(); final double[] pc = pointClass.firstObject(); final PerceptronClass pcc = pointClass.secondObject(); final boolean bool = pcc.equals(PerceptronClass.TRUE); final gov.sandia.cognition.math.matrix.Vector vec = VectorFactory.getDenseDefault().copyArray(pc); final InputOutputPair<gov.sandia.cognition.math.matrix.Vector, Boolean> item = DefaultInputOutputPair.create( vec, bool); ret.add(item); } System.out.println("Data created"); return ret; }
private void prepareDataCollection() { this.dataCollection = new ArrayList<InputOutputPair<Vector, Vector>>(); final double[][] xArr = this.xVals.getArray(); final double[][] yArr = this.yVals.getArray(); for (int i = 0; i < xArr.length; i++) { final Vector xVector = VectorFactory.getDefault().copyArray(xArr[i]); final double[] yValues = new double[10]; final int number = (int) (yArr[i][0] % 10); final int count = examples.adjustOrPutValue(number, 1, 1); yValues[number] = 1; final Vector yVector = VectorFactory.getDefault().copyValues(yValues); if (this.maxExamples != -1 && count > maxExamples) { if (count > maxTests + maxExamples) { continue; } List<IndependentPair<Vector, Vector>> numberTest = this.tests.get(number); if (numberTest == null) { this.tests.put(number, numberTest = new ArrayList<IndependentPair<Vector, Vector>>()); } numberTest.add(IndependentPair.pair(xVector, yVector)); totalTests++; } else { this.dataCollection.add(DefaultInputOutputPair.create(xVector, yVector)); } } }
private void prepareDataCollection() { this.dataCollection = new ArrayList<InputOutputPair<Vector, Vector>>(); final double[][] xArr = this.xVals.getArray(); final double[][] yArr = this.yVals.getArray(); for (int i = 0; i < xArr.length; i++) { final Vector xVector = VectorFactory.getDefault().copyArray(xArr[i]); final double[] yValues = new double[10]; final int number = (int) (yArr[i][0] % 10); final int count = examples.adjustOrPutValue(number, 1, 1); yValues[number] = 1; final Vector yVector = VectorFactory.getDefault().copyValues(yValues); if (this.maxExamples != -1 && count > maxExamples) { if (count > maxTests + maxExamples) { continue; } List<IndependentPair<Vector, Vector>> numberTest = this.tests.get(number); if (numberTest == null) { this.tests.put(number, numberTest = new ArrayList<IndependentPair<Vector, Vector>>()); } numberTest.add(IndependentPair.pair(xVector, yVector)); totalTests++; } else { this.dataCollection.add(DefaultInputOutputPair.create(xVector, yVector)); } } }
@Override public void update( final VotingCategorizerEnsemble<InputType, CategoryType, MemberType> target, final InputOutputPair<? extends InputType, CategoryType> data) { // Make sure the ensemble's category set contains this category. final CategoryType category = data.getOutput(); if (!target.getCategories().contains(category)) { target.getCategories().add(category); } // To figure out how many examples to add, we sample from a Poisson // distribution using the percent to sample as the rate. In this paper // this is 1.0, but we provide a parameter to control the bag fraction. final PoissonDistribution.PMF poisson = new PoissonDistribution.PMF( this.getPercentToSample()); for (MemberType member : target.getMembers()) { // Figure out the number of times to give this member the example. final int updateCount = poisson.sample(this.random).intValue(); // Now update that many times. for (int i = 0; i < updateCount; i++) { this.learner.update(member, data); } } }
@Override public void update( final VotingCategorizerEnsemble<InputType, CategoryType, MemberType> target, final InputOutputPair<? extends InputType, CategoryType> data) { // Make sure the ensemble's category set contains this category. final CategoryType category = data.getOutput(); if (!target.getCategories().contains(category)) { target.getCategories().add(category); } // To figure out how many examples to add, we sample from a Poisson // distribution using the percent to sample as the rate. In this paper // this is 1.0, but we provide a parameter to control the bag fraction. final PoissonDistribution.PMF poisson = new PoissonDistribution.PMF( this.getPercentToSample()); for (MemberType member : target.getMembers()) { // Figure out the number of times to give this member the example. final int updateCount = poisson.sample(this.random).intValue(); // Now update that many times. for (int i = 0; i < updateCount; i++) { this.learner.update(member, data); } } }
@Override public void update( final VotingCategorizerEnsemble<InputType, CategoryType, MemberType> target, final InputOutputPair<? extends InputType, CategoryType> data) { // Make sure the ensemble's category set contains this category. final CategoryType category = data.getOutput(); if (!target.getCategories().contains(category)) { target.getCategories().add(category); } // To figure out how many examples to add, we sample from a Poisson // distribution using the percent to sample as the rate. In this paper // this is 1.0, but we provide a parameter to control the bag fraction. final PoissonDistribution.PMF poisson = new PoissonDistribution.PMF( this.getPercentToSample()); for (MemberType member : target.getMembers()) { // Figure out the number of times to give this member the example. final int updateCount = poisson.sample(this.random).intValue(); // Now update that many times. for (int i = 0; i < updateCount; i++) { this.learner.update(member, data); } } }
localSimplex.add( DefaultInputOutputPair.create( initialPoint.getInput(), initialPoint.getOutput()) );
localSimplex.add( DefaultInputOutputPair.create( initialPoint.getInput(), initialPoint.getOutput()) );
localSimplex.add( DefaultInputOutputPair.create( initialPoint.getInput(), initialPoint.getOutput()) );