mirror of
https://github.com/Relintai/MLPP.git
synced 2025-02-10 16:10:06 +01:00
added gram matrix, linear independence check
This commit is contained in:
parent
a13e0e344b
commit
38c216c68f
@ -13,6 +13,17 @@
|
|||||||
|
|
||||||
namespace MLPP{
|
namespace MLPP{
|
||||||
|
|
||||||
|
std::vector<std::vector<double>> LinAlg::gramMatrix(std::vector<std::vector<double>> A){
|
||||||
|
return matmult(transpose(A), A); // AtA
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinAlg::linearIndependenceChecker(std::vector<std::vector<double>> A){
|
||||||
|
if (det(gramMatrix(A), A.size()) == 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::vector<double>> LinAlg::gaussianNoise(int n, int m){
|
std::vector<std::vector<double>> LinAlg::gaussianNoise(int n, int m){
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
std::default_random_engine generator(rd());
|
std::default_random_engine generator(rd());
|
||||||
|
@ -16,6 +16,10 @@ namespace MLPP{
|
|||||||
|
|
||||||
// MATRIX FUNCTIONS
|
// MATRIX FUNCTIONS
|
||||||
|
|
||||||
|
std::vector<std::vector<double>> gramMatrix(std::vector<std::vector<double>> A);
|
||||||
|
|
||||||
|
bool linearIndependenceChecker(std::vector<std::vector<double>> A);
|
||||||
|
|
||||||
std::vector<std::vector<double>> gaussianNoise(int n, int m);
|
std::vector<std::vector<double>> gaussianNoise(int n, int m);
|
||||||
|
|
||||||
std::vector<std::vector<double>> addition(std::vector<std::vector<double>> A, std::vector<std::vector<double>> B);
|
std::vector<std::vector<double>> addition(std::vector<std::vector<double>> A, std::vector<std::vector<double>> B);
|
||||||
|
35
main.cpp
35
main.cpp
@ -363,19 +363,19 @@ int main() {
|
|||||||
// Possible Weight Init Methods: Default, Uniform, HeNormal, HeUniform, XavierNormal, XavierUniform
|
// Possible Weight Init Methods: Default, Uniform, HeNormal, HeUniform, XavierNormal, XavierUniform
|
||||||
// Possible Activations: Linear, Sigmoid, Swish, Softplus, Softsign, CLogLog, Ar{Sinh, Cosh, Tanh, Csch, Sech, Coth}, GaussianCDF, GELU, UnitStep
|
// Possible Activations: Linear, Sigmoid, Swish, Softplus, Softsign, CLogLog, Ar{Sinh, Cosh, Tanh, Csch, Sech, Coth}, GaussianCDF, GELU, UnitStep
|
||||||
// Possible Loss Functions: MSE, RMSE, MBE, LogLoss, CrossEntropy, HingeLoss
|
// Possible Loss Functions: MSE, RMSE, MBE, LogLoss, CrossEntropy, HingeLoss
|
||||||
std::vector<std::vector<double>> inputSet = {{0,0,1,1}, {0,1,0,1}};
|
// std::vector<std::vector<double>> inputSet = {{0,0,1,1}, {0,1,0,1}};
|
||||||
std::vector<double> outputSet = {0,1,1,0};
|
// std::vector<double> outputSet = {0,1,1,0};
|
||||||
ANN ann(alg.transpose(inputSet), outputSet);
|
// ANN ann(alg.transpose(inputSet), outputSet);
|
||||||
ann.addLayer(2, "Sigmoid");
|
// ann.addLayer(2, "Sigmoid");
|
||||||
ann.addLayer(2, "Sigmoid");
|
// ann.addLayer(2, "Sigmoid");
|
||||||
ann.addOutputLayer("Sigmoid", "LogLoss");
|
// ann.addOutputLayer("Sigmoid", "LogLoss");
|
||||||
//ann.AMSGrad(0.1, 10000, 1, 0.9, 0.999, 0.000001, 1);
|
// //ann.AMSGrad(0.1, 10000, 1, 0.9, 0.999, 0.000001, 1);
|
||||||
//ann.Adadelta(1, 1000, 2, 0.9, 0.000001, 1);
|
// //ann.Adadelta(1, 1000, 2, 0.9, 0.000001, 1);
|
||||||
//ann.Momentum(0.1, 8000, 2, 0.9, true, 1);
|
// //ann.Momentum(0.1, 8000, 2, 0.9, true, 1);
|
||||||
ann.setLearningRateScheduler("Time", 0.000000000001);
|
// ann.setLearningRateScheduler("Time", 0.000000000001);
|
||||||
ann.gradientDescent(0.1, 20000, 1);
|
// ann.gradientDescent(0.1, 20000, 1);
|
||||||
alg.printVector(ann.modelSetTest(alg.transpose(inputSet)));
|
// alg.printVector(ann.modelSetTest(alg.transpose(inputSet)));
|
||||||
std::cout << "ACCURACY: " << 100 * ann.score() << "%" << std::endl;
|
// std::cout << "ACCURACY: " << 100 * ann.score() << "%" << std::endl;
|
||||||
|
|
||||||
//std::vector<std::vector<double>> outputSet = {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
|
//std::vector<std::vector<double>> outputSet = {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
|
||||||
// {2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40}};
|
// {2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40}};
|
||||||
@ -697,6 +697,15 @@ int main() {
|
|||||||
// DualSVC kernelSVM(inputSet, outputSet, 1000);
|
// DualSVC kernelSVM(inputSet, outputSet, 1000);
|
||||||
// kernelSVM.gradientDescent(0.0001, 20, 1);
|
// kernelSVM.gradientDescent(0.0001, 20, 1);
|
||||||
|
|
||||||
|
std::vector<std::vector<double>> linearlyDependentMat =
|
||||||
|
|
||||||
|
{
|
||||||
|
{1,2,3,4},
|
||||||
|
{234538495,4444,6111,55}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::cout << "True of false: linearly independent?: " << std::boolalpha << alg.linearIndependenceChecker(linearlyDependentMat) << std::endl;
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user