<commit_before>/** @file gsHFitting.h

    @brief Adaptive fitting using hierarchical splines

    This file is part of the G+Smo library.
    
    This Source Code Form is subject to the terms of the Mozilla Public
    License, v. 2.0. If a copy of the MPL was not distributed with this
    file, You can obtain one at http://mozilla.org/MPL/2.0/.

    Author(s): <NAME>, <NAME>
*/

#pragma once

#include <gsModeling/gsFitting.h>
#include <gsHSplines/gsHTensorBasis.h>

namespace gismo {

/** 
    \brief
    This class applies hierarchical fitting of parametrized point clouds.

    \tparam T coefficient type
    
    \ingroup HSplines
*/

template <unsigned d, class T>
class gsHFitting : public gsFitting<T>
{
public:
    /// Default constructor
    gsHFitting();

    /** 
        \brief
        Main constructor of the fitting class
        
        \param param_values a matrix containing the parameter values that parametrize the \a points

        \param points The points to be fitted

        \param basis  Hiearchical basis to use for fitting

        \param refin Percentage of errors to refine (if this strategy is chosen)

        \param extension Extension to apply to marked cells
        
        \param lambda Smoothing parameter
    */
    gsHFitting(gsMatrix<T> const & param_values,
               gsMatrix<T> const & points,
               gsHTensorBasis<d,T> & basis,
               T refin, std::vector<int> extension,
               T lambda = 0)
    : gsFitting<T>(param_values, points, basis)
    {
        GISMO_ASSERT((refin >=0) && (refin <=1), "Refinement percentage must be between 0 and 1." );
        for(std::size_t i = 0; i < extension.size();i++)
        {
            GISMO_ASSERT(extension[i]>=0, "Extension must be a positive number.");
        }

        GISMO_ASSERT(extension.size() == d, "Extension is not of the right dimension");

        m_ref    = refin;     //how many % to refine

        m_ext.resize(d);
	for (unsigned dim = 0; dim != d; dim++)
	    m_ext[dim] = extension[dim]; 


        m_lambda = lambda;    // Smoothing parameter

        m_max_error = m_min_error = 0;

        m_pointErrors.reserve(m_param_values.cols());
    }

public:

    /**
     * @brief iterative_refine iteratively refine the basis
     *
     *
     * @param iterations maximum number of iterations
     *
     * @param tolerance (>=0) if the max error is below the tolerance the refinement stops
     *
     * @param err_threshold if non negative all cells with errors
     * bigger than the threshold are refined /
     * If it is equal to -1 the m_ref percentage is used 
     * 0 = global refinement
     */
    void iterativeRefine(int iterations, T tolerance, T err_threshold = -1);

    /**
     * @brief nextIteration One step of the refinement of iterative_refine(...);
     * @param tolerance (>=0) if the maximum error is below the tolerance the refinement stops;
     * @param err_threshold the same as in iterative_refine(...).
     */
    void nextIteration(T tolerance, T err_threshold);

    /// Return the refinement percentage
    T getRefPercentage() const
    {
        return m_ref;
    }

    /// Returns the chosen cell extension
    const std::vector<unsigned> & get_extension() const 
    {
        return m_ext;
    }

    /// Sets the refinement percentage
    void setRefPercentage(double refPercent)
    {
        GISMO_ASSERT((refPercent >=0) && (refPercent <=1), "Invalid percentage" );
        m_ref = refPercent;
    }

    /// Sets the cell extension
    void setExtension(std::vector<unsigned> const & extension)
    {
        for(std::size_t i = 0; i < extension.size();i++)
        {
            GISMO_ASSERT(extension[i]>=0, "Extension must be non negative.");
        }
        assert(extension.size()== unsigned(this->m_basis.dim()));
        m_ext = extension;
    }

