Package org.neuroph.core.learning

Examples of org.neuroph.core.learning.TrainingSet


    /**
     * Create and run MLP with XOR training set
     */
    public static void main(String[] args) {
        // create training set (logical XOR function)
        TrainingSet trainingSet = new TrainingSet(2, 1);
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{0, 0}, new double[]{0}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{0, 1}, new double[]{1}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{1, 0}, new double[]{1}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{1, 1}, new double[]{0}));

        MultiLayerPerceptron nnet = new MultiLayerPerceptron( TransferFunctionType.TANH ,2, 3, 1);
        MatrixMultiLayerPerceptron mnet = new MatrixMultiLayerPerceptron(nnet);

        System.out.println("Training network...");
View Full Code Here


     * Runs this sample
     */
    public static void main(String args[]) {
            // create training set (logical AND function)
            TrainingSet trainingSet = new TrainingSet(2, 1);
            trainingSet.addElement(new SupervisedTrainingElement(new double[]{0, 0}, new double[]{0}));
            trainingSet.addElement(new SupervisedTrainingElement(new double[]{0, 1}, new double[]{0}));
            trainingSet.addElement(new SupervisedTrainingElement(new double[]{1, 0}, new double[]{0}));
            trainingSet.addElement(new SupervisedTrainingElement(new double[]{1, 1}, new double[]{1}));

            // create perceptron neural network
            NeuralNetwork myPerceptron = new Perceptron(2, 1);
            // learn the training set
            myPerceptron.learnInSameThread(trainingSet);
View Full Code Here

  /**
   * Generate the training data for the training sunspot years.
   * @return The training data.
   */
  public TrainingSet generateTraining() {
    TrainingSet result = new TrainingSet(WINDOW_SIZE, 1);

    for (int year = TRAIN_START; year < TRAIN_END; year++) {
      double[] input = new double[WINDOW_SIZE];
      double[] ideal = new double[1];

      int index = 0;
      for (int i = year - WINDOW_SIZE; i < year; i++) {
        input[index++] = this.normalizedSunspots[i];
      }

      ideal[0] = this.normalizedSunspots[year];

      result.addElement(new SupervisedTrainingElement(input, ideal));
    }
    return result;
  }
View Full Code Here

     
    normalizeSunspots(0.1, 0.9);
   
    network.getLearningRule().addObserver(this);
   
    TrainingSet training = generateTraining();
    network.learnInSameThread(training);
    predict(network);
   
    Neuroph.getInstance().shutdown();
  }
