<commit_before>/*
 * This file is part of the Multivariate Splines library.
 * Copyright (C) 2012 <NAME> (<EMAIL>)
 *
 * 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/.
*/


#ifndef MS_RBFSPLINE_H
#define MS_RBFSPLINE_H

#include "datatable.h"
#include "spline.h"
#include "memory"

namespace MultivariateSplines
{

enum class RadialBasisFunctionType
{
    MULTIQUADRIC,
    INVERSE_QUADRIC,
    INVERSE_MULTIQUADRIC,
    THIN_PLATE_SPLINE,
    GAUSSIAN
};

/*
 * Base class for radial basis functions.
 */
class RadialBasisFunction
{
public:
    RadialBasisFunction() : e(1.0) {}
    RadialBasisFunction(double e) : e(e) {}
    virtual double eval(double r) const = 0;
    virtual double evalDerivative(double r) const = 0;
protected:
    double e;
};

class ThinPlateSpline : public RadialBasisFunction
{
public:
    double eval(double r) const
    {
        return (r<=0.0) ? 0.0 : r*r*std::log(r);
    }
    double evalDerivative(double r) const
    {
        return (r<=0.0) ? 0.0 : r*(2*log(r) + 1);
    }
};

class Multiquadric : public RadialBasisFunction
{
public:
    double eval(double r) const
    {
        return std::sqrt(1.0 + e*e*r*r);
    }
    double evalDerivative(double r) const
    {
        return e*e*r/std::sqrt(1 + e*e*r*r);
    }
};

class InverseMultiquadric : public RadialBasisFunction
{
public:
    double eval(double r) const
    {
        return 1.0/std::sqrt(1.0 + e*e*r*r);
    }
    double evalDerivative(double r) const
    {
        return -e*e*r/(std::sqrt(1 + e*e*r*r)*(1 + e*e*r*r));
    }
};

class InverseQuadric : public RadialBasisFunction
{
public:
    double eval(double r) const
    {
        return 1.0/(1.0 + e*e*r*r);
    }
    double evalDerivative(double r) const
    {
        return -2*e*e*r/((1 + e*e*r*r)*(1 + e*e*r*r));
    }
};

class Gaussian : public RadialBasisFunction
{
public:
    double eval(double r) const
    {
        return std::exp(-e*e*r*r);
    }
    double evalDerivative(double r) const
    {
        return -2*e*e*r*std::exp(-e*e*r*r);
    }
};

/*
 * Class for radial basis function splines.
 * The RBF splines support scattered sampling, but their construction require
 * the solution of a fairly ill-conditioned linear system. This drawback may be
 * alleviated by applying a pre-conditioner to the linear system.
 */
class RBFSpline : public Spline
{
public:

    RBFSpline(const DataTable &samples, RadialBasisFunctionType type);
    RBFSpline(const DataTable &samples, RadialBasisFunctionType type, bool normalized);

    virtual RBFSpline* clone() const { return new RBFSpline(*this); }

    double eval(DenseVector x) const;
    double eval(std::vector<double> x) const;

    DenseMatrix evalJacobian(DenseVector x) const {}; // TODO: implement via RBF_fn
    DenseMatrix evalHessian(DenseVector x) const {}; // TODO: implement via RBF_fn
    //    std::vector<double> getDomainUpperBound() const;
    //    std::vector<double> getDomainLowerBound() const;
<commit_msg>Add return value to evalJacobian and evalHessian to make MSVC happy<commit_after>/*
 * This file is part of the Multivariate Splines library.
 * Copyright (C) 2012 <NAME> (<EMAIL>)
 *
 * 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/.
*/


#ifndef MS_RBFSPLINE_H
#define MS_RBFSPLINE_H

#include "datatable.h"
#include "spline.h"
#include "memory"

namespace MultivariateSplines
{

enum class RadialBasisFunctionType
{
    MULTIQUADRIC,
    INVERSE_QUADRIC,
    INVERSE_MULTIQUADRIC,
    THIN_PLATE_SPLINE,
    GAUSSIAN
};

/*
 * Base class for radial basis functions.
 */
class RadialBasisFunction
{
public:
    RadialBasisFunction() : e(1.0) {}
    RadialBasisFunction(double e) : e(e) {}
    virtual double eval(double r) const = 0;
    virtual double evalDerivative(double r) const = 0;
protected:
    double e;
};

class ThinPlateSpline : public RadialBasisFunction
{
public:
    double eval(double r) const
    {
        return (r<=0.0) ? 0.0 : r*r*std::log(r);
    }
    double evalDerivative(double r) const
    {
        return (r<=0.0) ? 0.0 : r*(2*log(r) + 1);
    }
};

class Multiquadric : public RadialBasisFunction
{
public:
    double eval(double r) const
    {
        return std::sqrt(1.0 + e*e*r*r);
    }
    double evalDerivative(double r) const
    {
        return e*e*r/std::sqrt(1 + e*e*r*r);
    }
};

class InverseMultiquadric : public RadialBasisFunction
{
public:
    double eval(double r) const
    {
        return 1.0/std::sqrt(1.0 + e*e*r*r);
    }
    double evalDerivative(double r) const
    {
        return -e*e*r/(std::sqrt(1 + e*e*r*r)*(1 + e*e*r*r));
    }
};

class InverseQuadric : public RadialBasisFunction
{
public:
    double eval(double r) const
    {
        return 1.0/(1.0 + e*e*r*r);
    }
    double evalDerivative(double r) const
    {
        return -2*e*e*r/((1 + e*e*r*r)*(1 + e*e*r*r));
    }
};

class Gaussian : public RadialBasisFunction
{
public:
    double eval(double r) const
    {
        return std::exp(-e*e*r*r);
    }
    double evalDerivative(double r) const
    {
        return -2*e*e*r*std::exp(-e*e*r*r);
    }
};

/*
 * Class for radial basis function splines.
 * The RBF splines support scattered sampling, but their construction require
 * the solution of a fairly ill-conditioned linear system. This drawback may be
 * alleviated by applying a pre-conditioner to the linear system.
 */
class RBFSpline : public Spline
{
public:

    RBFSpline(const DataTable &samples, RadialBasisFunctionType type);
    RBFSpline(const DataTable &samples, RadialBasisFunctionType type, bool normalized);

    virtual RBFSpline* clone() const { return new RBFSpline(*this); }

    double eval(DenseVector x) const;
    double eval(std::vector<double> x) const;

    DenseMatrix evalJacobian(DenseVector x) const { return DenseMatrix(); }; // TODO: implement via RBF_fn
    DenseMatrix evalHessian(DenseVector x) const { return DenseMatrix(); }; // TODO: implement via RBF_fn
    //    std::vector<double> getDomainUpperBound() const;
    //    std::vector<double> getDomainLowerBound() const;

{'fraction_non_alphanumeric': 0.12103929024081116, 'fraction_numerical': 0.012357414448669201, 'mean_word_length': 3.2340710932260226, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, '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': '4781007', 'n_tokens_mistral': 2295, 'n_tokens_neox': 2209, 'n_words': 588}