package com.naaturel.ANN.domain.model.neuron;

import com.naaturel.ANN.domain.abstraction.Model;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class Layer implements Model {

    private final List<Neuron> neurons;

    public Layer(List<Neuron> neurons) {
        this.neurons = neurons;
    }

    @Override
    public List<Float> predict(List<Input> inputs) {
        List<Float> result = new ArrayList<>();
        for(Neuron neuron : this.neurons){
            List<Float> res = neuron.predict(inputs);
            result.addAll(res);
        }
        return result;
    }

    @Override
    public int synCount() {
        int res = 0;
        for (Neuron neuron : this.neurons) {
            res += neuron.synCount();
        }
        return res;
    }

    @Override
    public void forEachNeuron(Consumer<Neuron> consumer) {
        this.neurons.forEach(consumer);
    }

    @Override
    public void forEachSynapse(Consumer<Synapse> consumer) {
        this.neurons.forEach(neuron -> neuron.forEachSynapse(consumer));
    }
}
