pmlpp/mlpp/gan/gan.h

84 lines
2.5 KiB
C
Raw Normal View History

2023-01-24 18:57:18 +01:00
#ifndef MLPP_GAN_H
#define MLPP_GAN_H
2023-01-24 18:57:18 +01:00
//
// GAN.hpp
//
// Created by Marc Melikyan on 11/4/20.
//
2023-01-27 13:01:16 +01:00
#include "core/math/math_defs.h"
2023-02-12 16:28:00 +01:00
#include "core/object/reference.h"
2023-01-24 18:12:23 +01:00
#include "../hidden_layer/hidden_layer.h"
#include "../output_layer/output_layer.h"
#include "../hidden_layer/hidden_layer_old.h"
#include "../output_layer/output_layer_old.h"
#include <string>
2023-01-24 19:00:54 +01:00
#include <tuple>
#include <vector>
2023-02-12 16:28:00 +01:00
class MLPPGAN : public Reference {
GDCLASS(MLPPGAN, Reference);
2023-01-24 19:00:54 +01:00
public:
2023-02-12 10:05:17 +01:00
/*
Ref<MLPPMatrix> get_input_set();
void set_input_set(const Ref<MLPPMatrix> &val);
Ref<MLPPVector> get_output_set();
void set_output_set(const Ref<MLPPVector> &val);
int get_k();
void set_k(const int val);
*/
std::vector<std::vector<real_t>> generate_example(int n);
void gradient_descent(real_t learning_rate, int max_epoch, bool ui = false);
2023-01-27 13:01:16 +01:00
real_t score();
2023-02-12 10:05:17 +01:00
void save(std::string file_name);
void add_layer(int n_hidden, std::string activation, std::string weight_init = "Default", std::string reg = "None", real_t lambda = 0.5, real_t alpha = 0.5);
void add_output_layer(std::string weight_init = "Default", std::string reg = "None", real_t lambda = 0.5, real_t alpha = 0.5);
MLPPGAN(real_t k, std::vector<std::vector<real_t>> output_set);
MLPPGAN();
~MLPPGAN();
protected:
std::vector<std::vector<real_t>> model_set_test_generator(std::vector<std::vector<real_t>> X); // Evaluator for the generator of the gan.
std::vector<real_t> model_set_test_discriminator(std::vector<std::vector<real_t>> X); // Evaluator for the discriminator of the gan.
real_t cost(std::vector<real_t> y_hat, std::vector<real_t> y);
void forward_pass();
2023-02-12 10:05:17 +01:00
void update_discriminator_parameters(std::vector<std::vector<std::vector<real_t>>> hidden_layer_updations, std::vector<real_t> output_layer_updation, real_t learning_rate);
void update_generator_parameters(std::vector<std::vector<std::vector<real_t>>> hidden_layer_updations, real_t learning_rate);
2023-02-12 10:05:17 +01:00
std::tuple<std::vector<std::vector<std::vector<real_t>>>, std::vector<real_t>> compute_discriminator_gradients(std::vector<real_t> y_hat, std::vector<real_t> output_set);
std::vector<std::vector<std::vector<real_t>>> compute_generator_gradients(std::vector<real_t> y_hat, std::vector<real_t> output_set);
2023-02-12 10:05:17 +01:00
void print_ui(int epoch, real_t cost_prev, std::vector<real_t> y_hat, std::vector<real_t> output_set);
2023-02-12 10:05:17 +01:00
static void _bind_methods();
2023-02-12 10:05:17 +01:00
std::vector<std::vector<real_t>> _output_set;
std::vector<real_t> _y_hat;
2023-02-12 10:05:17 +01:00
std::vector<MLPPOldHiddenLayer> _network;
MLPPOldOutputLayer *_output_layer;
2023-02-12 10:05:17 +01:00
int _n;
int _k;
2023-01-24 19:00:54 +01:00
};
2023-01-24 19:20:18 +01:00
#endif /* GAN_hpp */