add results for convergence for advanced dino jumping

This commit is contained in:
Jan Löwenstrom 2020-03-05 13:17:54 +01:00
parent e67f40ad65
commit 4641f50b79
10 changed files with 58 additions and 8 deletions

BIN
convResAdvScale.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

BIN
convResultAdv.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

View File

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

20
convergenceAdv.txt Normal file
View File

@ -0,0 +1,20 @@
0.05,447,1036,447,788,499,499,880,514,583,420,759,678,529,781,742,185,848,346,733,961,657,312,599,245,1076,1361,377,612,821,481,374,250,171,949,1079,788,465,537,431,312,565,1046,825,579,1178,547,1111,518,949,779,924,430,543,1262,642,814,508,422,1120,536,591,381,670,681,382,297,795,774,1552,691,909,748,520,639,704,575,752,418,503,292,1159,1020,570,839,696,895,511,635,830,522,628,518,408,392,605,888,790,629,547,999
0.1,337,303,221,455,64,271,377,946,381,253,669,479,267,870,250,364,347,83,124,464,356,535,820,180,369,310,284,456,166,267,240,215,347,295,226,409,344,266,404,480,195,235,655,233,429,149,304,164,409,276,268,139,495,388,401,283,343,284,720,351,170,781,59,369,789,155,206,464,380,272,645,180,216,698,166,497,650,297,595,352,138,163,412,238,336,90,453,238,306,598,487,722,640,592,493,144,435,441,387,374
0.15,288,400,363,158,414,302,126,175,323,303,391,202,295,329,468,198,199,179,384,193,168,443,74,153,347,458,395,209,545,199,421,587,144,200,219,204,134,200,253,193,396,108,530,728,286,118,256,351,279,308,210,713,474,415,397,328,220,201,136,515,374,154,847,578,313,250,224,392,362,551,127,211,321,176,372,572,304,290,225,541,296,315,392,235,161,359,307,360,613,194,389,278,334,153,402,224,246,260,264,226
0.2,193,331,294,156,245,530,237,199,225,298,414,424,342,239,361,295,176,326,155,371,272,255,259,201,506,520,108,172,416,220,245,283,203,213,164,469,262,263,177,80,174,346,573,577,243,226,437,427,261,195,210,389,286,297,263,328,393,174,166,267,344,223,161,171,321,256,322,251,238,164,216,198,449,327,328,175,334,260,479,269,389,137,292,384,232,549,394,177,207,165,123,304,346,407,437,66,176,358,277,111
0.25,155,195,340,162,250,300,204,218,278,291,184,282,95,370,265,275,168,229,207,463,273,157,233,106,338,414,397,305,283,374,347,243,78,172,284,296,187,439,149,513,689,99,93,260,382,204,141,310,170,409,436,112,283,435,284,108,210,264,335,177,121,181,124,294,129,394,183,117,211,137,254,384,263,228,423,443,349,142,115,276,268,251,275,191,387,283,124,212,191,167,490,329,293,194,294,241,432,50,105,341
0.3,282,128,127,74,136,311,303,206,150,387,167,353,286,138,107,269,343,301,157,370,553,161,292,175,250,187,259,451,222,203,312,177,212,248,197,276,122,236,159,480,274,474,46,208,96,248,131,358,301,142,302,298,153,105,524,131,225,343,207,301,409,321,505,546,131,395,275,151,148,280,266,539,116,105,166,232,245,155,219,222,123,174,221,162,521,206,325,77,388,199,380,222,52,177,119,98,323,378,262,214
0.35,404,130,174,176,297,284,274,139,279,225,105,115,238,191,278,162,185,316,233,535,175,131,86,245,135,262,285,427,214,224,139,170,348,371,385,151,231,258,202,260,293,109,159,323,317,68,231,170,313,168,222,216,357,225,177,125,195,361,242,133,258,158,174,101,132,272,131,213,224,124,232,701,395,321,173,144,226,260,220,211,352,190,188,422,260,151,167,241,459,237,298,225,123,274,107,242,253,134,132,288
0.40,318,374,159,305,164,220,69,174,233,277,163,293,236,323,154,210,209,117,271,126,155,632,233,208,417,273,127,213,73,223,99,118,178,197,137,207,138,351,208,254,232,207,609,256,169,164,403,589,145,79,344,293,270,218,162,221,341,71,125,203,215,178,81,150,213,223,368,236,244,249,231,166,317,171,164,208,292,172,174,256,285,136,236,446,312,371,285,152,155,524,171,113,287,156,281,97,209,195,368,283
0.45,198,106,298,295,298,124,168,159,194,144,110,270,253,225,126,191,184,119,255,484,528,147,181,190,345,166,158,211,304,242,92,199,219,129,86,170,167,150,190,168,514,317,154,164,186,261,276,234,72,241,130,233,269,136,217,73,219,193,353,42,127,305,361,313,86,109,254,400,327,452,165,350,192,139,499,192,147,313,225,159,122,121,228,217,79,162,183,354,360,432,258,313,325,317,265,33,175,233,203,178
0.50,149,341,278,153,204,216,244,250,291,247,268,114,175,202,87,236,377,280,161,444,199,185,112,52,495,248,87,199,327,374,192,136,545,92,174,186,85,238,277,274,227,139,112,300,205,292,398,188,329,214,114,55,212,154,533,109,139,165,216,280,210,231,193,295,149,190,131,130,184,159,161,229,286,146,218,151,137,265,80,191,326,282,194,164,114,203,221,495,298,187,116,110,119,140,237,203,124,307,260,164
0.55,190,161,170,533,205,104,85,228,610,294,293,380,297,333,498,303,198,248,430,180,157,131,402,706,346,282,151,102,346,227,195,98,306,391,533,312,297,149,480,191,93,110,233,104,434,244,296,124,131,275,157,165,93,94,241,96,82,417,283,150,148,142,262,216,425,223,531,430,203,153,254,221,162,472,361,286,243,202,205,433,228,266,162,156,296,487,288,196,278,195,88,400,302,216,181,283,185,137,262,120
0.60,106,272,207,213,259,228,104,214,245,230,122,170,296,190,223,208,455,133,207,257,147,182,252,475,193,115,254,97,406,167,49,179,199,77,163,234,242,157,153,347,200,322,62,191,152,381,236,119,229,563,127,171,127,126,371,213,565,505,135,242,301,224,221,135,466,185,470,217,403,334,122,362,449,349,285,101,114,281,194,210,410,200,400,199,428,306,387,146,102,375,209,75,139,100,214,295,187,284,230,175
0.65,136,80,343,113,146,367,303,463,507,284,211,365,259,522,44,261,122,188,1135,253,305,97,252,234,54,217,220,114,203,194,151,163,201,233,284,603,170,247,299,564,255,333,373,256,244,152,301,86,125,149,263,457,420,431,68,297,336,329,290,194,230,288,161,124,108,201,1089,296,233,737,351,253,38,688,448,148,807,273,119,131,514,98,157,159,486,231,288,164,228,47,163,287,576,141,145,197,272,248,201,787
0.70,272,201,329,67,281,293,356,217,213,372,266,346,434,143,264,390,341,296,142,263,330,102,384,669,602,275,149,259,225,227,339,222,397,422,474,274,481,337,585,344,387,308,222,249,396,615,321,310,135,187,296,225,362,146,222,157,336,307,187,486,89,217,223,277,262,235,157,548,249,119,403,348,550,326,273,428,322,225,192,240,824,779,343,146,406,96,268,144,653,344,527,121,224,562,416,180,166,151,201,64
0.75,815,131,219,257,95,270,177,38,283,207,451,478,422,108,331,666,573,281,139,102,179,218,87,284,274,370,173,130,235,534,420,219,174,352,234,343,337,171,302,276,1122,220,236,181,200,423,208,348,191,205,346,545,333,438,178,281,270,203,90,238,436,66,236,561,174,299,188,147,140,217,298,263,244,84,639,126,285,233,159,138,47,378,845,166,317,236,480,91,306,163,325,732,106,271,299,398,125,238,588,306
0.80,295,191,493,205,1165,763,1031,238,69,412,56,509,356,336,97,722,106,524,239,403,493,337,270,341,112,147,448,603,356,130,336,490,854,672,253,188,375,442,308,222,625,353,216,160,265,442,263,464,143,261,686,319,160,413,237,128,147,165,391,478,632,598,333,187,463,433,253,357,134,84,671,224,273,334,185,142,666,200,112,270,113,221,1003,432,210,414,194,187,101,292,69,424,862,190,306,235,339,268,64,178
0.85,221,61,356,234,367,238,586,474,171,168,411,157,295,304,242,118,245,361,250,856,256,194,738,391,499,213,234,411,1910,369,455,315,800,85,212,117,200,518,99,76,796,640,335,256,225,415,612,123,141,301,154,313,329,812,414,104,648,657,192,163,544,1346,305,229,131,4275,222,374,484,386,139,287,734,251,187,232,688,293,718,276,156,507,289,395,493,152,107,905,184,507,267,307,437,724,241,518,238,183,379,285
0.90,651,606,207,546,347,1180,121,112,1135,135,203,396,245,275,354,130,320,254,255,148,291,263,448,344,237,357,211,318,700,212,234,545,240,404,277,438,391,383,402,551,392,131,740,643,393,373,288,297,403,342,288,234,319,352,869,396,277,595,87,150,833,710,129,520,619,151,150,375,860,243,282,242,296,549,426,100,890,315,505,451,184,167,643,154,56,252,147,915,463,139,227,697,386,324,292,625,66,161,420,526
0.95,421,588,274,114,492,232,230,464,736,233,182,92,401,208,116,357,313,200,308,331,4166,440,575,1279,104,849,42,246,657,2075,203,85,1028,963,1433,696,221,169,168,276,166,238,434,713,1769,295,638,386,186,255,167,382,830,242,1249,260,592,1796,816,359,416,202,3354,928,220,343,596,57,146,705,313,309,500,138,482,57,309,590,913,380,311,212,286,324,950,894,532,525,231,2050,537,72,616,220,273,307,836,105,324,332
1.00,898,274,43,1486,173,433,52,573,214,154,602,339,66,719,378,366,857,438,246,775,1006,551,390,182,479,365,473,765,487,1763,759,185,335,286,369,138,220,240,307,669,239,402,180,254,224,240,327,197,2168,363,364,139,485,1176,322,257,707,667,208,794,166,2786,769,147,525,584,329,667,1233,613,456,3296,386,216,684,956,217,1735,662,146,447,99,681,38,1009,133,258,935,229,878,283,499,304,155,611,532,1257,621,394,564