    /// Returns boxes which define refinment area. 
    std::vector<unsigned> getBoxes(const std::vector<T>& errors,
				   const double threshold);
<commit_msg>fix math calls etc<commit_after>/** @file gsHFitting.h

    @brief Adaptive fitting using hierarchical splines

    This file is part of the G+Smo library.
    
    This Source Code Form is subject to the terms of the Mozilla Public
    License, v. 2.0. If a copy of the MPL was not distributed with this
    file, You can obtain one at http://mozilla.org/MPL/2.0/.

    Author(s): <NAME>, <NAME>
*/

#pragma once

#include <gsModeling/gsFitting.h>
#include <gsHSplines/gsHTensorBasis.h>

namespace gismo {

/** 
    \brief
    This class applies hierarchical fitting of parametrized point clouds.

    \tparam T coefficient type
    
    \ingroup HSplines
*/

template <unsigned d, class T>
class gsHFitting : public gsFitting<T>
{
public:
    /// Default constructor
    gsHFitting();

    /** 
        \brief
        Main constructor of the fitting class
        
        \param param_values a matrix containing the parameter values that parametrize the \a points

        \param points The points to be fitted

        \param basis  Hiearchical basis to use for fitting

        \param refin Percentage of errors to refine (if this strategy is chosen)

        \param extension Extension to apply to marked cells
        
        \param lambda Smoothing parameter
    */
    gsHFitting(gsMatrix<T> const & param_values,
               gsMatrix<T> const & points,
               gsHTensorBasis<d,T> & basis,
               T refin, std::vector<int> extension,
               T lambda = 0)
    : gsFitting<T>(param_values, points, basis)
    {
        GISMO_ASSERT((refin >=0) && (refin <=1), "Refinement percentage must be between 0 and 1." );
        for(std::size_t i = 0; i < extension.size();i++)
        {
            GISMO_ASSERT(extension[i]>=0, "Extension must be a positive number.");
        }

        GISMO_ASSERT(extension.size() == d, "Extension is not of the right dimension");

        m_ref    = refin;     //how many % to refine

        m_ext.resize(d);
	for (unsigned dim = 0; dim != d; dim++)
	    m_ext[dim] = extension[dim]; 


        m_lambda = lambda;    // Smoothing parameter

        m_max_error = m_min_error = 0;

        m_pointErrors.reserve(m_param_values.cols());
    }

public:

    /**
     * @brief iterative_refine iteratively refine the basis
     *
     *
     * @param iterations maximum number of iterations
     *
     * @param tolerance (>=0) if the max error is below the tolerance the refinement stops
     *
     * @param err_threshold if non negative all cells with errors
     * bigger than the threshold are refined /
     * If it is equal to -1 the m_ref percentage is used 
     * 0 = global refinement
     */
    void iterativeRefine(int iterations, T tolerance, T err_threshold = -1);

    /**
     * @brief nextIteration One step of the refinement of iterative_refine(...);
     * @param tolerance (>=0) if the maximum error is below the tolerance the refinement stops;
     * @param err_threshold the same as in iterative_refine(...).
     */
    void nextIteration(T tolerance, T err_threshold);

    /// Return the refinement percentage
    T getRefPercentage() const
    {
        return m_ref;
    }

    /// Returns the chosen cell extension
    const std::vector<unsigned> & get_extension() const 
    {
        return m_ext;
    }

    /// Sets the refinement percentage
    void setRefPercentage(double refPercent)
    {
        GISMO_ASSERT((refPercent >=0) && (refPercent <=1), "Invalid percentage" );
        m_ref = refPercent;
    }

    /// Sets the cell extension
    void setExtension(std::vector<unsigned> const & extension)
    {
        for(std::size_t i = 0; i < extension.size();i++)
        {
            GISMO_ASSERT(extension[i]>=0, "Extension must be non negative.");
        }
        assert(extension.size()== unsigned(this->m_basis.dim()));
        m_ext = extension;
    }

    /// Returns boxes which define refinment area. 
    std::vector<unsigned> getBoxes(const std::vector<T>& errors,
				   const T threshold);

{'fraction_non_alphanumeric': 0.09805389221556886, 'fraction_numerical': 0.0054890219560878245, 'mean_word_length': 2.3855574324324325, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3367744', 'n_tokens_mistral': 2434, 'n_tokens_neox': 2251, 'n_words': 793}