[ARDUINO]Q-TABLE作り。


I think the Q-Table is a important part of Reinforcement Learning or Q-Learning.

Row is States, Column is Action.

Code


int Q_table[3][4] = {};

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  rand_input();
  view_table();

}
void view_table(){
  Serial.println("Q-table");
  for(int i = 0; i < 3; i++){ 
    for(int j = 0; j < 4 ; j++){
      Serial.print(Q_table[i][j]);
      Serial.print("\t");
    }
    Serial.println();
  }
}
void rand_input(){
  Serial.println("input random number");
  for(int i = 0; i < 3; i++){ 
    for(int j = 0; j < 4 ; j++){
      Q_table[i][j] = random(10,20);
      Serial.print(Q_table[i][j]);
      Serial.print("\t");
    }
    Serial.println();
  }
  delay(1000);
}

Result

If you have any other nice code,
pls, do leave a comment below.

Dreamwalker