added laplacians

This commit is contained in:
novak_99 2021-11-21 16:02:21 -08:00
parent e44834cd03
commit cd0de3bf7c
3 changed files with 15 additions and 3 deletions

View File

@ -104,4 +104,14 @@ namespace MLPP{
LinAlg alg;
return linearApproximation(function, c, x) + 0.5 * alg.matmult({(alg.subtraction(x, c))}, alg.matmult(hessian(function, c), alg.transpose({alg.subtraction(x, c)})))[0][0];
}
double NumericalAnalysis::laplacian(double(*function)(std::vector<double>), std::vector<double> x){
LinAlg alg;
std::vector<std::vector<double>> hessian_matrix = hessian(function, x);
double laplacian = 0;
for(int i = 0; i < hessian_matrix.size(); i++){
laplacian += hessian_matrix[i][i]; // homogenous 2nd derivs w.r.t i, then i
}
return laplacian;
}
}

View File

@ -34,7 +34,7 @@ namespace MLPP{
double linearApproximation(double(*function)(std::vector<double>), std::vector<double> c, std::vector<double> x);
double quadraticApproximation(double(*function)(std::vector<double>), std::vector<double> c, std::vector<double> x);
double laplacian(double(*function)(std::vector<double>), std::vector<double> x); // laplacian
};
}

View File

@ -79,7 +79,7 @@ double f_mv(std::vector<double> x){
}
/*
Where x, y = x[0], x[1], this function is defined as:
f(x, y) = x^4 + xy^3 + yz^2
f(x, y) = x^3 + x + xy^3 + yz^2
f/x = 4x^3 + 3y^2
^2f/x^2 = 6x
@ -528,7 +528,7 @@ int main() {
//std::cout << numAn.quadraticApproximation(f, 0, 1) << std::endl;
std::cout << numAn.quadraticApproximation(f_mv, {0, 0, 0}, {1, 1, 1}) << std::endl;
// std::cout << numAn.quadraticApproximation(f_mv, {0, 0, 0}, {1, 1, 1}) << std::endl;
// std::cout << numAn.numDiff(&f, 1) << std::endl;
// std::cout << numAn.newtonRaphsonMethod(&f, 1, 1000) << std::endl;
@ -543,6 +543,8 @@ int main() {
// std::cout << "Our Hessian." << std::endl;
// alg.printMatrix(numAn.hessian(&f_mv, {2, 2, 500}));
std::cout << numAn.laplacian(f_mv, {1,1,1}) << std::endl;
return 0;
}