Skip to content

Commit

Permalink
Minor updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
saaltone committed Feb 19, 2024
1 parent 9c0debb commit 4b3bc5e
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/core/reinforcement/value/AbstractValueFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public void setParams(DynamicParam params) throws DynamicParamException {
/**
* Updates value function for state set sampled from memory.
*
* @param sampledStates sampled states.
* @throws MatrixException throws exception if matrix operation fails.
* @throws NeuralNetworkException throws exception if neural network operation fails.
* @throws DynamicParamException throws exception if parameter (params) setting fails.
Expand All @@ -145,10 +146,8 @@ public void update(TreeSet<State> sampledStates) throws MatrixException, NeuralN
if (sampledStates == null) return;

for (State state : sampledStates.descendingSet()) {
state.value = getStateValue(state);
if (!state.isFinalState()) state.nextState.targetAction = getTargetAction(state.nextState);
state.tdTarget = state.reward + (state.isFinalState() ? 0 : gamma * getTargetValue(state.nextState));
state.tdError = state.tdTarget - state.value;
state.tdError = state.tdTarget - getStateValue(state);

averageReward = averageReward == Double.MIN_VALUE ? state.reward : averagingTau * averageReward + (1 - averagingTau) * state.reward;
averageTDTarget = averageTDTarget == Double.MIN_VALUE ? state.tdTarget : averagingTau * averageTDTarget + (1 - averagingTau) * state.tdTarget;
Expand Down Expand Up @@ -179,20 +178,10 @@ public void update(TreeSet<State> sampledStates) throws MatrixException, NeuralN
* @return target value based on next state
* @throws NeuralNetworkException throws exception if neural network operation fails.
* @throws MatrixException throws exception if matrix operation fails.
* @throws DynamicParamException throws exception if parameter (params) setting fails.
* @throws DynamicParamException throws exception if parameter (params) setting fails.
*/
protected abstract double getTargetValue(State nextState) throws NeuralNetworkException, MatrixException, DynamicParamException;

/**
* Returns target action based on next state.
*
* @param nextState next state.
* @return target action based on next state
* @throws NeuralNetworkException throws exception if neural network operation fails.
* @throws MatrixException throws exception if matrix operation fails.
*/
protected abstract int getTargetAction(State nextState) throws NeuralNetworkException, MatrixException;

/**
* Updates baseline value for states.
*
Expand Down

0 comments on commit 4b3bc5e

Please sign in to comment.