2024-02-19 15:55:54 -05:00
|
|
|
/*
|
|
|
|
* <Short Description>
|
|
|
|
* Copyright (C) 2024 Brett Terpstra
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LILFBTF5_SYMBOL_REGRESSION_H
|
|
|
|
#define LILFBTF5_SYMBOL_REGRESSION_H
|
|
|
|
|
|
|
|
#include <lilfbtf/tests.h>
|
|
|
|
|
|
|
|
namespace fb
|
|
|
|
{
|
|
|
|
|
|
|
|
enum class symbolic_regress_function_t
|
|
|
|
{
|
2024-02-20 15:18:19 -05:00
|
|
|
ADD, SUB, MUL, DIV, EXP, LOG, SIN, COS, SIZE
|
2024-02-19 15:55:54 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class test_add_function_t : public function_base_t<test_add_function_t, symbolic_regress_function_t>
|
|
|
|
{
|
|
|
|
public:
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr test_add_function_t(): function_base_t<test_add_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::ADD, 2)
|
2024-02-19 15:55:54 -05:00
|
|
|
{}
|
|
|
|
|
|
|
|
template<typename T>
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr inline static T call(T a, T b)
|
2024-02-19 15:55:54 -05:00
|
|
|
{
|
|
|
|
return a + b;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class test_sub_function_t : public function_base_t<test_sub_function_t, symbolic_regress_function_t>
|
|
|
|
{
|
|
|
|
public:
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr test_sub_function_t(): function_base_t<test_sub_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::SUB, 2)
|
2024-02-19 15:55:54 -05:00
|
|
|
{}
|
|
|
|
|
|
|
|
template<typename T>
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr inline static T call(T a, T b)
|
2024-02-19 15:55:54 -05:00
|
|
|
{
|
|
|
|
return a - b;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class test_mul_function_t : public function_base_t<test_mul_function_t, symbolic_regress_function_t>
|
|
|
|
{
|
|
|
|
public:
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr test_mul_function_t(): function_base_t<test_mul_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::MUL, 2)
|
2024-02-19 15:55:54 -05:00
|
|
|
{}
|
|
|
|
|
|
|
|
template<typename T>
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr inline static T call(T a, T b)
|
2024-02-19 15:55:54 -05:00
|
|
|
{
|
|
|
|
return a * b;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class test_div_function_t : public function_base_t<test_div_function_t, symbolic_regress_function_t>
|
|
|
|
{
|
|
|
|
public:
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr test_div_function_t(): function_base_t<test_div_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::DIV, 2)
|
2024-02-19 15:55:54 -05:00
|
|
|
{}
|
|
|
|
|
|
|
|
template<typename T>
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr inline static T call(T a, T b)
|
2024-02-19 15:55:54 -05:00
|
|
|
{
|
|
|
|
if (b == 0)
|
|
|
|
return 0;
|
|
|
|
return a / b;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class test_exp_function_t : public function_base_t<test_exp_function_t, symbolic_regress_function_t>
|
|
|
|
{
|
|
|
|
public:
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr test_exp_function_t(): function_base_t<test_exp_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::EXP, 1)
|
2024-02-19 15:55:54 -05:00
|
|
|
{}
|
|
|
|
|
|
|
|
template<typename T>
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr inline static T call(T a)
|
2024-02-19 15:55:54 -05:00
|
|
|
{
|
|
|
|
return std::exp(a);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class test_log_function_t : public function_base_t<test_log_function_t, symbolic_regress_function_t>
|
|
|
|
{
|
|
|
|
public:
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr test_log_function_t(): function_base_t<test_log_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::LOG, 1)
|
2024-02-19 15:55:54 -05:00
|
|
|
{}
|
|
|
|
|
|
|
|
template<typename T>
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr inline static T call(T a)
|
2024-02-19 15:55:54 -05:00
|
|
|
{
|
|
|
|
if (a == 0)
|
|
|
|
return 0;
|
|
|
|
return std::log(a);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class test_sin_function_t : public function_base_t<test_sin_function_t, symbolic_regress_function_t>
|
|
|
|
{
|
|
|
|
public:
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr test_sin_function_t(): function_base_t<test_sin_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::SIN, 1)
|
2024-02-19 15:55:54 -05:00
|
|
|
{}
|
|
|
|
|
|
|
|
template<typename T>
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr inline static T call(T a)
|
2024-02-19 15:55:54 -05:00
|
|
|
{
|
|
|
|
return std::sin(a);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class test_cos_function_t : public function_base_t<test_cos_function_t, symbolic_regress_function_t>
|
|
|
|
{
|
|
|
|
public:
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr test_cos_function_t(): function_base_t<test_cos_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::COS, 1)
|
2024-02-19 15:55:54 -05:00
|
|
|
{}
|
|
|
|
|
|
|
|
template<typename T>
|
2024-02-20 15:18:19 -05:00
|
|
|
constexpr inline static T call(T a)
|
2024-02-19 15:55:54 -05:00
|
|
|
{
|
|
|
|
return std::cos(a);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //LILFBTF5_SYMBOL_REGRESSION_H
|