mirror of
https://github.com/Relintai/pmlpp.git
synced 2024-11-13 13:57:19 +01:00
Rename the GAN class in gan_old.h and cpp to GANOld.
This commit is contained in:
parent
1bb0cab99a
commit
f24bf466c8
@ -14,20 +14,20 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
MLPPGAN::MLPPGAN(real_t k, std::vector<std::vector<real_t>> outputSet) :
|
MLPPGANOld::MLPPGANOld(real_t k, std::vector<std::vector<real_t>> outputSet) :
|
||||||
outputSet(outputSet), n(outputSet.size()), k(k) {
|
outputSet(outputSet), n(outputSet.size()), k(k) {
|
||||||
}
|
}
|
||||||
|
|
||||||
MLPPGAN::~MLPPGAN() {
|
MLPPGANOld::~MLPPGANOld() {
|
||||||
delete outputLayer;
|
delete outputLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> MLPPGAN::generateExample(int n) {
|
std::vector<std::vector<real_t>> MLPPGANOld::generateExample(int n) {
|
||||||
MLPPLinAlg alg;
|
MLPPLinAlg alg;
|
||||||
return modelSetTestGenerator(alg.gaussianNoise(n, k));
|
return modelSetTestGenerator(alg.gaussianNoise(n, k));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MLPPGAN::gradientDescent(real_t learning_rate, int max_epoch, bool UI) {
|
void MLPPGANOld::gradientDescent(real_t learning_rate, int max_epoch, bool UI) {
|
||||||
class MLPPCost cost;
|
class MLPPCost cost;
|
||||||
MLPPLinAlg alg;
|
MLPPLinAlg alg;
|
||||||
real_t cost_prev = 0;
|
real_t cost_prev = 0;
|
||||||
@ -68,7 +68,7 @@ void MLPPGAN::gradientDescent(real_t learning_rate, int max_epoch, bool UI) {
|
|||||||
|
|
||||||
forwardPass();
|
forwardPass();
|
||||||
if (UI) {
|
if (UI) {
|
||||||
MLPPGAN::UI(epoch, cost_prev, MLPPGAN::y_hat, alg.onevec(n));
|
MLPPGANOld::UI(epoch, cost_prev, MLPPGANOld::y_hat, alg.onevec(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
epoch++;
|
epoch++;
|
||||||
@ -78,14 +78,14 @@ void MLPPGAN::gradientDescent(real_t learning_rate, int max_epoch, bool UI) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t MLPPGAN::score() {
|
real_t MLPPGANOld::score() {
|
||||||
MLPPLinAlg alg;
|
MLPPLinAlg alg;
|
||||||
MLPPUtilities util;
|
MLPPUtilities util;
|
||||||
forwardPass();
|
forwardPass();
|
||||||
return util.performance(y_hat, alg.onevec(n));
|
return util.performance(y_hat, alg.onevec(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MLPPGAN::save(std::string fileName) {
|
void MLPPGANOld::save(std::string fileName) {
|
||||||
MLPPUtilities util;
|
MLPPUtilities util;
|
||||||
if (!network.empty()) {
|
if (!network.empty()) {
|
||||||
util.saveParameters(fileName, network[0].weights, network[0].bias, false, 1);
|
util.saveParameters(fileName, network[0].weights, network[0].bias, false, 1);
|
||||||
@ -98,7 +98,7 @@ void MLPPGAN::save(std::string fileName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MLPPGAN::addLayer(int n_hidden, std::string activation, std::string weightInit, std::string reg, real_t lambda, real_t alpha) {
|
void MLPPGANOld::addLayer(int n_hidden, std::string activation, std::string weightInit, std::string reg, real_t lambda, real_t alpha) {
|
||||||
MLPPLinAlg alg;
|
MLPPLinAlg alg;
|
||||||
if (network.empty()) {
|
if (network.empty()) {
|
||||||
network.push_back(MLPPOldHiddenLayer(n_hidden, activation, alg.gaussianNoise(n, k), weightInit, reg, lambda, alpha));
|
network.push_back(MLPPOldHiddenLayer(n_hidden, activation, alg.gaussianNoise(n, k), weightInit, reg, lambda, alpha));
|
||||||
@ -109,7 +109,7 @@ void MLPPGAN::addLayer(int n_hidden, std::string activation, std::string weightI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MLPPGAN::addOutputLayer(std::string weightInit, std::string reg, real_t lambda, real_t alpha) {
|
void MLPPGANOld::addOutputLayer(std::string weightInit, std::string reg, real_t lambda, real_t alpha) {
|
||||||
MLPPLinAlg alg;
|
MLPPLinAlg alg;
|
||||||
if (!network.empty()) {
|
if (!network.empty()) {
|
||||||
outputLayer = new MLPPOldOutputLayer(network[network.size() - 1].n_hidden, "Sigmoid", "LogLoss", network[network.size() - 1].a, weightInit, reg, lambda, alpha);
|
outputLayer = new MLPPOldOutputLayer(network[network.size() - 1].n_hidden, "Sigmoid", "LogLoss", network[network.size() - 1].a, weightInit, reg, lambda, alpha);
|
||||||
@ -118,7 +118,7 @@ void MLPPGAN::addOutputLayer(std::string weightInit, std::string reg, real_t lam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> MLPPGAN::modelSetTestGenerator(std::vector<std::vector<real_t>> X) {
|
std::vector<std::vector<real_t>> MLPPGANOld::modelSetTestGenerator(std::vector<std::vector<real_t>> X) {
|
||||||
if (!network.empty()) {
|
if (!network.empty()) {
|
||||||
network[0].input = X;
|
network[0].input = X;
|
||||||
network[0].forwardPass();
|
network[0].forwardPass();
|
||||||
@ -131,7 +131,7 @@ std::vector<std::vector<real_t>> MLPPGAN::modelSetTestGenerator(std::vector<std:
|
|||||||
return network[network.size() / 2].a;
|
return network[network.size() / 2].a;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<real_t> MLPPGAN::modelSetTestDiscriminator(std::vector<std::vector<real_t>> X) {
|
std::vector<real_t> MLPPGANOld::modelSetTestDiscriminator(std::vector<std::vector<real_t>> X) {
|
||||||
if (!network.empty()) {
|
if (!network.empty()) {
|
||||||
for (uint32_t i = network.size() / 2 + 1; i < network.size(); i++) {
|
for (uint32_t i = network.size() / 2 + 1; i < network.size(); i++) {
|
||||||
if (i == network.size() / 2 + 1) {
|
if (i == network.size() / 2 + 1) {
|
||||||
@ -147,7 +147,7 @@ std::vector<real_t> MLPPGAN::modelSetTestDiscriminator(std::vector<std::vector<r
|
|||||||
return outputLayer->a;
|
return outputLayer->a;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t MLPPGAN::Cost(std::vector<real_t> y_hat, std::vector<real_t> y) {
|
real_t MLPPGANOld::Cost(std::vector<real_t> y_hat, std::vector<real_t> y) {
|
||||||
MLPPReg regularization;
|
MLPPReg regularization;
|
||||||
class MLPPCost cost;
|
class MLPPCost cost;
|
||||||
real_t totalRegTerm = 0;
|
real_t totalRegTerm = 0;
|
||||||
@ -161,7 +161,7 @@ real_t MLPPGAN::Cost(std::vector<real_t> y_hat, std::vector<real_t> y) {
|
|||||||
return (cost.*cost_function)(y_hat, y) + totalRegTerm + regularization.regTerm(outputLayer->weights, outputLayer->lambda, outputLayer->alpha, outputLayer->reg);
|
return (cost.*cost_function)(y_hat, y) + totalRegTerm + regularization.regTerm(outputLayer->weights, outputLayer->lambda, outputLayer->alpha, outputLayer->reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MLPPGAN::forwardPass() {
|
void MLPPGANOld::forwardPass() {
|
||||||
MLPPLinAlg alg;
|
MLPPLinAlg alg;
|
||||||
if (!network.empty()) {
|
if (!network.empty()) {
|
||||||
network[0].input = alg.gaussianNoise(n, k);
|
network[0].input = alg.gaussianNoise(n, k);
|
||||||
@ -179,7 +179,7 @@ void MLPPGAN::forwardPass() {
|
|||||||
y_hat = outputLayer->a;
|
y_hat = outputLayer->a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MLPPGAN::updateDiscriminatorParameters(std::vector<std::vector<std::vector<real_t>>> hiddenLayerUpdations, std::vector<real_t> outputLayerUpdation, real_t learning_rate) {
|
void MLPPGANOld::updateDiscriminatorParameters(std::vector<std::vector<std::vector<real_t>>> hiddenLayerUpdations, std::vector<real_t> outputLayerUpdation, real_t learning_rate) {
|
||||||
MLPPLinAlg alg;
|
MLPPLinAlg alg;
|
||||||
|
|
||||||
outputLayer->weights = alg.subtraction(outputLayer->weights, outputLayerUpdation);
|
outputLayer->weights = alg.subtraction(outputLayer->weights, outputLayerUpdation);
|
||||||
@ -196,7 +196,7 @@ void MLPPGAN::updateDiscriminatorParameters(std::vector<std::vector<std::vector<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MLPPGAN::updateGeneratorParameters(std::vector<std::vector<std::vector<real_t>>> hiddenLayerUpdations, real_t learning_rate) {
|
void MLPPGANOld::updateGeneratorParameters(std::vector<std::vector<std::vector<real_t>>> hiddenLayerUpdations, real_t learning_rate) {
|
||||||
MLPPLinAlg alg;
|
MLPPLinAlg alg;
|
||||||
|
|
||||||
if (!network.empty()) {
|
if (!network.empty()) {
|
||||||
@ -209,7 +209,7 @@ void MLPPGAN::updateGeneratorParameters(std::vector<std::vector<std::vector<real
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<std::vector<std::vector<std::vector<real_t>>>, std::vector<real_t>> MLPPGAN::computeDiscriminatorGradients(std::vector<real_t> y_hat, std::vector<real_t> outputSet) {
|
std::tuple<std::vector<std::vector<std::vector<real_t>>>, std::vector<real_t>> MLPPGANOld::computeDiscriminatorGradients(std::vector<real_t> y_hat, std::vector<real_t> outputSet) {
|
||||||
class MLPPCost cost;
|
class MLPPCost cost;
|
||||||
MLPPActivation avn;
|
MLPPActivation avn;
|
||||||
MLPPLinAlg alg;
|
MLPPLinAlg alg;
|
||||||
@ -245,7 +245,7 @@ std::tuple<std::vector<std::vector<std::vector<real_t>>>, std::vector<real_t>> M
|
|||||||
return { cumulativeHiddenLayerWGrad, outputWGrad };
|
return { cumulativeHiddenLayerWGrad, outputWGrad };
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::vector<std::vector<real_t>>> MLPPGAN::computeGeneratorGradients(std::vector<real_t> y_hat, std::vector<real_t> outputSet) {
|
std::vector<std::vector<std::vector<real_t>>> MLPPGANOld::computeGeneratorGradients(std::vector<real_t> y_hat, std::vector<real_t> outputSet) {
|
||||||
class MLPPCost cost;
|
class MLPPCost cost;
|
||||||
MLPPActivation avn;
|
MLPPActivation avn;
|
||||||
MLPPLinAlg alg;
|
MLPPLinAlg alg;
|
||||||
@ -274,7 +274,7 @@ std::vector<std::vector<std::vector<real_t>>> MLPPGAN::computeGeneratorGradients
|
|||||||
return cumulativeHiddenLayerWGrad;
|
return cumulativeHiddenLayerWGrad;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MLPPGAN::UI(int epoch, real_t cost_prev, std::vector<real_t> y_hat, std::vector<real_t> outputSet) {
|
void MLPPGANOld::UI(int epoch, real_t cost_prev, std::vector<real_t> y_hat, std::vector<real_t> outputSet) {
|
||||||
MLPPUtilities::CostInfo(epoch, cost_prev, Cost(y_hat, outputSet));
|
MLPPUtilities::CostInfo(epoch, cost_prev, Cost(y_hat, outputSet));
|
||||||
std::cout << "Layer " << network.size() + 1 << ": " << std::endl;
|
std::cout << "Layer " << network.size() + 1 << ": " << std::endl;
|
||||||
MLPPUtilities::UI(outputLayer->weights, outputLayer->bias);
|
MLPPUtilities::UI(outputLayer->weights, outputLayer->bias);
|
||||||
|
@ -20,10 +20,10 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class MLPPGAN {
|
class MLPPGANOld {
|
||||||
public:
|
public:
|
||||||
MLPPGAN(real_t k, std::vector<std::vector<real_t>> outputSet);
|
MLPPGANOld(real_t k, std::vector<std::vector<real_t>> outputSet);
|
||||||
~MLPPGAN();
|
~MLPPGANOld();
|
||||||
std::vector<std::vector<real_t>> generateExample(int n);
|
std::vector<std::vector<real_t>> generateExample(int n);
|
||||||
void gradientDescent(real_t learning_rate, int max_epoch, bool UI = false);
|
void gradientDescent(real_t learning_rate, int max_epoch, bool UI = false);
|
||||||
real_t score();
|
real_t score();
|
||||||
|
Loading…
Reference in New Issue
Block a user