public void run(int maxSteps, double minError) {
    	double[] output;
        int i;
        
        double error = 1;
        //for (i = 0; i < maxSteps && error > minError; i++) {  // Train neural network until minError reached or maxSteps exceeded
        for (i = 0; error > minError; i++) {    
        
        	error = 0;
            for (int j = 0; j < patterns.size(); j++) {
                network.setInput(patterns.get(j).getInput());
 
                network.activateNetwork();
 
                output = network.getOutput();
                patterns.get(j).setResult(output);
               // double oError = 0;
                for (int k = 0; k < patterns.get(j).getOutput().length; k++) {
                    double err = Math.pow(output[k] - patterns.get(j).getOutput()[k], 2);
                    error += err;
                }
 
                network.applyBackpropagation(patterns.get(j).getOutput());
            }
            
            error = 1.0/2.0 * error;
            Collections.shuffle(patterns); 					// added recently
        }
         
        System.out.println("Sum of squared errors = " + error + " %");
        System.out.println("##### EPOCH " + i+"\n");
        
        if (i == maxSteps) {
            System.out.println("!Error training try again");
        }
    }