View Full Code Here

     * Runs this sample
     */
    public static void main(String args[]) {

        // create training set (H and T letter in 3x3 grid)
        TrainingSet trainingSet = new TrainingSet();
        trainingSet.addElement(new TrainingElement(new double[]{1, 0, 1,
                                                                1, 1, 1,
                                                                1, 0, 1})); // H letter
       
        trainingSet.addElement(new TrainingElement(new double[]{1, 1, 1,
                                                                0, 1, 0,
                                                                0, 1, 0})); // T letter
 
        // create hopfield network
        Hopfield myHopfield = new Hopfield(9);
        // learn the training set
        myHopfield.learnInSameThread(trainingSet);

        // test hopfield network
        System.out.println("Testing network");

        // add one more 'incomplete' H pattern for testing - it will be recognized as H
        trainingSet.addElement(new TrainingElement(new double[]{1, 0, 0,
                                                                1, 0, 1,
                                                                1, 0, 1}));


        // print network output for the each element from the specified training set.
        for(TrainingElement trainingElement : trainingSet.trainingElements()) {
            myHopfield.setInput(trainingElement.getInput());
            myHopfield.calculate();
            myHopfield.calculate();  
            double[] networkOutput = myHopfield.getOutput();

View Full Code Here

     * Runs this sample
     */
    public static void main(String[] args) {
     
        // create training set (logical XOR function)
        TrainingSet trainingSet = new TrainingSet(2, 1);
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{0, 0}, new double[]{0}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{0, 1}, new double[]{1}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{1, 0}, new double[]{1}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{1, 1}, new double[]{0}));

        // create multi layer perceptron
        MultiLayerPerceptron myMlPerceptron = new MultiLayerPerceptron(TransferFunctionType.TANH, 2, 3, 1);

        // enable batch if using MomentumBackpropagation
View Full Code Here

     * @param inputsCount training element (neural net) inputs count
     * @param outputsCount training element (neural net) ouputs count
     * @return training set with stock data
     */
    public static TrainingSet importFromArray(double[] values, int inputsCount, int outputsCount) {
        TrainingSet trainingSet = new TrainingSet(inputsCount, outputsCount);
        for (int i = 0; i < values.length - inputsCount; i++) {
            ArrayList<Double> inputs = new ArrayList<Double>();
            for (int j = i; j < i + inputsCount; j++) {
                inputs.add(values[j]);
            }
            ArrayList<Double> outputs = new ArrayList<Double>();
            if (outputsCount > 0 && i + inputsCount + outputsCount <= values.length) {
                for (int j = i + inputsCount; j < i + inputsCount + outputsCount; j++) {
                    outputs.add(values[j]);
                }
                if (outputsCount > 0) {
                    trainingSet.addElement(new SupervisedTrainingElement(inputs, outputs));
                } else {
                    trainingSet.addElement(new TrainingElement(inputs));
                }
            }
        }
        return trainingSet;
    }
View Full Code Here

        int maxIterations = 10000;
        NeuralNetwork neuralNet = new MultiLayerPerceptron(4, 9, 1);
        ((LMS) neuralNet.getLearningRule()).setMaxError(0.001);//0-1
        ((LMS) neuralNet.getLearningRule()).setLearningRate(0.7);//0-1
        ((LMS) neuralNet.getLearningRule()).setMaxIterations(maxIterations);//0-1
        TrainingSet trainingSet = new TrainingSet();

        double daxmax = 10000.0D;
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{3710.0D / daxmax, 3690.0D / daxmax, 3890.0D / daxmax, 3695.0D / daxmax}, new double[]{3666.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{3690.0D / daxmax, 3890.0D / daxmax, 3695.0D / daxmax, 3666.0D / daxmax}, new double[]{3692.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{3890.0D / daxmax, 3695.0D / daxmax, 3666.0D / daxmax, 3692.0D / daxmax}, new double[]{3886.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{3695.0D / daxmax, 3666.0D / daxmax, 3692.0D / daxmax, 3886.0D / daxmax}, new double[]{3914.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{3666.0D / daxmax, 3692.0D / daxmax, 3886.0D / daxmax, 3914.0D / daxmax}, new double[]{3956.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{3692.0D / daxmax, 3886.0D / daxmax, 3914.0D / daxmax, 3956.0D / daxmax}, new double[]{3953.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{3886.0D / daxmax, 3914.0D / daxmax, 3956.0D / daxmax, 3953.0D / daxmax}, new double[]{4044.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{3914.0D / daxmax, 3956.0D / daxmax, 3953.0D / daxmax, 4044.0D / daxmax}, new double[]{3987.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{3956.0D / daxmax, 3953.0D / daxmax, 4044.0D / daxmax, 3987.0D / daxmax}, new double[]{3996.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{3953.0D / daxmax, 4044.0D / daxmax, 3987.0D / daxmax, 3996.0D / daxmax}, new double[]{4043.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{4044.0D / daxmax, 3987.0D / daxmax, 3996.0D / daxmax, 4043.0D / daxmax}, new double[]{4068.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{3987.0D / daxmax, 3996.0D / daxmax, 4043.0D / daxmax, 4068.0D / daxmax}, new double[]{4176.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{3996.0D / daxmax, 4043.0D / daxmax, 4068.0D / daxmax, 4176.0D / daxmax}, new double[]{4187.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{4043.0D / daxmax, 4068.0D / daxmax, 4176.0D / daxmax, 4187.0D / daxmax}, new double[]{4223.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{4068.0D / daxmax, 4176.0D / daxmax, 4187.0D / daxmax, 4223.0D / daxmax}, new double[]{4259.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{4176.0D / daxmax, 4187.0D / daxmax, 4223.0D / daxmax, 4259.0D / daxmax}, new double[]{4203.0D / daxmax}));
        trainingSet.addElement(new SupervisedTrainingElement(new double[]{4187.0D / daxmax, 4223.0D / daxmax, 4259.0D / daxmax, 4203.0D / daxmax}, new double[]{3989.0D / daxmax}));
        neuralNet.learnInSameThread(trainingSet);
        System.out.println("Time stamp N2:" + new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss:MM").format(new Date()));

        TrainingSet testSet = new TrainingSet();
        testSet.addElement(new TrainingElement(new double[]{4223.0D / daxmax, 4259.0D / daxmax, 4203.0D / daxmax, 3989.0D / daxmax}));

        for (TrainingElement testElement : testSet.trainingElements()) {
            neuralNet.setInput(testElement.getInput());
            neuralNet.calculate();
            double[] networkOutput = neuralNet.getOutput();
            System.out.print("Input: " + Arrays.toString(testElement.getInput()) );
            System.out.println(" Output: " + Arrays.toString(networkOutput) );
View Full Code Here

  {

    FileReader fileReader = null;

    try {
     TrainingSet trainingSet = new TrainingSet();
     fileReader = new FileReader(new File(filePath));
     BufferedReader reader = new BufferedReader(fileReader);

     String line = "";
     
      while((line = reader.readLine())!=null) {
        double[] inputs = new double[inputsCount];
        double[] outputs = new double[outputsCount];
        String[] values = line.split(separator);

        if (values[0].equals("")) continue; // skip if line was empty

        for (int i = 0; i < inputsCount; i++)
          inputs[i] =  Double.parseDouble(values[i]);

           for (int i = 0; i < outputsCount; i++)
          outputs[i] = Double.parseDouble(values[inputsCount + i]);

        if (outputsCount>0) {
              trainingSet.addElement(new SupervisedTrainingElement(inputs, outputs));
        } else {
              trainingSet.addElement(new TrainingElement(inputs));
        }
      }

      return trainingSet;
     
View Full Code Here

         * @param imageLabels image labels
         * @param rgbDataMap map collection of rgb data
         * @return training set for the specified image data
         */
  public static TrainingSet createTrainingSet(List<String> imageLabels, Map<String, FractionRgbData> rgbDataMap)   { 
    TrainingSet trainingSet = new TrainingSet();

    for (Entry<String, FractionRgbData> entry : rgbDataMap.entrySet()) {
      double[] input = entry.getValue().getFlattenedRgbValues();
      double[] response = createResponse(entry.getKey(), imageLabels);
      trainingSet.addElement(new SupervisedTrainingElement(
          VectorParser.convertToVector(input),
          VectorParser.convertToVector(response)));
    }

                return trainingSet;
View Full Code Here

TOP

Related Classes of org.neuroph.core.learning.TrainingSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.