working on it
parent
1c17bb8413
commit
6c14bbc941
2
libs/BLT
2
libs/BLT
|
@ -1 +1 @@
|
||||||
Subproject commit 1fdf6f6e894ab223e856d2b750cb6b9daa95ecdd
|
Subproject commit 0b6b6aed9b1fa2428bd665a72149f21f9e0e5d0d
|
|
@ -26,17 +26,17 @@ namespace fb
|
||||||
|
|
||||||
enum class symbolic_regress_function_t
|
enum class symbolic_regress_function_t
|
||||||
{
|
{
|
||||||
ADD, SUB, MUL, DIV, EXP, LOG, SIN, COS
|
ADD, SUB, MUL, DIV, EXP, LOG, SIN, COS, SIZE
|
||||||
};
|
};
|
||||||
|
|
||||||
class test_add_function_t : public function_base_t<test_add_function_t, symbolic_regress_function_t>
|
class test_add_function_t : public function_base_t<test_add_function_t, symbolic_regress_function_t>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test_add_function_t(): function_base_t<test_add_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::ADD, 2)
|
constexpr test_add_function_t(): function_base_t<test_add_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::ADD, 2)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline static T call(T a, T b)
|
constexpr inline static T call(T a, T b)
|
||||||
{
|
{
|
||||||
return a + b;
|
return a + b;
|
||||||
}
|
}
|
||||||
|
@ -45,11 +45,11 @@ namespace fb
|
||||||
class test_sub_function_t : public function_base_t<test_sub_function_t, symbolic_regress_function_t>
|
class test_sub_function_t : public function_base_t<test_sub_function_t, symbolic_regress_function_t>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test_sub_function_t(): function_base_t<test_sub_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::SUB, 2)
|
constexpr test_sub_function_t(): function_base_t<test_sub_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::SUB, 2)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline static T call(T a, T b)
|
constexpr inline static T call(T a, T b)
|
||||||
{
|
{
|
||||||
return a - b;
|
return a - b;
|
||||||
}
|
}
|
||||||
|
@ -58,11 +58,11 @@ namespace fb
|
||||||
class test_mul_function_t : public function_base_t<test_mul_function_t, symbolic_regress_function_t>
|
class test_mul_function_t : public function_base_t<test_mul_function_t, symbolic_regress_function_t>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test_mul_function_t(): function_base_t<test_mul_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::MUL, 2)
|
constexpr test_mul_function_t(): function_base_t<test_mul_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::MUL, 2)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline static T call(T a, T b)
|
constexpr inline static T call(T a, T b)
|
||||||
{
|
{
|
||||||
return a * b;
|
return a * b;
|
||||||
}
|
}
|
||||||
|
@ -71,11 +71,11 @@ namespace fb
|
||||||
class test_div_function_t : public function_base_t<test_div_function_t, symbolic_regress_function_t>
|
class test_div_function_t : public function_base_t<test_div_function_t, symbolic_regress_function_t>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test_div_function_t(): function_base_t<test_div_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::DIV, 2)
|
constexpr test_div_function_t(): function_base_t<test_div_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::DIV, 2)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline static T call(T a, T b)
|
constexpr inline static T call(T a, T b)
|
||||||
{
|
{
|
||||||
if (b == 0)
|
if (b == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -86,11 +86,11 @@ namespace fb
|
||||||
class test_exp_function_t : public function_base_t<test_exp_function_t, symbolic_regress_function_t>
|
class test_exp_function_t : public function_base_t<test_exp_function_t, symbolic_regress_function_t>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test_exp_function_t(): function_base_t<test_exp_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::EXP, 1)
|
constexpr test_exp_function_t(): function_base_t<test_exp_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::EXP, 1)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline static T call(T a)
|
constexpr inline static T call(T a)
|
||||||
{
|
{
|
||||||
return std::exp(a);
|
return std::exp(a);
|
||||||
}
|
}
|
||||||
|
@ -99,11 +99,11 @@ namespace fb
|
||||||
class test_log_function_t : public function_base_t<test_log_function_t, symbolic_regress_function_t>
|
class test_log_function_t : public function_base_t<test_log_function_t, symbolic_regress_function_t>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test_log_function_t(): function_base_t<test_log_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::LOG, 1)
|
constexpr test_log_function_t(): function_base_t<test_log_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::LOG, 1)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline static T call(T a)
|
constexpr inline static T call(T a)
|
||||||
{
|
{
|
||||||
if (a == 0)
|
if (a == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -114,11 +114,11 @@ namespace fb
|
||||||
class test_sin_function_t : public function_base_t<test_sin_function_t, symbolic_regress_function_t>
|
class test_sin_function_t : public function_base_t<test_sin_function_t, symbolic_regress_function_t>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test_sin_function_t(): function_base_t<test_sin_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::SIN, 1)
|
constexpr test_sin_function_t(): function_base_t<test_sin_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::SIN, 1)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline static T call(T a)
|
constexpr inline static T call(T a)
|
||||||
{
|
{
|
||||||
return std::sin(a);
|
return std::sin(a);
|
||||||
}
|
}
|
||||||
|
@ -127,11 +127,11 @@ namespace fb
|
||||||
class test_cos_function_t : public function_base_t<test_cos_function_t, symbolic_regress_function_t>
|
class test_cos_function_t : public function_base_t<test_cos_function_t, symbolic_regress_function_t>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test_cos_function_t(): function_base_t<test_cos_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::COS, 1)
|
constexpr test_cos_function_t(): function_base_t<test_cos_function_t, symbolic_regress_function_t>(symbolic_regress_function_t::COS, 1)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline static T call(T a)
|
constexpr inline static T call(T a)
|
||||||
{
|
{
|
||||||
return std::cos(a);
|
return std::cos(a);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ namespace fb
|
||||||
{
|
{
|
||||||
|
|
||||||
using arg_count_t = blt::size_t;
|
using arg_count_t = blt::size_t;
|
||||||
template<typename... allowed_arg_types>
|
//template<typename... allowed_arg_types>
|
||||||
using arg_t = std::variant<allowed_arg_types...>;
|
//using arg_t = std::variant<allowed_arg_types...>;
|
||||||
|
|
||||||
template<typename BASE, typename ENUM_TYPE, std::enable_if_t<std::is_enum_v<ENUM_TYPE>, bool> = true>
|
template<typename BASE, typename ENUM_TYPE, std::enable_if_t<std::is_enum_v<ENUM_TYPE>, bool> = true>
|
||||||
class function_base_t
|
class function_base_t
|
||||||
|
@ -39,19 +39,19 @@ namespace fb
|
||||||
ENUM_TYPE type_;
|
ENUM_TYPE type_;
|
||||||
arg_count_t args_count_;
|
arg_count_t args_count_;
|
||||||
public:
|
public:
|
||||||
function_base_t(ENUM_TYPE type, arg_count_t args_count): type_(type), args_count_(args_count)
|
constexpr function_base_t(ENUM_TYPE type, arg_count_t args_count): type_(type), args_count_(args_count)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename... arg_types>
|
template<typename... arg_types>
|
||||||
auto operator()(arg_types&& ... args)
|
constexpr auto operator()(arg_types&& ... args) const
|
||||||
{
|
{
|
||||||
return BASE::call(std::forward<arg_types>(args)...);
|
return BASE::call(std::forward<arg_types>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
ENUM_TYPE type()
|
[[nodiscard]] constexpr ENUM_TYPE type() const noexcept
|
||||||
{ return type_; }
|
{ return type_; }
|
||||||
|
|
||||||
arg_count_t argCount()
|
[[nodiscard]] constexpr arg_count_t argCount() const noexcept
|
||||||
{ return args_count_; }
|
{ return args_count_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,16 @@
|
||||||
#include <lilfbtf/tests.h>
|
#include <lilfbtf/tests.h>
|
||||||
#include <lilfbtf/symbol_regression.h>
|
#include <lilfbtf/symbol_regression.h>
|
||||||
#include <blt/std/logging.h>
|
#include <blt/std/logging.h>
|
||||||
|
#include <blt/std/vector.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "blt/std/utility.h"
|
#include "blt/std/utility.h"
|
||||||
|
#include <blt/std/ranges.h>
|
||||||
|
#include <variant>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
namespace fb
|
namespace fb
|
||||||
{
|
{
|
||||||
|
using arg_t = double;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Classes
|
* Classes
|
||||||
|
@ -36,6 +41,130 @@ namespace fb
|
||||||
test_sin_function_t sin_base;
|
test_sin_function_t sin_base;
|
||||||
test_cos_function_t cos_base;
|
test_cos_function_t cos_base;
|
||||||
|
|
||||||
|
#define STATIC_FUNCTION_LIST \
|
||||||
|
STATIC_FUNCTION_APPLY(test_add_function_t, args[0], args[1]) \
|
||||||
|
STATIC_FUNCTION_APPLY(test_sub_function_t, args[0], args[1]) \
|
||||||
|
STATIC_FUNCTION_APPLY(test_mul_function_t, args[0], args[1]) \
|
||||||
|
STATIC_FUNCTION_APPLY(test_div_function_t, args[0], args[1]) \
|
||||||
|
STATIC_FUNCTION_APPLY(test_exp_function_t, args[0]) \
|
||||||
|
STATIC_FUNCTION_APPLY(test_log_function_t, args[0]) \
|
||||||
|
STATIC_FUNCTION_APPLY(test_sin_function_t, args[0]) \
|
||||||
|
STATIC_FUNCTION_APPLY(test_cos_function_t, args[0])
|
||||||
|
|
||||||
|
#define FUNCTION_LIST \
|
||||||
|
FUNCTION_APPLY(add_base, add_t, args[0], args[1]) \
|
||||||
|
FUNCTION_APPLY(sub_base, sub_t, args[0], args[1]) \
|
||||||
|
FUNCTION_APPLY(mul_base, mul_t, args[0], args[1]) \
|
||||||
|
FUNCTION_APPLY(div_base, div_t, args[0], args[1]) \
|
||||||
|
FUNCTION_APPLY(exp_base, exp_t, args[0]) \
|
||||||
|
FUNCTION_APPLY(log_base, log_t, args[0]) \
|
||||||
|
FUNCTION_APPLY(sin_base, sin_t, args[0]) \
|
||||||
|
FUNCTION_APPLY(cos_base, cos_t, args[0])
|
||||||
|
|
||||||
|
class function_virtual_t
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
arg_count_t args_count_;
|
||||||
|
public:
|
||||||
|
explicit function_virtual_t(arg_count_t args_count): args_count_(args_count)
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual arg_t operator()(blt::span<arg_t> args) = 0;
|
||||||
|
|
||||||
|
[[nodiscard]] arg_count_t argCount() const noexcept
|
||||||
|
{
|
||||||
|
return args_count_;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~function_virtual_t() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
// create virtual function variants
|
||||||
|
|
||||||
|
#define FUNCTION_APPLY(type, name, ...) \
|
||||||
|
class function_virtual_##name : public function_virtual_t{ \
|
||||||
|
public: \
|
||||||
|
function_virtual_##name(): function_virtual_t(type.argCount())\
|
||||||
|
{} \
|
||||||
|
\
|
||||||
|
arg_t operator()(blt::span<arg_t> args) final \
|
||||||
|
{ \
|
||||||
|
return type(__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
};
|
||||||
|
|
||||||
|
FUNCTION_LIST
|
||||||
|
|
||||||
|
#undef FUNCTION_APPLY
|
||||||
|
#define FUNCTION_APPLY(type, name, ...) std::make_unique<function_virtual_##name>(),
|
||||||
|
|
||||||
|
std::array<std::unique_ptr<function_virtual_t>, static_cast<int>(symbolic_regress_function_t::SIZE)> virtual_functions = {
|
||||||
|
FUNCTION_LIST
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef FUNCTION_APPLY
|
||||||
|
|
||||||
|
using function_variant = std::variant<test_add_function_t, test_sub_function_t, test_mul_function_t, test_div_function_t, test_exp_function_t, test_log_function_t, test_sin_function_t, test_cos_function_t>;
|
||||||
|
|
||||||
|
#define STATIC_FUNCTION_APPLY(type, ...) \
|
||||||
|
constexpr auto operator()(const type& func){ \
|
||||||
|
return func(__VA_ARGS__); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct function_variant_visitor_apply
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
blt::span<arg_t> args;
|
||||||
|
public:
|
||||||
|
constexpr explicit function_variant_visitor_apply(blt::span<arg_t> args): args(args)
|
||||||
|
{}
|
||||||
|
|
||||||
|
STATIC_FUNCTION_LIST
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef STATIC_FUNCTION_APPLY
|
||||||
|
#define STATIC_FUNCTION_APPLY(type, ...) \
|
||||||
|
constexpr auto operator()(const type& func){ \
|
||||||
|
return func.argCount(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
struct function_variant_visitor_argc
|
||||||
|
{
|
||||||
|
STATIC_FUNCTION_LIST
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class flat_tree
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct node_container
|
||||||
|
{
|
||||||
|
[[nodiscard]] constexpr arg_count_t argCount() const
|
||||||
|
{ return 0; }
|
||||||
|
|
||||||
|
[[nodiscard]] static inline constexpr arg_count_t determine_max_argc()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename NODE_CONTAINER, typename ALLOC>
|
||||||
|
class node_tree
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static ALLOC allocator;
|
||||||
|
struct node
|
||||||
|
{
|
||||||
|
std::array<node*, NODE_CONTAINER::determine_max_argc()> children;
|
||||||
|
NODE_CONTAINER caller;
|
||||||
|
};
|
||||||
|
public:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Functions
|
* Functions
|
||||||
|
@ -47,6 +176,6 @@ namespace fb
|
||||||
(void) tree_min_size;
|
(void) tree_min_size;
|
||||||
(void) tree_max_size;
|
(void) tree_max_size;
|
||||||
|
|
||||||
std::cout << exp_base(population_size) << std::endl;
|
std::cout << log_base(population_size) << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue