Fixed warnings in MLPPNumericalAnalysis.

This commit is contained in:
Relintai 2023-02-12 16:10:00 +01:00
parent ef17833999
commit b965bd6a6b
2 changed files with 22 additions and 15 deletions

View File

@ -126,7 +126,7 @@ real_t MLPPNumericalAnalysis::halleyMethod(real_t (*function)(real_t), real_t x_
return x; return x;
} }
real_t MLPPNumericalAnalysis::invQuadraticInterpolation(real_t (*function)(real_t), std::vector<real_t> x_0, real_t epoch_num) { real_t MLPPNumericalAnalysis::invQuadraticInterpolation(real_t (*function)(real_t), std::vector<real_t> x_0, int epoch_num) {
real_t x = 0; real_t x = 0;
std::vector<real_t> currentThree = x_0; std::vector<real_t> currentThree = x_0;
for (int i = 0; i < epoch_num; i++) { for (int i = 0; i < epoch_num; i++) {
@ -142,7 +142,7 @@ real_t MLPPNumericalAnalysis::invQuadraticInterpolation(real_t (*function)(real_
} }
real_t MLPPNumericalAnalysis::eulerianMethod(real_t (*derivative)(real_t), std::vector<real_t> q_0, real_t p, real_t h) { real_t MLPPNumericalAnalysis::eulerianMethod(real_t (*derivative)(real_t), std::vector<real_t> q_0, real_t p, real_t h) {
real_t max_epoch = (p - q_0[0]) / h; int max_epoch = static_cast<int>((p - q_0[0]) / h);
real_t x = q_0[0]; real_t x = q_0[0];
real_t y = q_0[1]; real_t y = q_0[1];
for (int i = 0; i < max_epoch; i++) { for (int i = 0; i < max_epoch; i++) {
@ -153,7 +153,7 @@ real_t MLPPNumericalAnalysis::eulerianMethod(real_t (*derivative)(real_t), std::
} }
real_t MLPPNumericalAnalysis::eulerianMethod(real_t (*derivative)(std::vector<real_t>), std::vector<real_t> q_0, real_t p, real_t h) { real_t MLPPNumericalAnalysis::eulerianMethod(real_t (*derivative)(std::vector<real_t>), std::vector<real_t> q_0, real_t p, real_t h) {
real_t max_epoch = (p - q_0[0]) / h; int max_epoch = static_cast<int>((p - q_0[0]) / h);
real_t x = q_0[0]; real_t x = q_0[0];
real_t y = q_0[1]; real_t y = q_0[1];
for (int i = 0; i < max_epoch; i++) { for (int i = 0; i < max_epoch; i++) {
@ -182,7 +182,7 @@ real_t MLPPNumericalAnalysis::growthMethod(real_t C, real_t k, real_t t) {
std::vector<real_t> MLPPNumericalAnalysis::jacobian(real_t (*function)(std::vector<real_t>), std::vector<real_t> x) { std::vector<real_t> MLPPNumericalAnalysis::jacobian(real_t (*function)(std::vector<real_t>), std::vector<real_t> x) {
std::vector<real_t> jacobian; std::vector<real_t> jacobian;
jacobian.resize(x.size()); jacobian.resize(x.size());
for (int i = 0; i < jacobian.size(); i++) { for (uint32_t i = 0; i < jacobian.size(); i++) {
jacobian[i] = numDiff(function, x, i); // Derivative w.r.t axis i evaluated at x. For all x_i. jacobian[i] = numDiff(function, x, i); // Derivative w.r.t axis i evaluated at x. For all x_i.
} }
return jacobian; return jacobian;
@ -190,32 +190,38 @@ std::vector<real_t> MLPPNumericalAnalysis::jacobian(real_t (*function)(std::vect
std::vector<std::vector<real_t>> MLPPNumericalAnalysis::hessian(real_t (*function)(std::vector<real_t>), std::vector<real_t> x) { std::vector<std::vector<real_t>> MLPPNumericalAnalysis::hessian(real_t (*function)(std::vector<real_t>), std::vector<real_t> x) {
std::vector<std::vector<real_t>> hessian; std::vector<std::vector<real_t>> hessian;
hessian.resize(x.size()); hessian.resize(x.size());
for (int i = 0; i < hessian.size(); i++) {
for (uint32_t i = 0; i < hessian.size(); i++) {
hessian[i].resize(x.size()); hessian[i].resize(x.size());
} }
for (int i = 0; i < hessian.size(); i++) {
for (int j = 0; j < hessian[i].size(); j++) { for (uint32_t i = 0; i < hessian.size(); i++) {
for (uint32_t j = 0; j < hessian[i].size(); j++) {
hessian[i][j] = numDiff_2(function, x, i, j); hessian[i][j] = numDiff_2(function, x, i, j);
} }
} }
return hessian; return hessian;
} }
std::vector<std::vector<std::vector<real_t>>> MLPPNumericalAnalysis::thirdOrderTensor(real_t (*function)(std::vector<real_t>), std::vector<real_t> x) { std::vector<std::vector<std::vector<real_t>>> MLPPNumericalAnalysis::thirdOrderTensor(real_t (*function)(std::vector<real_t>), std::vector<real_t> x) {
std::vector<std::vector<std::vector<real_t>>> tensor; std::vector<std::vector<std::vector<real_t>>> tensor;
tensor.resize(x.size()); tensor.resize(x.size());
for (int i = 0; i < tensor.size(); i++) {
for (uint32_t i = 0; i < tensor.size(); i++) {
tensor[i].resize(x.size()); tensor[i].resize(x.size());
for (int j = 0; j < tensor[i].size(); j++) { for (uint32_t j = 0; j < tensor[i].size(); j++) {
tensor[i][j].resize(x.size()); tensor[i][j].resize(x.size());
} }
} }
for (int i = 0; i < tensor.size(); i++) { // O(n^3) time complexity :(
for (int j = 0; j < tensor[i].size(); j++) { for (uint32_t i = 0; i < tensor.size(); i++) { // O(n^3) time complexity :(
for (int k = 0; k < tensor[i][j].size(); k++) for (uint32_t j = 0; j < tensor[i].size(); j++) {
for (uint32_t k = 0; k < tensor[i][j].size(); k++)
tensor[i][j][k] = numDiff_3(function, x, i, j, k); tensor[i][j][k] = numDiff_3(function, x, i, j, k);
} }
} }
return tensor; return tensor;
} }
@ -251,12 +257,13 @@ real_t MLPPNumericalAnalysis::cubicApproximation(real_t (*function)(std::vector<
} }
real_t MLPPNumericalAnalysis::laplacian(real_t (*function)(std::vector<real_t>), std::vector<real_t> x) { real_t MLPPNumericalAnalysis::laplacian(real_t (*function)(std::vector<real_t>), std::vector<real_t> x) {
MLPPLinAlg alg;
std::vector<std::vector<real_t>> hessian_matrix = hessian(function, x); std::vector<std::vector<real_t>> hessian_matrix = hessian(function, x);
real_t laplacian = 0; real_t laplacian = 0;
for (int i = 0; i < hessian_matrix.size(); i++) {
for (uint32_t i = 0; i < hessian_matrix.size(); i++) {
laplacian += hessian_matrix[i][i]; // homogenous 2nd derivs w.r.t i, then i laplacian += hessian_matrix[i][i]; // homogenous 2nd derivs w.r.t i, then i
} }
return laplacian; return laplacian;
} }

View File

@ -37,7 +37,7 @@ public:
real_t newtonRaphsonMethod(real_t (*function)(real_t), real_t x_0, real_t epoch_num); real_t newtonRaphsonMethod(real_t (*function)(real_t), real_t x_0, real_t epoch_num);
real_t halleyMethod(real_t (*function)(real_t), real_t x_0, real_t epoch_num); real_t halleyMethod(real_t (*function)(real_t), real_t x_0, real_t epoch_num);
real_t invQuadraticInterpolation(real_t (*function)(real_t), std::vector<real_t> x_0, real_t epoch_num); real_t invQuadraticInterpolation(real_t (*function)(real_t), std::vector<real_t> x_0, int epoch_num);
real_t eulerianMethod(real_t (*derivative)(real_t), std::vector<real_t> q_0, real_t p, real_t h); // Euler's method for solving diffrential equations. real_t eulerianMethod(real_t (*derivative)(real_t), std::vector<real_t> q_0, real_t p, real_t h); // Euler's method for solving diffrential equations.
real_t eulerianMethod(real_t (*derivative)(std::vector<real_t>), std::vector<real_t> q_0, real_t p, real_t h); // Euler's method for solving diffrential equations. real_t eulerianMethod(real_t (*derivative)(std::vector<real_t>), std::vector<real_t> q_0, real_t p, real_t h); // Euler's method for solving diffrential equations.