added gram matrix, linear independence check

This commit is contained in:
novak_99 2022-01-30 10:30:41 -08:00
parent a13e0e344b
commit 38c216c68f
4 changed files with 37 additions and 13 deletions

View File

@ -13,6 +13,17 @@
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::random_device rd;
std::default_random_engine generator(rd());

View File

@ -16,6 +16,10 @@ namespace MLPP{
// 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>> addition(std::vector<std::vector<double>> A, std::vector<std::vector<double>> B);

BIN
a.out

Binary file not shown.

View File

@ -363,19 +363,19 @@ int main() {
// 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 Loss Functions: MSE, RMSE, MBE, LogLoss, CrossEntropy, HingeLoss
std::vector<std::vector<double>> inputSet = {{0,0,1,1}, {0,1,0,1}};
std::vector<double> outputSet = {0,1,1,0};
ANN ann(alg.transpose(inputSet), outputSet);
ann.addLayer(2, "Sigmoid");
ann.addLayer(2, "Sigmoid");
ann.addOutputLayer("Sigmoid", "LogLoss");
//ann.AMSGrad(0.1, 10000, 1, 0.9, 0.999, 0.000001, 1);
//ann.Adadelta(1, 1000, 2, 0.9, 0.000001, 1);
//ann.Momentum(0.1, 8000, 2, 0.9, true, 1);
ann.setLearningRateScheduler("Time", 0.000000000001);
ann.gradientDescent(0.1, 20000, 1);
alg.printVector(ann.modelSetTest(alg.transpose(inputSet)));
std::cout << "ACCURACY: " << 100 * ann.score() << "%" << std::endl;
// std::vector<std::vector<double>> inputSet = {{0,0,1,1}, {0,1,0,1}};
// std::vector<double> outputSet = {0,1,1,0};
// ANN ann(alg.transpose(inputSet), outputSet);
// ann.addLayer(2, "Sigmoid");
// ann.addLayer(2, "Sigmoid");
// ann.addOutputLayer("Sigmoid", "LogLoss");
// //ann.AMSGrad(0.1, 10000, 1, 0.9, 0.999, 0.000001, 1);
// //ann.Adadelta(1, 1000, 2, 0.9, 0.000001, 1);
// //ann.Momentum(0.1, 8000, 2, 0.9, true, 1);
// ann.setLearningRateScheduler("Time", 0.000000000001);
// ann.gradientDescent(0.1, 20000, 1);
// alg.printVector(ann.modelSetTest(alg.transpose(inputSet)));
// 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},
// {2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40}};
@ -696,6 +696,15 @@ int main() {
// DualSVC kernelSVM(inputSet, outputSet, 1000);
// 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;