mirror of
https://github.com/Relintai/pmlpp.git
synced 2025-03-12 22:38:51 +01:00
Also added bindings for MLPPHiddenLayer.
This commit is contained in:
parent
1aa239720b
commit
6132c85b46
@ -11,6 +11,104 @@
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
|
||||
int MLPPHiddenLayer::get_n_hidden() {
|
||||
return n_hidden;
|
||||
}
|
||||
void MLPPHiddenLayer::set_n_hidden(const int val) {
|
||||
n_hidden = val;
|
||||
}
|
||||
|
||||
MLPPActivation::ActivationFunction MLPPHiddenLayer::get_activation() {
|
||||
return activation;
|
||||
}
|
||||
void MLPPHiddenLayer::set_activation(const MLPPActivation::ActivationFunction val) {
|
||||
activation = val;
|
||||
}
|
||||
|
||||
Ref<MLPPMatrix> MLPPHiddenLayer::get_input() {
|
||||
return input;
|
||||
}
|
||||
void MLPPHiddenLayer::set_input(const Ref<MLPPMatrix> &val) {
|
||||
input = val;
|
||||
}
|
||||
|
||||
Ref<MLPPMatrix> MLPPHiddenLayer::get_weights() {
|
||||
return weights;
|
||||
}
|
||||
void MLPPHiddenLayer::set_weights(const Ref<MLPPMatrix> &val) {
|
||||
weights = val;
|
||||
}
|
||||
|
||||
Ref<MLPPVector> MLPPHiddenLayer::MLPPHiddenLayer::get_bias() {
|
||||
return bias;
|
||||
}
|
||||
void MLPPHiddenLayer::set_bias(const Ref<MLPPVector> &val) {
|
||||
bias = val;
|
||||
}
|
||||
|
||||
Ref<MLPPMatrix> MLPPHiddenLayer::get_z() {
|
||||
return z;
|
||||
}
|
||||
void MLPPHiddenLayer::set_z(const Ref<MLPPMatrix> &val) {
|
||||
z = val;
|
||||
}
|
||||
|
||||
Ref<MLPPMatrix> MLPPHiddenLayer::get_a() {
|
||||
return a;
|
||||
}
|
||||
void MLPPHiddenLayer::set_a(const Ref<MLPPMatrix> &val) {
|
||||
a = val;
|
||||
}
|
||||
|
||||
Ref<MLPPVector> MLPPHiddenLayer::get_z_test() {
|
||||
return z_test;
|
||||
}
|
||||
void MLPPHiddenLayer::set_z_test(const Ref<MLPPVector> &val) {
|
||||
z_test = val;
|
||||
}
|
||||
|
||||
Ref<MLPPVector> MLPPHiddenLayer::get_a_test() {
|
||||
return a_test;
|
||||
}
|
||||
void MLPPHiddenLayer::set_a_test(const Ref<MLPPVector> &val) {
|
||||
a_test = val;
|
||||
}
|
||||
|
||||
Ref<MLPPMatrix> MLPPHiddenLayer::get_delta() {
|
||||
return delta;
|
||||
}
|
||||
void MLPPHiddenLayer::set_delta(const Ref<MLPPMatrix> &val) {
|
||||
delta = val;
|
||||
}
|
||||
|
||||
MLPPReg::RegularizationType MLPPHiddenLayer::get_reg() {
|
||||
return reg;
|
||||
}
|
||||
void MLPPHiddenLayer::set_reg(const MLPPReg::RegularizationType val) {
|
||||
reg = val;
|
||||
}
|
||||
|
||||
real_t MLPPHiddenLayer::get_lambda() {
|
||||
return lambda;
|
||||
}
|
||||
void MLPPHiddenLayer::set_lambda(const real_t val) {
|
||||
lambda = val;
|
||||
}
|
||||
|
||||
real_t MLPPHiddenLayer::get_alpha() {
|
||||
return alpha;
|
||||
}
|
||||
void MLPPHiddenLayer::set_alpha(const real_t val) {
|
||||
alpha = val;
|
||||
}
|
||||
|
||||
MLPPUtilities::WeightDistributionType MLPPHiddenLayer::get_weight_init() {
|
||||
return weight_init;
|
||||
}
|
||||
void MLPPHiddenLayer::set_weight_init(const MLPPUtilities::WeightDistributionType val) {
|
||||
weight_init = val;
|
||||
}
|
||||
|
||||
void MLPPHiddenLayer::forward_pass() {
|
||||
MLPPLinAlg alg;
|
||||
MLPPActivation avn;
|
||||
@ -85,6 +183,67 @@ MLPPHiddenLayer::MLPPHiddenLayer() {
|
||||
MLPPHiddenLayer::~MLPPHiddenLayer() {
|
||||
}
|
||||
|
||||
void MLPPHiddenLayer::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_n_hidden"), &MLPPHiddenLayer::get_n_hidden);
|
||||
ClassDB::bind_method(D_METHOD("set_n_hidden", "val"), &MLPPHiddenLayer::set_n_hidden);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "n_hidden"), "set_n_hidden", "get_n_hidden");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_activation"), &MLPPHiddenLayer::get_activation);
|
||||
ClassDB::bind_method(D_METHOD("set_activation", "val"), &MLPPHiddenLayer::set_activation);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "activation"), "set_activation", "get_activation");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_input"), &MLPPHiddenLayer::get_input);
|
||||
ClassDB::bind_method(D_METHOD("set_input", "val"), &MLPPHiddenLayer::set_input);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "MLPPMatrix"), "set_input", "get_input");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_weights"), &MLPPHiddenLayer::get_weights);
|
||||
ClassDB::bind_method(D_METHOD("set_weights", "val"), &MLPPHiddenLayer::set_weights);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "weights", PROPERTY_HINT_RESOURCE_TYPE, "MLPPMatrix"), "set_weights", "get_weights");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_bias"), &MLPPHiddenLayer::get_bias);
|
||||
ClassDB::bind_method(D_METHOD("set_bias", "val"), &MLPPHiddenLayer::set_bias);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "bias", PROPERTY_HINT_RESOURCE_TYPE, "MLPPVector"), "set_bias", "get_bias");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_z"), &MLPPHiddenLayer::get_z);
|
||||
ClassDB::bind_method(D_METHOD("set_z", "val"), &MLPPHiddenLayer::set_z);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "z", PROPERTY_HINT_RESOURCE_TYPE, "MLPPMatrix"), "set_z", "get_z");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_a"), &MLPPHiddenLayer::get_a);
|
||||
ClassDB::bind_method(D_METHOD("set_a", "val"), &MLPPHiddenLayer::set_a);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "a", PROPERTY_HINT_RESOURCE_TYPE, "MLPPMatrix"), "set_a", "get_a");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_z_test"), &MLPPHiddenLayer::get_z_test);
|
||||
ClassDB::bind_method(D_METHOD("set_z_test", "val"), &MLPPHiddenLayer::set_z_test);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "z_test", PROPERTY_HINT_RESOURCE_TYPE, "MLPPVector"), "set_z_test", "get_z_test");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_a_test"), &MLPPHiddenLayer::get_a_test);
|
||||
ClassDB::bind_method(D_METHOD("set_a_test", "val"), &MLPPHiddenLayer::set_a_test);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "a_test", PROPERTY_HINT_RESOURCE_TYPE, "MLPPVector"), "set_a_test", "get_a_test");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_delta"), &MLPPHiddenLayer::get_delta);
|
||||
ClassDB::bind_method(D_METHOD("set_delta", "val"), &MLPPHiddenLayer::set_delta);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "delta", PROPERTY_HINT_RESOURCE_TYPE, "MLPPMatrix"), "set_delta", "get_delta");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_reg"), &MLPPHiddenLayer::get_reg);
|
||||
ClassDB::bind_method(D_METHOD("set_reg", "val"), &MLPPHiddenLayer::set_reg);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "reg"), "set_reg", "get_reg");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_lambda"), &MLPPHiddenLayer::get_lambda);
|
||||
ClassDB::bind_method(D_METHOD("set_lambda", "val"), &MLPPHiddenLayer::set_lambda);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "lambda"), "set_lambda", "get_lambda");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_alpha"), &MLPPHiddenLayer::get_alpha);
|
||||
ClassDB::bind_method(D_METHOD("set_alpha", "val"), &MLPPHiddenLayer::set_alpha);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "alpha"), "set_alpha", "get_alpha");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_weight_init"), &MLPPHiddenLayer::get_weight_init);
|
||||
ClassDB::bind_method(D_METHOD("set_weight_init", "val"), &MLPPHiddenLayer::set_weight_init);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "set_weight_init"), "set_weight_init", "get_weight_init");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("forward_pass"), &MLPPHiddenLayer::forward_pass);
|
||||
ClassDB::bind_method(D_METHOD("test", "x"), &MLPPHiddenLayer::test);
|
||||
}
|
||||
|
||||
MLPPOldHiddenLayer::MLPPOldHiddenLayer(int n_hidden, std::string activation, std::vector<std::vector<real_t>> input, std::string weightInit, std::string reg, real_t lambda, real_t alpha) :
|
||||
n_hidden(n_hidden), activation(activation), input(input), weightInit(weightInit), reg(reg), lambda(lambda), alpha(alpha) {
|
||||
weights = MLPPUtilities::weightInitialization(input[0].size(), n_hidden, weightInit);
|
||||
|
@ -15,8 +15,8 @@
|
||||
#include "core/object/reference.h"
|
||||
|
||||
#include "../activation/activation.h"
|
||||
#include "../utilities/utilities.h"
|
||||
#include "../regularization/reg.h"
|
||||
#include "../utilities/utilities.h"
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
@ -29,6 +29,59 @@ class MLPPHiddenLayer : public Reference {
|
||||
GDCLASS(MLPPHiddenLayer, Reference);
|
||||
|
||||
public:
|
||||
int get_n_hidden();
|
||||
void set_n_hidden(const int val);
|
||||
|
||||
MLPPActivation::ActivationFunction get_activation();
|
||||
void set_activation(const MLPPActivation::ActivationFunction val);
|
||||
|
||||
Ref<MLPPMatrix> get_input();
|
||||
void set_input(const Ref<MLPPMatrix> &val);
|
||||
|
||||
Ref<MLPPMatrix> get_weights();
|
||||
void set_weights(const Ref<MLPPMatrix> &val);
|
||||
|
||||
Ref<MLPPVector> get_bias();
|
||||
void set_bias(const Ref<MLPPVector> &val);
|
||||
|
||||
Ref<MLPPMatrix> get_z();
|
||||
void set_z(const Ref<MLPPMatrix> &val);
|
||||
|
||||
Ref<MLPPMatrix> get_a();
|
||||
void set_a(const Ref<MLPPMatrix> &val);
|
||||
|
||||
Ref<MLPPVector> get_z_test();
|
||||
void set_z_test(const Ref<MLPPVector> &val);
|
||||
|
||||
Ref<MLPPVector> get_a_test();
|
||||
void set_a_test(const Ref<MLPPVector> &val);
|
||||
|
||||
Ref<MLPPMatrix> get_delta();
|
||||
void set_delta(const Ref<MLPPMatrix> &val);
|
||||
|
||||
MLPPReg::RegularizationType get_reg();
|
||||
void set_reg(const MLPPReg::RegularizationType val);
|
||||
|
||||
real_t get_lambda();
|
||||
void set_lambda(const real_t val);
|
||||
|
||||
real_t get_alpha();
|
||||
void set_alpha(const real_t val);
|
||||
|
||||
MLPPUtilities::WeightDistributionType get_weight_init();
|
||||
void set_weight_init(const MLPPUtilities::WeightDistributionType val);
|
||||
|
||||
void forward_pass();
|
||||
void test(const Ref<MLPPVector> &x);
|
||||
|
||||
MLPPHiddenLayer(int p_n_hidden, MLPPActivation::ActivationFunction p_activation, Ref<MLPPMatrix> p_input, MLPPUtilities::WeightDistributionType p_weight_init, MLPPReg::RegularizationType p_reg, real_t p_lambda, real_t p_alpha);
|
||||
|
||||
MLPPHiddenLayer();
|
||||
~MLPPHiddenLayer();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
int n_hidden;
|
||||
MLPPActivation::ActivationFunction activation;
|
||||
|
||||
@ -51,17 +104,8 @@ public:
|
||||
real_t alpha; /* This is the controlling param for Elastic Net*/
|
||||
|
||||
MLPPUtilities::WeightDistributionType weight_init;
|
||||
|
||||
void forward_pass();
|
||||
void test(const Ref<MLPPVector> &x);
|
||||
|
||||
MLPPHiddenLayer(int p_n_hidden, MLPPActivation::ActivationFunction p_activation, Ref<MLPPMatrix> p_input, MLPPUtilities::WeightDistributionType p_weight_init, MLPPReg::RegularizationType p_reg, real_t p_lambda, real_t p_alpha);
|
||||
|
||||
MLPPHiddenLayer();
|
||||
~MLPPHiddenLayer();
|
||||
};
|
||||
|
||||
|
||||
class MLPPOldHiddenLayer {
|
||||
public:
|
||||
MLPPOldHiddenLayer(int n_hidden, std::string activation, std::vector<std::vector<real_t>> input, std::string weightInit, std::string reg, real_t lambda, real_t alpha);
|
||||
|
@ -29,9 +29,10 @@ SOFTWARE.
|
||||
|
||||
#include "mlpp/regularization/reg.h"
|
||||
#include "mlpp/utilities/utilities.h"
|
||||
|
||||
#include "mlpp/activation/activation.h"
|
||||
|
||||
#include "mlpp/hidden_layer/hidden_layer.h"
|
||||
|
||||
#include "mlpp/kmeans/kmeans.h"
|
||||
#include "mlpp/knn/knn.h"
|
||||
|
||||
@ -44,9 +45,10 @@ void register_pmlpp_types(ModuleRegistrationLevel p_level) {
|
||||
|
||||
ClassDB::register_class<MLPPUtilities>();
|
||||
ClassDB::register_class<MLPPReg>();
|
||||
|
||||
ClassDB::register_class<MLPPActivation>();
|
||||
|
||||
ClassDB::register_class<MLPPHiddenLayer>();
|
||||
|
||||
ClassDB::register_class<MLPPKNN>();
|
||||
ClassDB::register_class<MLPPKMeans>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user