package com.naaturel.ANN.implementation.simplePerceptron;

import com.naaturel.ANN.domain.abstraction.AlgorithmStrategy;
import com.naaturel.ANN.domain.abstraction.TrainingContext;
import com.naaturel.ANN.domain.model.dataset.DataSet;
import com.naaturel.ANN.domain.model.dataset.DataSetEntry;

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

public class SimpleDeltaStrategy implements AlgorithmStrategy {

    private final TrainingContext context;

    public SimpleDeltaStrategy(TrainingContext context) {
        this.context = context;
    }

    @Override
    public void apply() {
        DataSet dataSet = context.dataset;
        DataSetEntry entry = context.currentEntry;
        List<Float> predicted = context.predictions;
        List<Float> expected = dataSet.getLabelsAsFloat(entry);

        //context.delta = label.getValue() - context.predictions;
        context.deltas = IntStream.range(0, predicted.size())
                .mapToObj(i -> expected.get(i) - predicted.get(i))
                .collect(Collectors.toList());
        System.out.printf("");
    }

}
