mirror of
https://github.com/Relintai/MLPP.git
synced 2024-11-12 10:15:01 +01:00
changes to .so
This commit is contained in:
parent
983a81d54f
commit
1523eea7b8
@ -12,6 +12,7 @@
|
||||
#include "Cost/Cost.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
namespace MLPP {
|
||||
ANN::ANN(std::vector<std::vector<double>> inputSet, std::vector<double> outputSet)
|
||||
@ -306,11 +307,11 @@ void ANN::Adam(double learning_rate, int max_epoch, int mini_batch_size, double
|
||||
m_output = alg.addition(alg.scalarMultiply(b1, m_output), alg.scalarMultiply(1 - b1, outputWGrad));
|
||||
v_output = alg.addition(alg.scalarMultiply(b2, v_output), alg.scalarMultiply(1 - b2, alg.exponentiate(outputWGrad, 2)));
|
||||
|
||||
std::vector<std::vector<std::vector<double>>> m_hidden_hat = alg.scalarMultiply(1/(1 - pow(b1, epoch)), m_hidden);
|
||||
std::vector<std::vector<std::vector<double>>> v_hidden_hat = alg.scalarMultiply(1/(1 - pow(b2, epoch)), v_hidden);
|
||||
std::vector<std::vector<std::vector<double>>> m_hidden_hat = alg.scalarMultiply(1/(1 - std::pow(b1, epoch)), m_hidden);
|
||||
std::vector<std::vector<std::vector<double>>> v_hidden_hat = alg.scalarMultiply(1/(1 - std::pow(b2, epoch)), v_hidden);
|
||||
|
||||
std::vector<double> m_output_hat = alg.scalarMultiply(1/(1 - pow(b1, epoch)), m_output);
|
||||
std::vector<double> v_output_hat = alg.scalarMultiply(1/(1 - pow(b2, epoch)), v_output);
|
||||
std::vector<double> m_output_hat = alg.scalarMultiply(1/(1 - std::pow(b1, epoch)), m_output);
|
||||
std::vector<double> v_output_hat = alg.scalarMultiply(1/(1 - std::pow(b2, epoch)), v_output);
|
||||
|
||||
std::vector<std::vector<std::vector<double>>> hiddenLayerUpdations = alg.scalarMultiply(learning_rate/n, alg.elementWiseDivision(m_hidden_hat, alg.scalarAdd(e, alg.sqrt(v_hidden_hat))));
|
||||
std::vector<double> outputLayerUpdation = alg.scalarMultiply(learning_rate/n, alg.elementWiseDivision(m_output_hat, alg.scalarAdd(e, alg.sqrt(v_output_hat))));
|
||||
@ -368,9 +369,9 @@ void ANN::Adam(double learning_rate, int max_epoch, int mini_batch_size, double
|
||||
m_output = alg.addition(alg.scalarMultiply(b1, m_output), alg.scalarMultiply(1 - b1, outputWGrad));
|
||||
u_output = alg.max(alg.scalarMultiply(b2, u_output), alg.abs(outputWGrad));
|
||||
|
||||
std::vector<std::vector<std::vector<double>>> m_hidden_hat = alg.scalarMultiply(1/(1 - pow(b1, epoch)), m_hidden);
|
||||
std::vector<std::vector<std::vector<double>>> m_hidden_hat = alg.scalarMultiply(1/(1 - std::pow(b1, epoch)), m_hidden);
|
||||
|
||||
std::vector<double> m_output_hat = alg.scalarMultiply(1/(1 - pow(b1, epoch)), m_output);
|
||||
std::vector<double> m_output_hat = alg.scalarMultiply(1/(1 - std::pow(b1, epoch)), m_output);
|
||||
|
||||
std::vector<std::vector<std::vector<double>>> hiddenLayerUpdations = alg.scalarMultiply(learning_rate/n, alg.elementWiseDivision(m_hidden_hat, alg.scalarAdd(e, u_hidden)));
|
||||
std::vector<double> outputLayerUpdation = alg.scalarMultiply(learning_rate/n, alg.elementWiseDivision(m_output_hat, alg.scalarAdd(e, u_output)));
|
||||
@ -430,13 +431,13 @@ void ANN::Adam(double learning_rate, int max_epoch, int mini_batch_size, double
|
||||
m_output = alg.addition(alg.scalarMultiply(b1, m_output), alg.scalarMultiply(1 - b1, outputWGrad));
|
||||
v_output = alg.addition(alg.scalarMultiply(b2, v_output), alg.scalarMultiply(1 - b2, alg.exponentiate(outputWGrad, 2)));
|
||||
|
||||
std::vector<std::vector<std::vector<double>>> m_hidden_hat = alg.scalarMultiply(1/(1 - pow(b1, epoch)), m_hidden);
|
||||
std::vector<std::vector<std::vector<double>>> v_hidden_hat = alg.scalarMultiply(1/(1 - pow(b2, epoch)), v_hidden);
|
||||
std::vector<std::vector<std::vector<double>>> m_hidden_final = alg.addition(alg.scalarMultiply(b1, m_hidden_hat), alg.scalarMultiply((1 - b1)/(1 - pow(b1, epoch)), cumulativeHiddenLayerWGrad));
|
||||
std::vector<std::vector<std::vector<double>>> m_hidden_hat = alg.scalarMultiply(1/(1 - std::pow(b1, epoch)), m_hidden);
|
||||
std::vector<std::vector<std::vector<double>>> v_hidden_hat = alg.scalarMultiply(1/(1 - std::pow(b2, epoch)), v_hidden);
|
||||
std::vector<std::vector<std::vector<double>>> m_hidden_final = alg.addition(alg.scalarMultiply(b1, m_hidden_hat), alg.scalarMultiply((1 - b1)/(1 - std::pow(b1, epoch)), cumulativeHiddenLayerWGrad));
|
||||
|
||||
std::vector<double> m_output_hat = alg.scalarMultiply(1/(1 - pow(b1, epoch)), m_output);
|
||||
std::vector<double> v_output_hat = alg.scalarMultiply(1/(1 - pow(b2, epoch)), v_output);
|
||||
std::vector<double> m_output_final = alg.addition(alg.scalarMultiply(b1, m_output_hat), alg.scalarMultiply((1 - b1)/(1 - pow(b1, epoch)), outputWGrad));
|
||||
std::vector<double> m_output_hat = alg.scalarMultiply(1/(1 - std::pow(b1, epoch)), m_output);
|
||||
std::vector<double> v_output_hat = alg.scalarMultiply(1/(1 - std::pow(b2, epoch)), v_output);
|
||||
std::vector<double> m_output_final = alg.addition(alg.scalarMultiply(b1, m_output_hat), alg.scalarMultiply((1 - b1)/(1 - std::pow(b1, epoch)), outputWGrad));
|
||||
|
||||
std::vector<std::vector<std::vector<double>>> hiddenLayerUpdations = alg.scalarMultiply(learning_rate/n, alg.elementWiseDivision(m_hidden_final, alg.scalarAdd(e, alg.sqrt(v_hidden_hat))));
|
||||
std::vector<double> outputLayerUpdation = alg.scalarMultiply(learning_rate/n, alg.elementWiseDivision(m_output_final, alg.scalarAdd(e, alg.sqrt(v_output_hat))));
|
||||
|
@ -546,9 +546,9 @@ namespace MLPP{
|
||||
|
||||
double Activation::GELU(double z, bool deriv){
|
||||
if (deriv){
|
||||
return 0.5 * tanh(0.0356774 * pow(z, 3) + 0.797885 * z) + (0.0535161 * pow(z, 3) + 0.398942 * z) * pow(sech(0.0356774 * pow(z, 3) + 0.797885 * z), 2) + 0.5;
|
||||
return 0.5 * tanh(0.0356774 * std::pow(z, 3) + 0.797885 * z) + (0.0535161 * std::pow(z, 3) + 0.398942 * z) * std::pow(sech(0.0356774 * std::pow(z, 3) + 0.797885 * z), 2) + 0.5;
|
||||
}
|
||||
return 0.5 * z * (1 + tanh(sqrt(2/M_PI) * (z + 0.044715 * pow(z, 3))));
|
||||
return 0.5 * z * (1 + tanh(sqrt(2/M_PI) * (z + 0.044715 * std::pow(z, 3))));
|
||||
}
|
||||
|
||||
std::vector<double> Activation::GELU(std::vector<double> z, bool deriv){
|
||||
|
@ -49,14 +49,14 @@ namespace MLPP{
|
||||
// Calculating the weight gradient
|
||||
double sum = 0;
|
||||
for(int j = 0; j < n; j++){
|
||||
sum += error[j] * inputSet[j][i] * pow(weights[i], inputSet[j][i] - 1);
|
||||
sum += error[j] * inputSet[j][i] * std::pow(weights[i], inputSet[j][i] - 1);
|
||||
}
|
||||
double w_gradient = sum / n;
|
||||
|
||||
// Calculating the initial gradient
|
||||
double sum2 = 0;
|
||||
for(int j = 0; j < n; j++){
|
||||
sum2 += error[j] * pow(weights[i], inputSet[j][i]);
|
||||
sum2 += error[j] * std::pow(weights[i], inputSet[j][i]);
|
||||
}
|
||||
|
||||
|
||||
@ -110,8 +110,8 @@ namespace MLPP{
|
||||
|
||||
// Calculating the weight gradients
|
||||
|
||||
double w_gradient = (y_hat - outputSet[outputIndex]) * inputSet[outputIndex][i] * pow(weights[i], inputSet[outputIndex][i] - 1);
|
||||
double i_gradient = (y_hat - outputSet[outputIndex]) * pow(weights[i], inputSet[outputIndex][i]);
|
||||
double w_gradient = (y_hat - outputSet[outputIndex]) * inputSet[outputIndex][i] * std::pow(weights[i], inputSet[outputIndex][i] - 1);
|
||||
double i_gradient = (y_hat - outputSet[outputIndex]) * std::pow(weights[i], inputSet[outputIndex][i]);
|
||||
|
||||
// Weight/initial updation
|
||||
weights[i] -= learning_rate * w_gradient;
|
||||
@ -157,14 +157,14 @@ namespace MLPP{
|
||||
// Calculating the weight gradient
|
||||
double sum = 0;
|
||||
for(int k = 0; k < outputMiniBatches[i].size(); k++){
|
||||
sum += error[k] * inputMiniBatches[i][k][j] * pow(weights[j], inputMiniBatches[i][k][j] - 1);
|
||||
sum += error[k] * inputMiniBatches[i][k][j] * std::pow(weights[j], inputMiniBatches[i][k][j] - 1);
|
||||
}
|
||||
double w_gradient = sum / outputMiniBatches[i].size();
|
||||
|
||||
// Calculating the initial gradient
|
||||
double sum2 = 0;
|
||||
for(int k = 0; k < outputMiniBatches[i].size(); k++){
|
||||
sum2 += error[k] * pow(weights[j], inputMiniBatches[i][k][j]);
|
||||
sum2 += error[k] * std::pow(weights[j], inputMiniBatches[i][k][j]);
|
||||
}
|
||||
|
||||
|
||||
@ -217,7 +217,7 @@ namespace MLPP{
|
||||
for(int i = 0; i < X.size(); i++){
|
||||
y_hat[i] = 0;
|
||||
for(int j = 0; j < X[i].size(); j++){
|
||||
y_hat[i] += initial[j] * pow(weights[j], X[i][j]);
|
||||
y_hat[i] += initial[j] * std::pow(weights[j], X[i][j]);
|
||||
}
|
||||
y_hat[i] += bias;
|
||||
}
|
||||
@ -227,7 +227,7 @@ namespace MLPP{
|
||||
double ExpReg::Evaluate(std::vector<double> x){
|
||||
double y_hat = 0;
|
||||
for(int i = 0; i < x.size(); i++){
|
||||
y_hat += initial[i] * pow(weights[i], x[i]);
|
||||
y_hat += initial[i] * std::pow(weights[i], x[i]);
|
||||
}
|
||||
|
||||
return y_hat + bias;
|
||||
|
@ -209,7 +209,7 @@ namespace MLPP{
|
||||
std::vector<std::vector<double>> LinAlg::exponentiate(std::vector<std::vector<double>> A, double p){
|
||||
for(int i = 0; i < A.size(); i++){
|
||||
for(int j = 0; j < A[i].size(); j++){
|
||||
A[i][j] = pow(A[i][j], p);
|
||||
A[i][j] = std::pow(A[i][j], p);
|
||||
}
|
||||
}
|
||||
return A;
|
||||
@ -281,7 +281,7 @@ namespace MLPP{
|
||||
}
|
||||
sub_i++;
|
||||
}
|
||||
deter += pow(-1, i) * A[0][i] * det(B, d-1);
|
||||
deter += std::pow(-1, i) * A[0][i] * det(B, d-1);
|
||||
}
|
||||
}
|
||||
return deter;
|
||||
@ -862,7 +862,7 @@ namespace MLPP{
|
||||
std::vector<double> b;
|
||||
b.resize(a.size());
|
||||
for(int i = 0; i < b.size(); i++){
|
||||
b[i] = pow(a[i], p);
|
||||
b[i] = std::pow(a[i], p);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
@ -154,17 +154,17 @@ namespace MLPP{
|
||||
double Stat::powerMean(std::vector<double> x, double p){
|
||||
double sum = 0;
|
||||
for(int i = 0; i < x.size(); i++){
|
||||
sum += pow(x[i], p);
|
||||
sum += std::pow(x[i], p);
|
||||
}
|
||||
return pow(sum / x.size(), 1/p);
|
||||
return std::pow(sum / x.size(), 1/p);
|
||||
}
|
||||
|
||||
double Stat::lehmerMean(std::vector<double> x, double p){
|
||||
double num = 0;
|
||||
double den = 0;
|
||||
for(int i = 0; i < x.size(); i++){
|
||||
num += pow(x[i], p);
|
||||
den += pow(x[i], p - 1);
|
||||
num += std::pow(x[i], p);
|
||||
den += std::pow(x[i], p - 1);
|
||||
}
|
||||
return num/den;
|
||||
}
|
||||
@ -173,8 +173,8 @@ namespace MLPP{
|
||||
double num = 0;
|
||||
double den = 0;
|
||||
for(int i = 0; i < x.size(); i++){
|
||||
num += weights[i] * pow(x[i], p);
|
||||
den += weights[i] * pow(x[i], p - 1);
|
||||
num += weights[i] * std::pow(x[i], p);
|
||||
den += weights[i] * std::pow(x[i], p - 1);
|
||||
}
|
||||
return num/den;
|
||||
}
|
||||
@ -188,7 +188,7 @@ namespace MLPP{
|
||||
}
|
||||
|
||||
double Stat::heinzMean(double A, double B, double x){
|
||||
return (pow(A, x) * pow(B, 1 - x) + pow(A, 1 - x) * pow(B, x)) / 2;
|
||||
return (std::pow(A, x) * std::pow(B, 1 - x) + std::pow(A, 1 - x) * std::pow(B, x)) / 2;
|
||||
}
|
||||
|
||||
double Stat::neumanSandorMean(double a, double b){
|
||||
@ -200,14 +200,14 @@ namespace MLPP{
|
||||
if(x == y){
|
||||
return x;
|
||||
}
|
||||
return pow((pow(x, p) - pow(y, p)) / (p * (x - y)), 1/(p - 1));
|
||||
return std::pow((std::pow(x, p) - std::pow(y, p)) / (p * (x - y)), 1/(p - 1));
|
||||
}
|
||||
|
||||
double Stat::identricMean(double x, double y){
|
||||
if(x == y){
|
||||
return x;
|
||||
}
|
||||
return (1/M_E) * pow(pow(x, x) / pow(y, y), 1/(x-y));
|
||||
return (1/M_E) * std::pow(std::pow(x, x) / std::pow(y, y), 1/(x-y));
|
||||
}
|
||||
|
||||
double Stat::logMean(double x, double y){
|
||||
|
Loading…
Reference in New Issue
Block a user