001    package aima.learning.neural;
002    
003    import java.util.ArrayList;
004    import java.util.List;
005    
006    public class NNExample {
007            private final List<Double> normalizedInput, normalizedTarget;
008    
009            public NNExample(List<Double> normalizedInput, List<Double> normalizedTarget) {
010                    this.normalizedInput = normalizedInput;
011                    this.normalizedTarget = normalizedTarget;
012            }
013    
014            public NNExample copyExample() {
015                    List<Double> newInput = new ArrayList<Double>();
016                    List<Double> newTarget = new ArrayList<Double>();
017                    for (Double d : normalizedInput) {
018                            newInput.add(new Double(d.doubleValue()));
019                    }
020                    for (Double d : normalizedTarget) {
021                            newTarget.add(new Double(d.doubleValue()));
022                    }
023                    return new NNExample(newInput, newTarget);
024            }
025    
026            public Vector getInput() {
027                    Vector v = new Vector(normalizedInput);
028                    return v;
029    
030            }
031    
032            public Vector getTarget() {
033                    Vector v = new Vector(normalizedTarget);
034                    return v;
035    
036            }
037    
038            public boolean isCorrect(Vector prediction) {
039                    /*
040                     * compares the index having greatest value in target to indec having
041                     * greatest value in prediction. Ifidentical, correct
042                     */
043                    return getTarget().indexHavingMaxValue() == prediction
044                                    .indexHavingMaxValue();
045            }
046    
047    }