diff --git a/mlpp/activation/activation.cpp b/mlpp/activation/activation.cpp index 07c1871..6d4eb10 100644 --- a/mlpp/activation/activation.cpp +++ b/mlpp/activation/activation.cpp @@ -851,7 +851,7 @@ real_t MLPPActivation::sigmoid_normr(real_t z) { } Ref MLPPActivation::sigmoid_normv(const Ref &z) { MLPPLinAlg alg; - return alg.element_wise_division(alg.onevecv(z->size()), alg.additionnv(alg.onevecv(z->size()), alg.expv(alg.scalar_multiplynv(-1, z)))); + return alg.element_wise_division(alg.onevecv(z->size()), alg.additionnv(alg.onevecv(z->size()), alg.expnv(alg.scalar_multiplynv(-1, z)))); } Ref MLPPActivation::sigmoid_normm(const Ref &z) { MLPPLinAlg alg; @@ -893,7 +893,7 @@ Ref MLPPActivation::softmax_normv(const Ref &z) { a.instance(); a->resize(z_size); - Ref exp_z = alg.expv(z); + Ref exp_z = alg.expnv(z); real_t sum = 0; const real_t *exp_z_ptr = exp_z->ptr(); @@ -943,7 +943,7 @@ Ref MLPPActivation::softmax_derivv(const Ref &z) { a.instance(); a->resize(z_size); - Ref exp_z = alg.expv(z); + Ref exp_z = alg.expnv(z); real_t sum = 0; const real_t *exp_z_ptr = exp_z->ptr(); @@ -1219,12 +1219,12 @@ real_t MLPPActivation::softplus_normr(real_t z) { Ref MLPPActivation::softplus_normv(const Ref &z) { MLPPLinAlg alg; - return alg.logv(alg.additionnv(alg.onevecv(z->size()), alg.expv(z))); + return alg.lognv(alg.additionnv(alg.onevecv(z->size()), alg.expnv(z))); } Ref MLPPActivation::softplus_normm(const Ref &z) { MLPPLinAlg alg; - return alg.logv(alg.additionnv(alg.onematm(z->size().x, z->size().y), alg.expv(z))); + return alg.lognv(alg.additionnv(alg.onematm(z->size().x, z->size().y), alg.expnv(z))); } real_t MLPPActivation::softplus_derivr(real_t z) { @@ -1259,12 +1259,12 @@ real_t MLPPActivation::softsign_derivr(real_t z) { Ref MLPPActivation::softsign_derivv(const Ref &z) { MLPPLinAlg alg; - return alg.element_wise_division(alg.onevecv(z->size()), alg.exponentiatev(alg.additionnv(alg.onevecv(z->size()), alg.absv(z)), 2)); + return alg.element_wise_division(alg.onevecv(z->size()), alg.exponentiatenv(alg.additionnv(alg.onevecv(z->size()), alg.absv(z)), 2)); } Ref MLPPActivation::softsign_derivm(const Ref &z) { MLPPLinAlg alg; - return alg.element_wise_divisionm(alg.onematm(z->size().x, z->size().y), alg.exponentiatev(alg.additionm(alg.onematm(z->size().x, z->size().y), alg.absm(z)), 2)); + return alg.element_wise_divisionm(alg.onematm(z->size().x, z->size().y), alg.exponentiatenv(alg.additionm(alg.onematm(z->size().x, z->size().y), alg.absm(z)), 2)); } //GAUSSIANCDF @@ -1275,7 +1275,7 @@ real_t MLPPActivation::gaussian_cdf_normr(real_t z) { Ref MLPPActivation::gaussian_cdf_normv(const Ref &z) { MLPPLinAlg alg; - return alg.scalar_multiplynv(0.5, alg.additionnv(alg.onevecv(z->size()), alg.erfv(alg.scalar_multiplynv(1 / sqrt(2), z)))); + return alg.scalar_multiplynv(0.5, alg.additionnv(alg.onevecv(z->size()), alg.erfnv(alg.scalar_multiplynv(1 / sqrt(2), z)))); } Ref MLPPActivation::gaussian_cdf_normm(const Ref &z) { @@ -1290,7 +1290,7 @@ real_t MLPPActivation::gaussian_cdf_derivr(real_t z) { Ref MLPPActivation::gaussian_cdf_derivv(const Ref &z) { MLPPLinAlg alg; - return alg.scalar_multiplynv(1 / Math::sqrt(2 * M_PI), alg.expv(alg.scalar_multiplynv(-1 / 2.0, alg.hadamard_productnv(z, z)))); + return alg.scalar_multiplynv(1 / Math::sqrt(2 * M_PI), alg.expnv(alg.scalar_multiplynv(-1 / 2.0, alg.hadamard_productnv(z, z)))); } Ref MLPPActivation::gaussian_cdf_derivm(const Ref &z) { @@ -1307,7 +1307,7 @@ real_t MLPPActivation::cloglog_normr(real_t z) { Ref MLPPActivation::cloglog_normv(const Ref &z) { MLPPLinAlg alg; - return alg.scalar_multiplynv(-1, alg.scalar_addnv(-1, alg.expv(alg.scalar_multiplynv(-1, alg.expv(z))))); + return alg.scalar_multiplynv(-1, alg.scalar_addnv(-1, alg.expnv(alg.scalar_multiplynv(-1, alg.expnv(z))))); } Ref MLPPActivation::cloglog_normm(const Ref &z) { @@ -1322,7 +1322,7 @@ real_t MLPPActivation::cloglog_derivr(real_t z) { Ref MLPPActivation::cloglog_derivv(const Ref &z) { MLPPLinAlg alg; - return alg.expv(alg.scalar_multiplynv(-1, alg.expv(z))); + return alg.expnv(alg.scalar_multiplynv(-1, alg.expnv(z))); } Ref MLPPActivation::cloglog_derivm(const Ref &z) { @@ -1339,7 +1339,7 @@ real_t MLPPActivation::logit_normr(real_t z) { Ref MLPPActivation::logit_normv(const Ref &z) { MLPPLinAlg alg; - return alg.logv(alg.element_wise_division(z, alg.subtractionnv(alg.onevecv(z->size()), z))); + return alg.lognv(alg.element_wise_division(z, alg.subtractionnv(alg.onevecv(z->size()), z))); } Ref MLPPActivation::logit_normm(const Ref &z) { MLPPLinAlg alg; @@ -2002,7 +2002,7 @@ real_t MLPPActivation::sinh_normr(real_t z) { } Ref MLPPActivation::sinh_normv(const Ref &z) { MLPPLinAlg alg; - return alg.scalar_multiplynv(0.5, alg.subtractionnv(alg.expv(z), alg.expv(alg.scalar_multiplynv(-1, z)))); + return alg.scalar_multiplynv(0.5, alg.subtractionnv(alg.expnv(z), alg.expnv(alg.scalar_multiplynv(-1, z)))); } Ref MLPPActivation::sinh_normm(const Ref &z) { MLPPLinAlg alg; @@ -2026,7 +2026,7 @@ real_t MLPPActivation::cosh_normr(real_t z) { } Ref MLPPActivation::cosh_normv(const Ref &z) { MLPPLinAlg alg; - return alg.scalar_multiplynv(0.5, alg.additionnv(alg.expv(z), alg.expv(alg.scalar_multiplynv(-1, z)))); + return alg.scalar_multiplynv(0.5, alg.additionnv(alg.expnv(z), alg.expnv(alg.scalar_multiplynv(-1, z)))); } Ref MLPPActivation::cosh_normm(const Ref &z) { MLPPLinAlg alg; @@ -2051,7 +2051,7 @@ real_t MLPPActivation::tanh_normr(real_t z) { Ref MLPPActivation::tanh_normv(const Ref &z) { MLPPLinAlg alg; - return alg.element_wise_division(alg.subtractionnv(alg.expv(z), alg.expv(alg.scalar_multiplynv(-1, z))), alg.additionnv(alg.expv(z), alg.expv(alg.scalar_multiplynv(-1, z)))); + return alg.element_wise_division(alg.subtractionnv(alg.expnv(z), alg.expnv(alg.scalar_multiplynv(-1, z))), alg.additionnv(alg.expnv(z), alg.expnv(alg.scalar_multiplynv(-1, z)))); } Ref MLPPActivation::tanh_normm(const Ref &z) { MLPPLinAlg alg; @@ -2180,7 +2180,7 @@ real_t MLPPActivation::arsinh_normr(real_t z) { Ref MLPPActivation::arsinh_normv(const Ref &z) { MLPPLinAlg alg; - return alg.logv(alg.additionnv(z, alg.sqrtv(alg.additionnv(alg.hadamard_productnv(z, z), alg.onevecv(z->size()))))); + return alg.lognv(alg.additionnv(z, alg.sqrtnv(alg.additionnv(alg.hadamard_productnv(z, z), alg.onevecv(z->size()))))); } Ref MLPPActivation::arsinh_normm(const Ref &z) { @@ -2196,7 +2196,7 @@ real_t MLPPActivation::arsinh_derivr(real_t z) { Ref MLPPActivation::arsinh_derivv(const Ref &z) { MLPPLinAlg alg; - return alg.element_wise_division(alg.onevecv(z->size()), alg.sqrtv(alg.additionnv(alg.hadamard_productnv(z, z), alg.onevecv(z->size())))); + return alg.element_wise_division(alg.onevecv(z->size()), alg.sqrtnv(alg.additionnv(alg.hadamard_productnv(z, z), alg.onevecv(z->size())))); } Ref MLPPActivation::arsinh_derivm(const Ref &z) { @@ -2213,7 +2213,7 @@ real_t MLPPActivation::arcosh_normr(real_t z) { Ref MLPPActivation::arcosh_normv(const Ref &z) { MLPPLinAlg alg; - return alg.logv(alg.additionnv(z, alg.sqrtv(alg.subtractionnv(alg.hadamard_productnv(z, z), alg.onevecv(z->size()))))); + return alg.lognv(alg.additionnv(z, alg.sqrtnv(alg.subtractionnv(alg.hadamard_productnv(z, z), alg.onevecv(z->size()))))); } Ref MLPPActivation::arcosh_normm(const Ref &z) { @@ -2228,7 +2228,7 @@ real_t MLPPActivation::arcosh_derivr(real_t z) { Ref MLPPActivation::arcosh_derivv(const Ref &z) { MLPPLinAlg alg; - return alg.element_wise_division(alg.onevecv(z->size()), alg.sqrtv(alg.subtractionnv(alg.hadamard_productnv(z, z), alg.onevecv(z->size())))); + return alg.element_wise_division(alg.onevecv(z->size()), alg.sqrtnv(alg.subtractionnv(alg.hadamard_productnv(z, z), alg.onevecv(z->size())))); } Ref MLPPActivation::arcosh_derivm(const Ref &z) { @@ -2245,7 +2245,7 @@ real_t MLPPActivation::artanh_normr(real_t z) { Ref MLPPActivation::artanh_normv(const Ref &z) { MLPPLinAlg alg; - return alg.scalar_multiplynv(0.5, alg.logv(alg.element_wise_division(alg.additionnv(alg.onevecv(z->size()), z), alg.subtractionnv(alg.onevecv(z->size()), z)))); + return alg.scalar_multiplynv(0.5, alg.lognv(alg.element_wise_division(alg.additionnv(alg.onevecv(z->size()), z), alg.subtractionnv(alg.onevecv(z->size()), z)))); } Ref MLPPActivation::artanh_normm(const Ref &z) { @@ -2277,9 +2277,9 @@ real_t MLPPActivation::arcsch_normr(real_t z) { Ref MLPPActivation::arcsch_normv(const Ref &z) { MLPPLinAlg alg; - return alg.logv( + return alg.lognv( alg.additionnv( - alg.sqrtv( + alg.sqrtnv( alg.additionnv( alg.onevecv(z->size()), alg.element_wise_division(alg.onevecv(z->size()), alg.hadamard_productnv(z, z)))), @@ -2306,7 +2306,7 @@ Ref MLPPActivation::arcsch_derivv(const Ref &z) { alg.fullv(z->size(), -1), alg.hadamard_productm( alg.hadamard_productnv(z, z), - alg.sqrtv(alg.additionnv(alg.onevecv(z->size()), alg.element_wise_division(alg.onevecv(z->size()), alg.hadamard_productnv(z, z)))))); + alg.sqrtnv(alg.additionnv(alg.onevecv(z->size()), alg.element_wise_division(alg.onevecv(z->size()), alg.hadamard_productnv(z, z)))))); } Ref MLPPActivation::arcsch_derivm(const Ref &z) { MLPPLinAlg alg; @@ -2327,7 +2327,7 @@ real_t MLPPActivation::arsech_normr(real_t z) { Ref MLPPActivation::arsech_normv(const Ref &z) { MLPPLinAlg alg; - return alg.logv( + return alg.lognv( alg.additionnv( alg.element_wise_division( alg.onevecv(z->size()), z), @@ -2365,7 +2365,7 @@ Ref MLPPActivation::arsech_derivv(const Ref &z) { alg.fullv(z->size(), -1), alg.hadamard_productnv( z, - alg.sqrtv( + alg.sqrtnv( alg.subtractionnv(alg.onevecv(z->size()), alg.hadamard_productnv(z, z))))); } @@ -2389,7 +2389,7 @@ Ref MLPPActivation::arcoth_normv(const Ref &z) { return alg.scalar_multiplynv( 0.5, - alg.logv(alg.element_wise_division(alg.additionnv(alg.onevecv(z->size()), z), alg.subtractionnv(z, alg.onevecv(z->size()))))); + alg.lognv(alg.element_wise_division(alg.additionnv(alg.onevecv(z->size()), z), alg.subtractionnv(z, alg.onevecv(z->size()))))); } Ref MLPPActivation::arcoth_normm(const Ref &z) { diff --git a/mlpp/ann/ann.cpp b/mlpp/ann/ann.cpp index c667e63..82f3a39 100644 --- a/mlpp/ann/ann.cpp +++ b/mlpp/ann/ann.cpp @@ -312,10 +312,10 @@ void MLPPANN::adagrad(real_t learning_rate, int max_epoch, int mini_batch_size, } v_hidden = alg.addition_vt(v_hidden, alg.exponentiate_vt(grads.cumulative_hidden_layer_w_grad, 2)); - v_output = alg.additionnv(v_output, alg.exponentiatev(grads.output_w_grad, 2)); + v_output = alg.additionnv(v_output, alg.exponentiatenv(grads.output_w_grad, 2)); Vector> hidden_layer_updations = alg.scalar_multiply_vm(learning_rate / _n, alg.element_wise_division_vt(grads.cumulative_hidden_layer_w_grad, alg.scalar_add_vm(e, alg.sqrt_vt(v_hidden)))); - Ref output_layer_updation = alg.scalar_multiplynv(learning_rate / _n, alg.element_wise_division(grads.output_w_grad, alg.scalar_addnv(e, alg.sqrtv(v_output)))); + Ref output_layer_updation = alg.scalar_multiplynv(learning_rate / _n, alg.element_wise_division(grads.output_w_grad, alg.scalar_addnv(e, alg.sqrtnv(v_output)))); update_parameters(hidden_layer_updations, output_layer_updation, learning_rate); // subject to change. may want bias to have this matrix too. y_hat = model_set_test(current_input_batch); @@ -376,10 +376,10 @@ void MLPPANN::adadelta(real_t learning_rate, int max_epoch, int mini_batch_size, } v_hidden = alg.addition_vt(alg.scalar_multiply_vm(1 - b1, v_hidden), alg.scalar_multiply_vm(b1, alg.exponentiate_vt(grads.cumulative_hidden_layer_w_grad, 2))); - v_output = alg.additionnv(v_output, alg.exponentiatev(grads.output_w_grad, 2)); + v_output = alg.additionnv(v_output, alg.exponentiatenv(grads.output_w_grad, 2)); Vector> hidden_layer_updations = alg.scalar_multiply_vm(learning_rate / _n, alg.element_wise_division_vt(grads.cumulative_hidden_layer_w_grad, alg.scalar_add_vm(e, alg.sqrt_vt(v_hidden)))); - Ref output_layer_updation = alg.scalar_multiplynv(learning_rate / _n, alg.element_wise_division(grads.output_w_grad, alg.scalar_addnv(e, alg.sqrtv(v_output)))); + Ref output_layer_updation = alg.scalar_multiplynv(learning_rate / _n, alg.element_wise_division(grads.output_w_grad, alg.scalar_addnv(e, alg.sqrtnv(v_output)))); update_parameters(hidden_layer_updations, output_layer_updation, learning_rate); // subject to change. may want bias to have this matrix too. y_hat = model_set_test(current_input_batch); @@ -448,7 +448,7 @@ void MLPPANN::adam(real_t learning_rate, int max_epoch, int mini_batch_size, rea v_hidden = alg.addition_vt(alg.scalar_multiply_vm(b2, v_hidden), alg.scalar_multiply_vm(1 - b2, alg.exponentiate_vt(grads.cumulative_hidden_layer_w_grad, 2))); m_output = alg.additionnv(alg.scalar_multiplynv(b1, m_output), alg.scalar_multiplynv(1 - b1, grads.output_w_grad)); - v_output = alg.additionnv(alg.scalar_multiplynv(b2, v_output), alg.scalar_multiplynv(1 - b2, alg.exponentiatev(grads.output_w_grad, 2))); + v_output = alg.additionnv(alg.scalar_multiplynv(b2, v_output), alg.scalar_multiplynv(1 - b2, alg.exponentiatenv(grads.output_w_grad, 2))); Vector> m_hidden_hat = alg.scalar_multiply_vm(1 / (1 - Math::pow(b1, epoch)), m_hidden); Vector> v_hidden_hat = alg.scalar_multiply_vm(1 / (1 - Math::pow(b2, epoch)), v_hidden); @@ -457,7 +457,7 @@ void MLPPANN::adam(real_t learning_rate, int max_epoch, int mini_batch_size, rea Ref v_output_hat = alg.scalar_multiplynv(1 / (1 - Math::pow(b2, epoch)), v_output); Vector> hidden_layer_updations = alg.scalar_multiply_vm(learning_rate / _n, alg.element_wise_division_vt(m_hidden_hat, alg.scalar_add_vm(e, alg.sqrt_vt(v_hidden_hat)))); - Ref output_layer_updation = alg.scalar_multiplynv(learning_rate / _n, alg.element_wise_division(m_output_hat, alg.scalar_addnv(e, alg.sqrtv(v_output_hat)))); + Ref output_layer_updation = alg.scalar_multiplynv(learning_rate / _n, alg.element_wise_division(m_output_hat, alg.scalar_addnv(e, alg.sqrtnv(v_output_hat)))); update_parameters(hidden_layer_updations, output_layer_updation, learning_rate); // subject to change. may want bias to have this matrix too. y_hat = model_set_test(current_input_batch); @@ -596,7 +596,7 @@ void MLPPANN::nadam(real_t learning_rate, int max_epoch, int mini_batch_size, re v_hidden = alg.addition_vt(alg.scalar_multiply_vm(b2, v_hidden), alg.scalar_multiply_vm(1 - b2, alg.exponentiate_vt(grads.cumulative_hidden_layer_w_grad, 2))); m_output = alg.additionnv(alg.scalar_multiplynv(b1, m_output), alg.scalar_multiplynv(1 - b1, grads.output_w_grad)); - v_output = alg.additionnv(alg.scalar_multiplynv(b2, v_output), alg.scalar_multiplynv(1 - b2, alg.exponentiatev(grads.output_w_grad, 2))); + v_output = alg.additionnv(alg.scalar_multiplynv(b2, v_output), alg.scalar_multiplynv(1 - b2, alg.exponentiatenv(grads.output_w_grad, 2))); Vector> m_hidden_hat = alg.scalar_multiply_vm(1 / (1.0 - Math::pow(b1, epoch)), m_hidden); Vector> v_hidden_hat = alg.scalar_multiply_vm(1 / (1.0 - Math::pow(b2, epoch)), v_hidden); @@ -607,7 +607,7 @@ void MLPPANN::nadam(real_t learning_rate, int max_epoch, int mini_batch_size, re Ref m_output_final = alg.additionnv(alg.scalar_multiplynv(b1, m_output_hat), alg.scalar_multiplynv((1 - b1) / (1.0 - Math::pow(b1, epoch)), grads.output_w_grad)); Vector> hidden_layer_updations = alg.scalar_multiply_vm(learning_rate / _n, alg.element_wise_division_vt(m_hidden_final, alg.scalar_add_vm(e, alg.sqrt_vt(v_hidden_hat)))); - Ref output_layer_updation = alg.scalar_multiplynv(learning_rate / _n, alg.element_wise_divisionm(m_output_final, alg.scalar_addnv(e, alg.sqrtv(v_output_hat)))); + Ref output_layer_updation = alg.scalar_multiplynv(learning_rate / _n, alg.element_wise_divisionm(m_output_final, alg.scalar_addnv(e, alg.sqrtnv(v_output_hat)))); update_parameters(hidden_layer_updations, output_layer_updation, learning_rate); // subject to change. may want bias to have this matrix too. @@ -681,13 +681,13 @@ void MLPPANN::amsgrad(real_t learning_rate, int max_epoch, int mini_batch_size, v_hidden = alg.addition_vt(alg.scalar_multiply_vm(b2, v_hidden), alg.scalar_multiply_vm(1 - b2, alg.exponentiate_vt(grads.cumulative_hidden_layer_w_grad, 2))); m_output = alg.additionnv(alg.scalar_multiplynv(b1, m_output), alg.scalar_multiplynv(1 - b1, grads.output_w_grad)); - v_output = alg.additionnv(alg.scalar_multiplynv(b2, v_output), alg.scalar_multiplynv(1 - b2, alg.exponentiatev(grads.output_w_grad, 2))); + v_output = alg.additionnv(alg.scalar_multiplynv(b2, v_output), alg.scalar_multiplynv(1 - b2, alg.exponentiatenv(grads.output_w_grad, 2))); v_hidden_hat = alg.max_vt(v_hidden_hat, v_hidden); v_output_hat = alg.maxnvv(v_output_hat, v_output); Vector> hidden_layer_updations = alg.scalar_multiply_vm(learning_rate / _n, alg.element_wise_division_vt(m_hidden, alg.scalar_add_vm(e, alg.sqrt_vt(v_hidden_hat)))); - Ref output_layer_updation = alg.scalar_multiplynv(learning_rate / _n, alg.element_wise_division(m_output, alg.scalar_addnv(e, alg.sqrtv(v_output_hat)))); + Ref output_layer_updation = alg.scalar_multiplynv(learning_rate / _n, alg.element_wise_division(m_output, alg.scalar_addnv(e, alg.sqrtnv(v_output_hat)))); update_parameters(hidden_layer_updations, output_layer_updation, learning_rate); // subject to change. may want bias to have this matrix too. y_hat = model_set_test(current_input_batch); diff --git a/mlpp/lin_alg/lin_alg.cpp b/mlpp/lin_alg/lin_alg.cpp index cf50842..b4cc199 100644 --- a/mlpp/lin_alg/lin_alg.cpp +++ b/mlpp/lin_alg/lin_alg.cpp @@ -2171,7 +2171,7 @@ std::vector MLPPLinAlg::cbrt(std::vector a) { return exponentiate(a, real_t(1) / real_t(3)); } -Ref MLPPLinAlg::logv(const Ref &a) { +Ref MLPPLinAlg::lognv(const Ref &a) { ERR_FAIL_COND_V(!a.is_valid(), Ref()); Ref out; @@ -2189,7 +2189,7 @@ Ref MLPPLinAlg::logv(const Ref &a) { return out; } -Ref MLPPLinAlg::log10v(const Ref &a) { +Ref MLPPLinAlg::log10nv(const Ref &a) { ERR_FAIL_COND_V(!a.is_valid(), Ref()); Ref out; @@ -2207,7 +2207,7 @@ Ref MLPPLinAlg::log10v(const Ref &a) { return out; } -Ref MLPPLinAlg::expv(const Ref &a) { +Ref MLPPLinAlg::expnv(const Ref &a) { ERR_FAIL_COND_V(!a.is_valid(), Ref()); Ref out; @@ -2225,7 +2225,7 @@ Ref MLPPLinAlg::expv(const Ref &a) { return out; } -Ref MLPPLinAlg::erfv(const Ref &a) { +Ref MLPPLinAlg::erfnv(const Ref &a) { ERR_FAIL_COND_V(!a.is_valid(), Ref()); Ref out; @@ -2243,7 +2243,7 @@ Ref MLPPLinAlg::erfv(const Ref &a) { return out; } -Ref MLPPLinAlg::exponentiatev(const Ref &a, real_t p) { +Ref MLPPLinAlg::exponentiatenv(const Ref &a, real_t p) { ERR_FAIL_COND_V(!a.is_valid(), Ref()); Ref out; @@ -2261,7 +2261,7 @@ Ref MLPPLinAlg::exponentiatev(const Ref &a, real_t p) { return out; } -Ref MLPPLinAlg::sqrtv(const Ref &a) { +Ref MLPPLinAlg::sqrtnv(const Ref &a) { ERR_FAIL_COND_V(!a.is_valid(), Ref()); Ref out; @@ -2279,8 +2279,8 @@ Ref MLPPLinAlg::sqrtv(const Ref &a) { return out; } -Ref MLPPLinAlg::cbrtv(const Ref &a) { - return exponentiatev(a, static_cast(1) / static_cast(3)); +Ref MLPPLinAlg::cbrtnv(const Ref &a) { + return exponentiatenv(a, static_cast(1) / static_cast(3)); } real_t MLPPLinAlg::dot(std::vector a, std::vector b) { diff --git a/mlpp/lin_alg/lin_alg.h b/mlpp/lin_alg/lin_alg.h index 84ba6f8..221f667 100644 --- a/mlpp/lin_alg/lin_alg.h +++ b/mlpp/lin_alg/lin_alg.h @@ -235,13 +235,13 @@ public: std::vector sqrt(std::vector a); std::vector cbrt(std::vector a); - Ref logv(const Ref &a); - Ref log10v(const Ref &a); - Ref expv(const Ref &a); - Ref erfv(const Ref &a); - Ref exponentiatev(const Ref &a, real_t p); - Ref sqrtv(const Ref &a); - Ref cbrtv(const Ref &a); + Ref lognv(const Ref &a); + Ref log10nv(const Ref &a); + Ref expnv(const Ref &a); + Ref erfnv(const Ref &a); + Ref exponentiatenv(const Ref &a, real_t p); + Ref sqrtnv(const Ref &a); + Ref cbrtnv(const Ref &a); real_t dot(std::vector a, std::vector b); real_t dotv(const Ref &a, const Ref &b); diff --git a/mlpp/lin_reg/lin_reg.cpp b/mlpp/lin_reg/lin_reg.cpp index f225688..299e5cd 100644 --- a/mlpp/lin_reg/lin_reg.cpp +++ b/mlpp/lin_reg/lin_reg.cpp @@ -405,7 +405,7 @@ void MLPPLinReg::adagrad(real_t learning_rate, int max_epoch, int mini_batch_siz v = alg.hadamard_productnv(weight_grad, weight_grad); - _weights = alg.subtractionnv(_weights, alg.scalar_multiplynv(learning_rate, alg.element_wise_division(weight_grad, alg.sqrtv(alg.scalar_addnv(e, v))))); + _weights = alg.subtractionnv(_weights, alg.scalar_multiplynv(learning_rate, alg.element_wise_division(weight_grad, alg.sqrtnv(alg.scalar_addnv(e, v))))); // Calculating the bias gradients _bias -= learning_rate * alg.sum_elementsv(error) / current_output_mini_batch->size(); // As normal @@ -460,7 +460,7 @@ void MLPPLinReg::adadelta(real_t learning_rate, int max_epoch, int mini_batch_si v = alg.additionnv(alg.scalar_multiplynv(b1, v), alg.scalar_multiplynv(1 - b1, alg.hadamard_productnv(weight_grad, weight_grad))); - _weights = alg.subtractionnv(_weights, alg.scalar_multiplynv(learning_rate, alg.element_wise_division(weight_grad, alg.sqrtv(alg.scalar_addnv(e, v))))); + _weights = alg.subtractionnv(_weights, alg.scalar_multiplynv(learning_rate, alg.element_wise_division(weight_grad, alg.sqrtnv(alg.scalar_addnv(e, v))))); // Calculating the bias gradients _bias -= learning_rate * alg.sum_elementsv(error) / current_output_mini_batch->size(); // As normal @@ -514,12 +514,12 @@ void MLPPLinReg::adam(real_t learning_rate, int max_epoch, int mini_batch_size, Ref weight_grad = alg.additionnv(gradient, reg_deriv_term); // Weight_grad_final m = alg.additionnv(alg.scalar_multiplynv(b1, m), alg.scalar_multiplynv(1 - b1, weight_grad)); - v = alg.additionnv(alg.scalar_multiplynv(b2, v), alg.scalar_multiplynv(1 - b2, alg.exponentiatev(weight_grad, 2))); + v = alg.additionnv(alg.scalar_multiplynv(b2, v), alg.scalar_multiplynv(1 - b2, alg.exponentiatenv(weight_grad, 2))); Ref m_hat = alg.scalar_multiplynv(1 / (1 - Math::pow(b1, epoch)), m); Ref v_hat = alg.scalar_multiplynv(1 / (1 - Math::pow(b2, epoch)), v); - _weights = alg.subtractionnv(_weights, alg.scalar_multiplynv(learning_rate, alg.element_wise_divisionm(m_hat, alg.scalar_addnv(e, alg.sqrtv(v_hat))))); + _weights = alg.subtractionnv(_weights, alg.scalar_multiplynv(learning_rate, alg.element_wise_divisionm(m_hat, alg.scalar_addnv(e, alg.sqrtnv(v_hat))))); // Calculating the bias gradients _bias -= learning_rate * alg.sum_elementsv(error) / current_output_mini_batch->size(); // As normal @@ -631,13 +631,13 @@ void MLPPLinReg::nadam(real_t learning_rate, int max_epoch, int mini_batch_size, Ref weight_grad = alg.additionnv(gradient, reg_deriv_term); // Weight_grad_final m = alg.additionnv(alg.scalar_multiplynv(b1, m), alg.scalar_multiplynv(1 - b1, weight_grad)); - v = alg.additionnv(alg.scalar_multiplynv(b2, v), alg.scalar_multiplynv(1 - b2, alg.exponentiatev(weight_grad, 2))); + v = alg.additionnv(alg.scalar_multiplynv(b2, v), alg.scalar_multiplynv(1 - b2, alg.exponentiatenv(weight_grad, 2))); m_final = alg.additionnv(alg.scalar_multiplynv(b1, m), alg.scalar_multiplynv((1 - b1) / (1 - Math::pow(b1, epoch)), weight_grad)); Ref m_hat = alg.scalar_multiplynv(1 / (1 - Math::pow(b1, epoch)), m); Ref v_hat = alg.scalar_multiplynv(1 / (1 - Math::pow(b2, epoch)), v); - _weights = alg.subtractionnv(_weights, alg.scalar_multiplynv(learning_rate, alg.element_wise_division(m_final, alg.scalar_addnv(e, alg.sqrtv(v_hat))))); + _weights = alg.subtractionnv(_weights, alg.scalar_multiplynv(learning_rate, alg.element_wise_division(m_final, alg.scalar_addnv(e, alg.sqrtnv(v_hat))))); // Calculating the bias gradients _bias -= learning_rate * alg.sum_elementsv(error) / current_output_mini_batch->size(); // As normal