Skip to content
Snippets Groups Projects
LevenbergMarquardt.h 1.62 KiB
Newer Older
//
// Created by martin on 9.2.19.
//

#ifndef LIB4NEURO_LEVENBERGMARQUARDT_H
#define LIB4NEURO_LEVENBERGMARQUARDT_H

#include <memory>

#include "LearningMethod.h"

namespace lib4neuro {

    enum LM_UPDATE_TYPE {
        MARQUARDT,
        QUADRATIC,
        NIELSEN
    };

    /**
     * Method implementing Levenberg-Marquardt optimization algorithm
     *
     * This version is described in the paper:
     * Gavin, Henri. "The Levenberg-Marquardt method for nonlinear least squares curve-fitting problems."
     * Department of Civil and Environmental Engineering, Duke University (2011): 1-15.
     */
    class LevenbergMarquardt : public GradientLearningMethod {

    private:
        struct LevenbergMarquardtImpl;
        std::shared_ptr<LevenbergMarquardtImpl> p_impl;
                           double tolerance=1e-2,
                           double tolerance_gradient=1e-3,
                           double tolerance_parameters=1e-3,
                           double LM_step_acceptance_threshold=1e-1,
                           double lambda_initial=1e-2,
                           double lambda_increase=11,
                           double lambda_decrease=9);

        void optimize(ErrorFunction &ef, std::ofstream* ofs = nullptr);
        void optimize(ErrorFunction &ef,
                      LM_UPDATE_TYPE update_type,
                      std::ofstream* ofs = nullptr);
        std::shared_ptr<std::vector<double>> get_parameters() override;