@seeplus, qtable is not defined as const.
For updating matrix element, the row index and column index are actually variable.
Here is my code. I'm getting error for the bold commands.
#include <iostream>
#include <string>
#include <string.h>
#include <valarray>
#include <ctime>
#include <cstdlib>
using namespace std;
using matrix = valarray< valarray<double> >;
double state[] = {0, 1, 2};
double action_new[] = {44, 20.1036, 102.2713, 100.4267};
int state_size = sizeof(state)/sizeof(state[0]);
int action_size = sizeof(action_new)/sizeof(action_new[0]);
matrix qtable={ { 3, 44, 55, 6 }, { 2, 66, 4, 3 }, { 12, 33, 0, 1 } };
int main() {
cout<<"QTable = "<<endl;
for (int i = 0; i < state_size; ++i) {
for (int j = 0; j < action_size; ++j) {
cout << qtable[i][j] << "\t";
}
cout << endl;
}
for(int episode =1; episode<=5; ++episode)
{
//srand( time( 0 ) );
auto current_state_index = rand() % state_size;
auto current_state = state[current_state_index];
cout <<" current state index = " << current_state_index <<endl;
cout <<" current state = " <<current_state << endl;
auto chosen_action_value = qtable[current_state_index].max();
//finding index of the chosen action value
for (int m=0; m<action_size; ++m)
{
if(action_new[m]==chosen_action_value) {
auto chosen_action_index = m;
break;
}
}
//update Qtable element with row = current_state_index and col = chosen_action_index
qtable[current_state_index][chosen_action_index] = qtable[current_state_index][chosen_action_index] + 2;
}
srand( time( 0 ) );
cout<<"Updated QTable = "<<endl;
for (int i = 0; i < state_size; ++i) {
for (int j = 0; j < action_size; ++j) {
cout << qtable[i][j] << "\t";
}
cout << endl;
}
}
error: ‘chosen_action_index’ was not declared in this scope
qtable[current_state_index][chosen_action_index] = qtable[current_state_index][chosen_action_index] + 2;
Would you suggest me the correct command?
Thank you