6
epsilonValues.R Normal file
View File

@ -0,0 +1,6 @@
# Libraries
library(ggplot2)
convergence <- read.csv(file.choose(), header=FALSE, row.names=1)
men <- rowMeans(convergence[,-1])
ba <- barplot(names=rownames(convergence), height=men, ylim=c(0,max(men) +100), ylab = "avg. episodes until convergence", xlab = "epsilon value")
text(x = ba, y = men, label = as.integer(men), pos = 3, cex = 0.8, col = "red")

View File

@ -107,7 +107,7 @@ public abstract class EpisodicLearning<A extends Enum> extends Learning<A> imple
if(timestampCurrentEpisode > 300000){
converged = true;
// t
File file = new File("convergence.txt");
File file = new File("convergenceAdv.txt");
try {
Files.writeString(Path.of(file.getPath()), currentEpisode/2 + ",", StandardOpenOption.APPEND);
} catch (IOException e) {

View File

@ -10,6 +10,9 @@ import lombok.Getter;
import javax.swing.*;
import java.awt.*;
/**
* 57 states
*/
@Getter
public class DinoWorld implements Environment<DinoAction>, Visualizable {
protected Dino dino;

View File

@ -1,9 +1,19 @@
package evironment.jumpingDino;
import core.RNG;
import core.State;
import java.awt.*;
/**
* 3580 states
* if:
* dx = -(int)((Math.random() + 0.5) * Config.OBSTACLE_SPEED);
* xSpawn = Config.FRAME_WIDTH + Config.FRAME_WIDTH + Config.OBSTACLE_SIZE;
*
* 350 states
* if 4 speed variants
*/
public class DinoWorldAdvanced extends DinoWorld{
public DinoWorldAdvanced(){
super();
@ -18,9 +28,18 @@ public class DinoWorldAdvanced extends DinoWorld{
protected void spawnNewObstacle() {
int dx;
int xSpawn;
dx = -(int)((Math.random() + 0.5) * Config.OBSTACLE_SPEED);
double ran = RNG.getRandom().nextDouble();
if(ran < 0.25){
dx = -(int)(0.7 * Config.OBSTACLE_SPEED);
}else if(ran < 0.5){
dx = -(int)(1.3 * Config.OBSTACLE_SPEED);
}else if(ran < 0.75){
dx = -(int)(1.6 * Config.OBSTACLE_SPEED);
} else{
dx = -2 * Config.OBSTACLE_SPEED;
}
// randomly spawning more right outside of the screen
xSpawn = (int)(Math.random() + 0.5 * Config.FRAME_WIDTH + Config.FRAME_WIDTH + Config.OBSTACLE_SIZE);
xSpawn = Config.FRAME_WIDTH + Config.FRAME_WIDTH + Config.OBSTACLE_SIZE;
currentObstacle = new Obstacle(Config.OBSTACLE_SIZE, xSpawn, Config.FRAME_HEIGHT - Config.GROUND_Y - Config.OBSTACLE_SIZE, dx, 0, Color.BLACK);
}
}

View File

@ -5,6 +5,7 @@ import core.algo.Method;
import core.controller.RLController;
import evironment.jumpingDino.DinoAction;
import evironment.jumpingDino.DinoWorld;
import evironment.jumpingDino.DinoWorldAdvanced;
import java.io.File;
import java.io.IOException;
@ -14,7 +15,7 @@ import java.nio.file.StandardOpenOption;
public class DinoSampling {
public static void main(String[] args) {
File file = new File("convergence.txt");
File file = new File("convergenceAdv.txt");
for(float f = 0.05f; f <=1.003 ; f+=0.05f){
try {
Files.writeString(Path.of(file.getPath()), f + ",", StandardOpenOption.APPEND);
@ -26,14 +27,14 @@ public class DinoSampling {
RNG.setSeed(i *13);
RLController<DinoAction> rl = new RLController<>(
new DinoWorld(),
new DinoWorldAdvanced(),
Method.MC_CONTROL_FIRST_VISIT,
DinoAction.values());
rl.setDelay(0);
rl.setDiscountFactor(1f);
rl.setEpsilon(f);
rl.setLearningRate(1f);
rl.setNrOfEpisodes(20000);
rl.setNrOfEpisodes(100000);
rl.start();
}

View File

@ -6,13 +6,14 @@ import core.controller.RLController;
import core.controller.RLControllerGUI;
import evironment.jumpingDino.DinoAction;
import evironment.jumpingDino.DinoWorld;
import evironment.jumpingDino.DinoWorldAdvanced;
public class JumpingDino {
public static void main(String[] args) {
RNG.setSeed(55);
RLController<DinoAction> rl = new RLControllerGUI<>(
new DinoWorld(),
new DinoWorldAdvanced(),
Method.MC_CONTROL_FIRST_VISIT,
DinoAction.values());
@ -20,7 +21,7 @@ public class JumpingDino {
rl.setDiscountFactor(1f);
rl.setEpsilon(0.15f);
rl.setLearningRate(1f);
rl.setNrOfEpisodes(10000);
rl.setNrOfEpisodes(1000000);
rl.start();
}
}