Adapt Q-learning network types to new API.

This commit is contained in:
Ryan Curtin
2022-06-15 22:58:26 -04:00
parent 3880da3f3e
commit de329c9c9f
4 changed files with 12 additions and 16 deletions
@@ -52,10 +52,12 @@ QLearning<
targetNetwork = learningNetwork;
// Set up q-learning network.
if (learningNetwork.Parameters().is_empty())
learningNetwork.Reset();
if (learningNetwork.Parameters().n_elem != environment.InitialSample().Encode().n_elem)
learningNetwork.Reset(environment.InitialSample().Encode().n_elem);
targetNetwork.Reset();
// Initialize the target network with the parameters of learning network.
targetNetwork.Parameters() = learningNetwork.Parameters();
targetNetwork.Reset(environment.InitialSample().Encode().n_elem);
#if ENS_VERSION_MAJOR == 1
this->updater.Initialize(learningNetwork.Parameters().n_rows,
@@ -66,9 +68,6 @@ QLearning<
learningNetwork.Parameters().n_rows,
learningNetwork.Parameters().n_cols);
#endif
// Initialize the target network with the parameters of learning network.
targetNetwork.Parameters() = learningNetwork.Parameters();
}
template <
@@ -167,9 +167,9 @@ class CategoricalDQN
/**
* Resets the parameters of the network.
*/
void Reset()
void Reset(const size_t inputDimensionality = 0)
{
network.Reset();
network.Reset(inputDimensionality);
}
/**
@@ -126,7 +126,6 @@ class DuelingDQN
completeNetwork.Add(featureNetwork);
completeNetwork.Add(concat);
this->Reset();
}
/**
@@ -151,7 +150,6 @@ class DuelingDQN
concat->Add(advantageNetwork);
completeNetwork.Add(featureNetwork);
completeNetwork.Add(concat);
this->Reset();
}
//! Copy constructor.
@@ -185,8 +183,7 @@ class DuelingDQN
completeNetwork.Predict(state, networkOutput);
value = networkOutput.row(0);
advantage = networkOutput.rows(1, networkOutput.n_rows - 1);
actionValue = advantage.each_row() +
(value - arma::mean(advantage));
actionValue = advantage.each_row() + (value - arma::mean(advantage));
}
/**
@@ -228,9 +225,9 @@ class DuelingDQN
/**
* Resets the parameters of the network.
*/
void Reset()
void Reset(const size_t inputDimensionality = 0)
{
completeNetwork.Reset();
completeNetwork.Reset(inputDimensionality);
}
/**
@@ -118,9 +118,9 @@ class SimpleDQN
/**
* Resets the parameters of the network.
*/
void Reset()
void Reset(const size_t inputDimensionality = 0)
{
network.Reset();
network.Reset(inputDimensionality);
}
/**