This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reactor replace internal optimizer with public shared optimizer (#45)
* refactor out the internal class from public API * remove todo -- it was incomplete type defintions * refactored internal optimizers while encapulating eigen * fix spelling * switch optimizers to shared ptr * missing CRTP * fix copy PASTE MISTAKE
- Loading branch information
1 parent
3288265
commit 4376e0e
Showing
11 changed files
with
75 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,20 @@ | ||
#include "CaberNet/optimizers.h" | ||
#include "internals/optimizers/internal_optimizers.hpp" | ||
|
||
namespace net::base { | ||
#include "internals/config.h" | ||
#include "internals/internal_tensor.hpp" | ||
|
||
Optimizer::~Optimizer() {} | ||
|
||
internal::Optimizer* Optimizer::get() const { | ||
return optimizer_.get(); | ||
} | ||
|
||
void Optimizer::add_parameter(internal::Tensor* parameter) { | ||
optimizer_->add_parameter(parameter); | ||
std::cout << "Parameter added" << std::endl; | ||
} | ||
|
||
void Optimizer::step() { | ||
if(optimizer_) optimizer_->step(); | ||
} | ||
|
||
} | ||
#if defined(USE_EIGEN_BACKEND) | ||
|
||
namespace net::optimizer { | ||
|
||
SGD::~SGD() {} | ||
|
||
SGD::SGD(float learning_rate) { | ||
optimizer_ = std::make_shared<internal::SGD>(learning_rate); | ||
void SGD::update(internal::Tensor* parameter) { | ||
Eigen::Map<Eigen::Array<internal::Tensor::scalar_type, 1, -1>> parameter_map(parameter->data(), parameter->size()); | ||
Eigen::Map<Eigen::Array<internal::Tensor::scalar_type, 1, -1>> parameter_gradient_map(parameter->gradient()->data(), parameter->size()); | ||
parameter_map -= learning_rate_ * parameter_gradient_map; | ||
parameter_gradient_map = 0; | ||
} | ||
|
||
} | ||
|
||
#endif |