Added LinAlg.cbrt

This commit is contained in:
novak_99 2021-06-02 13:40:56 -07:00
parent 6850dbf953
commit 3397671049
5 changed files with 20 additions and 4 deletions

View File

@ -219,6 +219,10 @@ namespace MLPP{
return exponentiate(A, 0.5);
}
std::vector<std::vector<double>> LinAlg::cbrt(std::vector<std::vector<double>> A){
return exponentiate(A, double(1)/double(3));
}
std::vector<std::vector<double>> LinAlg::matrixPower(std::vector<std::vector<double>> A, int n){
std::vector<std::vector<double>> B = identity(A.size());
if(n == 0){
@ -738,6 +742,10 @@ namespace MLPP{
return exponentiate(a, 0.5);
}
std::vector<double> LinAlg::cbrt(std::vector<double> a){
return exponentiate(a, double(1)/double(3));
}
double LinAlg::dot(std::vector<double> a, std::vector<double> b){
double c = 0;
for(int i = 0; i < a.size(); i++){

View File

@ -46,6 +46,8 @@ namespace MLPP{
std::vector<std::vector<double>> sqrt(std::vector<std::vector<double>> A);
std::vector<std::vector<double>> cbrt(std::vector<std::vector<double>> A);
std::vector<std::vector<double>> matrixPower(std::vector<std::vector<double>> A, int n);
std::vector<std::vector<double>> abs(std::vector<std::vector<double>> A);
@ -119,6 +121,8 @@ namespace MLPP{
std::vector<double> exponentiate(std::vector<double> a, double p);
std::vector<double> sqrt(std::vector<double> a);
std::vector<double> cbrt(std::vector<double> a);
double dot(std::vector<double> a, std::vector<double> b);
@ -158,7 +162,6 @@ namespace MLPP{
void printTensor(std::vector<std::vector<std::vector<double>>> A);
private:
};

Binary file not shown.

BIN
a.out Executable file

Binary file not shown.

View File

@ -266,7 +266,7 @@ int main() {
// std::cout << "ACCURACY: " << 100 * knn.score() << "%" << std::endl;
// //CONVOLUTION, POOLING, ETC..
// // CONVOLUTION, POOLING, ETC..
// std::vector<std::vector<double>> input = {
// {1,1,1,1,0,0,0,0},
// {1,1,1,1,0,0,0,0},
@ -354,11 +354,11 @@ int main() {
// std::cout << avn.softsign(z_s, 1) << std::endl;
// std::vector<double> z_v = {0.001, 5};
// alg.printVector(avn.softmax(z_v));
// alg.printVector(avn.softsign(z_v));
// alg.printVector(avn.softsign(z_v, 1));
// std::vector<std::vector<double>> Z_m = {{0.001, 5}};
// alg.printMatrix(avn.softmax(Z_m));
// alg.printMatrix(avn.softsign(Z_m));
// alg.printMatrix(avn.softsign(Z_m, 1));
// std::cout << alg.trace({{1,2}, {3,4}}) << std::endl;
@ -368,5 +368,10 @@ int main() {
// alg.printMatrix(alg.matrixPower({{5,5},{5,5}}, 2));
// alg.printVector(alg.solve({{1,1}, {1.5, 4.0}}, {2200, 5050}));
std::vector<std::vector<double>> matrixOfCubes = {{1,2,64,27}};
std::vector<double> vectorOfCubes = {1,2,64,27};
alg.printMatrix(alg.cbrt(matrixOfCubes));
alg.printVector(alg.cbrt(vectorOfCubes));
return 0;
}