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 Network implements Model {

    private final List<Layer> layers;

    public Network(List<Layer> layers) {
        this.layers = layers;
    }

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

    @Override
    public int synCount() {
        int res = 0;
        for(Layer layer : this.layers){
            res += layer.synCount();
        }
        return res;
    }

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

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