package com.naaturel.ANN.implementation.gradientDescent;

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

import java.util.concurrent.atomic.AtomicInteger;

public class GradientDescentCorrectionStrategy implements AlgorithmStrategy {

    private final GradientDescentTrainingContext context;

    public GradientDescentCorrectionStrategy(GradientDescentTrainingContext context) {
        this.context = context;
    }

    @Override
    public void apply() {
        AtomicInteger i = new AtomicInteger(0);
        context.model.forEachSynapse(syn -> {
            float corrector = context.correctorTerms.get(i.get());
            float c = syn.getWeight() + corrector;
            syn.setWeight(c);
            i.incrementAndGet();
        });
    }
}
