/*
 * Copyright 2015 David Clutter
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.clutteredcode.ann.feedforward;

import com.clutteredcode.ann.InputNeuron;
import com.clutteredcode.ann.Neuron;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * @author David Clutter
 */
public class InputLayer extends Layer {

    public InputLayer(final List<InputNeuron> neurons) {
        super(neurons);
    }

    @Override
    public List<Double> fire(final List<Double> inputs) {
        if (inputs.size() != neurons.size())
            throw new IllegalArgumentException("inputs (" + inputs.size() + ") and Neurons (" + neurons.size() + ") in the input layer must have the same number of elements");

        return IntStream.range(0, inputs.size())
                .mapToDouble(i -> {
                    final double input = inputs.get(i);
                    final Neuron neuron = neurons.get(i);
                    return neuron.fire(input);
                })
                .boxed()
                .collect(Collectors.toList());
    }

    /**
     * Returns {@code this InputLayer} without mutating.
     *
     * @param mutationRate This parameter is ignored.
     * @return {@code this InputLayer}.
     */
    @Override
    public Layer mutate(final double mutationRate) {
        return this;
    }

    /**
     * Returns {@code this InputLayer} without performing crossover.
     *
     * @param mate This parameter is ignored.
     * @return {@code this InputLayer}.
     */
    @Override
    public Layer crossover(final Layer mate) {
        return this;
    }
}
@@ -730,16 +730,21 @@
 va.util.
+Array
 List;%0Aim
@@ -762,25 +762,16 @@
 til.
-stream.Collec
+Itera
 tor
-s
 ;%0Aim
@@ -789,24 +789,12 @@
 til.
+Li
 st
-ream.IntStream
 ;%0A%0A/
@@ -1062,32 +1062,34 @@
  neurons.size())
+ %7B
 %0A            thr
@@ -1253,48 +1253,77 @@
 %22);%0A
-%0A        return IntStream.range(0, input
+        %7D%0A        final List%3CDouble%3E outputs = new ArrayList%3C%3E(neuron
 s.si
@@ -1327,16 +1327,17 @@
 .size())
+;
 %0A       
@@ -1341,74 +1341,45 @@
     
-        .mapToDouble(i -%3E %7B%0A                    final d
+final Iterator%3CD
 ouble
+%3E
  input
+sIterator
  = i
@@ -1384,21 +1384,25 @@
  inputs.
-get(i
+iterator(
 );%0A     
@@ -1404,28 +1404,21 @@
         
-            
+for (
 final Ne
@@ -1429,25 +1429,25 @@
  neuron 
-=
+:
  neurons
 .get(i);
@@ -1442,16 +1442,11 @@
 rons
-.get(i);
+) %7B
 %0A   
@@ -1454,30 +1454,93 @@
         
-        return
+final double input = inputsIterator.next();%0A            final double output =
  neuron.
@@ -1568,39 +1568,28 @@
     
-    %7D)%0A                .boxed()
+outputs.add(output);
 %0A   
@@ -1593,24 +1593,26 @@
         
+%7D%0A
         
 .collect
@@ -1607,37 +1607,22 @@
     
-.collect(Collectors.toList())
+return outputs
 ;%0A  

use for loop in InputLayer.fire() instead of java8 stream for better performance