3d rotation matrices.

This commit is contained in:
novak_99 2021-11-23 01:17:38 -08:00
parent 30737542ed
commit d60cae6189
3 changed files with 22 additions and 3 deletions

View File

@ -897,6 +897,15 @@ namespace MLPP{
return b; return b;
} }
std::vector<std::vector<double>> LinAlg::rotate(std::vector<std::vector<double>> A, double theta, int axis){
std::vector<std::vector<double>> rotationMatrix = {{std::cos(theta), -std::sin(theta)}, {std::sin(theta), std::cos(theta)}};
if(axis == 0) {rotationMatrix = {{1, 0, 0}, {0, std::cos(theta), -std::sin(theta)}, {0, std::sin(theta), std::cos(theta)}};}
else if(axis == 1) {rotationMatrix = {{std::cos(theta), 0, std::sin(theta)}, {0, 1, 0}, {-std::sin(theta), 0, std::cos(theta)}};}
else if (axis == 2) {rotationMatrix = {{std::cos(theta), -std::sin(theta), 0}, {std::sin(theta), std::cos(theta), 0}, {1, 0, 0}};}
return matmult(A, rotationMatrix);
}
double LinAlg::max(std::vector<double> a){ double LinAlg::max(std::vector<double> a){
int max = a[0]; int max = a[0];
for(int i = 0; i < a.size(); i++){ for(int i = 0; i < a.size(); i++){

View File

@ -74,6 +74,8 @@ namespace MLPP{
std::vector<std::vector<double>> cos(std::vector<std::vector<double>> A); std::vector<std::vector<double>> cos(std::vector<std::vector<double>> A);
std::vector<std::vector<double>> rotate(std::vector<std::vector<double>> A, double theta, int axis = -1);
double max(std::vector<std::vector<double>> A); double max(std::vector<std::vector<double>> A);
double min(std::vector<std::vector<double>> A); double min(std::vector<std::vector<double>> A);

View File

@ -100,7 +100,7 @@ int main() {
// Activation avn; // Activation avn;
// Cost cost; // Cost cost;
// Data data; // Data data;
// Convolutions conv; Convolutions conv;
// DATA SETS // DATA SETS
// std::vector<std::vector<double>> inputSet = {{1,2,3,4,5,6,7,8,9,10}, {3,5,9,12,15,18,21,24,27,30}}; // std::vector<std::vector<double>> inputSet = {{1,2,3,4,5,6,7,8,9,10}, {3,5,9,12,15,18,21,24,27,30}};
@ -157,7 +157,11 @@ int main() {
// std::cout << "Logarithmic Mean: " << stat.logMean(1, 10) << std::endl; // std::cout << "Logarithmic Mean: " << stat.logMean(1, 10) << std::endl;
// std::cout << "Absolute Average Deviation: " << stat.absAvgDeviation(x) << std::endl; // std::cout << "Absolute Average Deviation: " << stat.absAvgDeviation(x) << std::endl;
// // LINEAR ALGEBRA // LINEAR ALGEBRA
std::vector<std::vector<double>> square = {{1, 1}, {-1, 1}, {1, -1}, {-1, -1}};
alg.printMatrix(alg.rotate(square, M_PI/4));
// std::vector<std::vector<double>> A = { // std::vector<std::vector<double>> A = {
// {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, // {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
// {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, // {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
@ -405,6 +409,10 @@ int main() {
// tensorSet.push_back(input); // tensorSet.push_back(input);
// alg.printVector(conv.globalPool(tensorSet, "Average")); // Can use Max, Min, or Average global pooling. // alg.printVector(conv.globalPool(tensorSet, "Average")); // Can use Max, Min, or Average global pooling.
// std::vector<std::vector<double>> laplacian = {{1, 1, 1}, {1, -4, 1}, {1, 1, 1}};
// alg.printMatrix(conv.convolve(conv.gaussianFilter2D(5, 1), laplacian, 1));
// // PCA, SVD, eigenvalues & eigenvectors // // PCA, SVD, eigenvalues & eigenvectors
// std::vector<std::vector<double>> inputSet = {{1,1}, {1,1}}; // std::vector<std::vector<double>> inputSet = {{1,1}, {1,1}};
// auto [Eigenvectors, Eigenvalues] = alg.eig(inputSet); // auto [Eigenvectors, Eigenvalues] = alg.eig(inputSet);
@ -543,7 +551,7 @@ int main() {
// std::cout << "Our Hessian." << std::endl; // std::cout << "Our Hessian." << std::endl;
// alg.printMatrix(numAn.hessian(&f_mv, {2, 2, 500})); // alg.printMatrix(numAn.hessian(&f_mv, {2, 2, 500}));
std::cout << numAn.laplacian(f_mv, {1,1,1}) << std::endl; // std::cout << numAn.laplacian(f_mv, {1,1,1}) << std::endl;
return 0; return 0;
} }