이 프로그램에서는 20 회 반복 실행됩니다. 각 반복은 터미널 상태에 도달하면 완료됩니다. 나는 20 개의 모든 반복에 대한 결과를 텍스트 파일에 쓰려고하지만, 마지막 반복 만 텍스트 파일에 쓰게됩니다.텍스트 파일에 arraylist 결과 추가
나는 두 명의 arraylists를 만들고 두 개의 arraylists에게 "numsteps"(iteration의 단계 수를 유지함) 및 "rewards"(그 반복에 대한 보상의 총계를 유지함)를 추가함으로써 생각했습니다. ''steps ''and ' "rewards"'를 입력하면 각 반복마다 모든 값을 arraylists에 삽입 한 다음 arraylists를 텍스트 파일에 입력합니다.
그러나 지금은 numsteps 및 보상의 마지막 반복 만 텍스트 파일에 삽입합니다.
내가 잘못 가고있는 사람을 누구나 볼 수 있습니까?
if (nextState.isTerminal()) {
//storing total number of steps and total of rewards int x and y
double reward = ((GridEnvir) env).total;
int numsteps = (int) ((GridEnvir) env).numStepsInTrial;
//create array for number of steps in trial = steps
ArrayList<Integer> steps = new ArrayList<Integer>();
steps.add(numsteps);
//create array for rewards in trial = rewards
ArrayList<Double> rewards = new ArrayList<Double>();
rewards.add(reward);
try {
// method to write to a text file.
write(steps, rewards, 20);
} catch (IOException e) {
System.out.println("does work");
}
/// printing out to the console window each time the nextState.isTerminal() condition is reached
System.out.println("\n Found goal in " + x + " steps "+ " total reward " + y);
System.out.println(agt);
}
}
이 다음 방법은 텍스트 파일에 결과를 씁니다. 아래
public static void write(ArrayList<Integer> numsteps, ArrayList<Double> reward,
int episode) throws IOException {
PrintWriter pw = new PrintWriter(
// not actual (this part of code is hidden)
"results.txt");
int y[] = new int[episode];
pw.write("NumSteps" + "\t " + "reward" + "\n");
for (int i = 0; i < y.length; i++) {
for (int a : numsteps) {
for (Double b : reward)
pw.write(a + "\t\t " + b + "\n");
}// }
pw.close();
}
}}
안녕하십니까. 안녕하세요. 나는 그것을 시도했지만 지금은 20 번 마지막 결과를 씁니다. – DugD
마지막 결과가 20 번 의미하는 점은 무엇입니까? 당신의리스트 numsteps가 1, 2이고 보상에 3, 4가 있다면 1,3 ... 1,4 .. 2,3 .. 2,4 ..이 4 줄은 20 번 .. – SMA
무슨 뜻입니까? 마지막 반복은 15 개의 단계와 보상 4를 가질 수 있으며, 결과의 모두를 얻는 대신 20, 15, 4 (15 4) 등의 결과를 출력합니다. 예 : (35, 23) (20, 20) (15, 4) (11, 0) – DugD