Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify TD3 Reinforcement Learning Agent Creation #3682

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#ifndef MLPACK_METHODS_REINFORCEMENT_LEARNING_REINFORCEMENT_LEARNING_HPP
#define MLPACK_METHODS_REINFORCEMENT_LEARNING_REINFORCEMENT_LEARNING_HPP

#include "td3_default_values.hpp"

#include "environment/environment.hpp"
#include "policy/policy.hpp"
#include "q_networks/q_networks.hpp"
Expand Down
7 changes: 4 additions & 3 deletions src/mlpack/methods/reinforcement_learning/td3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "replay/replay.hpp"
#include "training_config.hpp"
#include "td3_default_values.hpp"

namespace mlpack {

Expand Down Expand Up @@ -47,9 +48,9 @@ namespace mlpack {
*/
template <
typename EnvironmentType,
typename QNetworkType,
typename PolicyNetworkType,
typename UpdaterType,
typename QNetworkType=decltype(DefaultValues::qNetwork()),
typename PolicyNetworkType=decltype(DefaultValues::policyNetwork()),
typename UpdaterType=decltype(DefaultValues::default_updater),
typename ReplayType = RandomReplay<EnvironmentType>
>
class TD3
Expand Down
69 changes: 69 additions & 0 deletions src/mlpack/methods/reinforcement_learning/td3_default_values.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @file methods/reinforcement_learning/td3_default_values.hpp
* @author Advaith P
*
* This file has default values for the TD3 class,which implements the
* Twin Delayed Deep Deterministic Policy Gradient algorithm.
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef DEFAULT_VALUES_RL_TD3
#define DEFAULT_VALUES_RL_TD3



#include <mlpack/core.hpp>
#include <ensmallen.hpp>
#include <mlpack/methods/ann/ann.hpp>
#include "training_config.hpp"

using namespace mlpack;
using namespace ens;


namespace DefaultValues
{

inline TrainingConfig TrainingConfigWithDefaults() {
TrainingConfig config;
config.StepSize() = 0.01;
config.TargetNetworkSyncInterval() = 1;
config.UpdateInterval() = 3;
config.Rho() = 0.001;
return config;
}

inline FFN<EmptyLoss, GaussianInitialization> qNetwork() {
// Construct qNetwork instance
FFN<EmptyLoss, GaussianInitialization> qNetworkInstance(EmptyLoss(), GaussianInitialization(0, 0.1));
// Add layers
qNetworkInstance.Add(new Linear(128));
qNetworkInstance.Add(new ReLU());
qNetworkInstance.Add(new Linear(1));
return qNetworkInstance;
}

inline FFN<EmptyLoss, GaussianInitialization> policyNetwork() {
// Construct policyNetwork instance
FFN<EmptyLoss, GaussianInitialization> policyNetworkInstance(EmptyLoss(), GaussianInitialization(0, 0.1));
// Add layers
policyNetworkInstance.Add(new Linear(128));
policyNetworkInstance.Add(new ReLU());
policyNetworkInstance.Add(new Linear(1));
policyNetworkInstance.Add(new TanH());
return policyNetworkInstance;
}


AdamUpdate default_updater;




}
#endif