Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AMOEBA3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMAC
Learning Group
AMOEBA3
Commits
9846af44
Commit
9846af44
authored
5 years ago
by
Hugo Roussel
Browse files
Options
Downloads
Patches
Plain Diff
small improvements
parent
4cf7a490
No related branches found
No related tags found
1 merge request
!4
Exp rein
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
AMOEBAonAMAK/src/experiments/SimpleReinforcement.java
+15
-9
15 additions, 9 deletions
AMOEBAonAMAK/src/experiments/SimpleReinforcement.java
with
15 additions
and
9 deletions
AMOEBAonAMAK/src/experiments/SimpleReinforcement.java
+
15
−
9
View file @
9846af44
...
@@ -43,8 +43,8 @@ public class SimpleReinforcement {
...
@@ -43,8 +43,8 @@ public class SimpleReinforcement {
private
Drawable
pos
;
private
Drawable
pos
;
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
poc
(
true
);
//
poc(true);
//
exp1();
exp1
();
}
}
...
@@ -62,7 +62,7 @@ public class SimpleReinforcement {
...
@@ -62,7 +62,7 @@ public class SimpleReinforcement {
return
;
// now compilator know config is initialized
return
;
// now compilator know config is initialized
}
}
Configuration
.
commandLineMode
=
true
;
//
Configuration.commandLineMode = true;
Log
.
defaultMinLevel
=
Log
.
Level
.
INFORM
;
Log
.
defaultMinLevel
=
Log
.
Level
.
INFORM
;
World
.
minLevel
=
TRACE_LEVEL
.
ERROR
;
World
.
minLevel
=
TRACE_LEVEL
.
ERROR
;
AMOEBA
amoeba
=
new
AMOEBA
(
config
.
getAbsolutePath
(),
null
);
AMOEBA
amoeba
=
new
AMOEBA
(
config
.
getAbsolutePath
(),
null
);
...
@@ -75,7 +75,7 @@ public class SimpleReinforcement {
...
@@ -75,7 +75,7 @@ public class SimpleReinforcement {
double
explo
=
0.8
;
double
explo
=
0.8
;
int
nbGood
=
0
;
int
nbGood
=
0
;
int
nbBad
=
0
;
int
nbBad
=
0
;
for
(
int
i
=
0
;
i
<
10
00
;
i
++)
{
for
(
int
i
=
0
;
i
<
2
00
;
i
++)
{
Deque
<
HashMap
<
String
,
Double
>>
actions
=
new
ArrayDeque
<>();
Deque
<
HashMap
<
String
,
Double
>>
actions
=
new
ArrayDeque
<>();
//System.out.println("Explore "+i);
//System.out.println("Explore "+i);
int
nbStep
=
0
;
int
nbStep
=
0
;
...
@@ -156,8 +156,10 @@ public class SimpleReinforcement {
...
@@ -156,8 +156,10 @@ public class SimpleReinforcement {
System
.
out
.
println
(
"Good: "
+
nbGood
+
" Bad: "
+
nbBad
+
" Good%: "
+
percentGood
);
System
.
out
.
println
(
"Good: "
+
nbGood
+
" Bad: "
+
nbBad
+
" Good%: "
+
percentGood
);
// tests
// tests
int
nbTest
=
500
;
double
nbPositiveReward
=
0.0
;
double
tot_reward
=
0.0
;
double
tot_reward
=
0.0
;
for
(
int
i
=
0
;
i
<
500
;
i
++)
{
for
(
int
i
=
0
;
i
<
nbTest
;
i
++)
{
double
reward
=
0.0
;
double
reward
=
0.0
;
state
=
env
.
reset
();
state
=
env
.
reset
();
HashMap
<
String
,
Double
>
action
=
new
HashMap
<
String
,
Double
>();
HashMap
<
String
,
Double
>
action
=
new
HashMap
<
String
,
Double
>();
...
@@ -187,10 +189,14 @@ public class SimpleReinforcement {
...
@@ -187,10 +189,14 @@ public class SimpleReinforcement {
state
=
state2
;
state
=
state2
;
}
}
if
(
reward
>
0
)
{
nbPositiveReward
+=
1.0
;
}
tot_reward
+=
reward
;
tot_reward
+=
reward
;
}
}
System
.
out
.
println
(
"Average reward : "
+
tot_reward
/
500.0
);
System
.
out
.
println
(
"Test average reward : "
+
tot_reward
/
nbTest
+
" Positive reward %: "
+(
nbPositiveReward
/
nbTest
));
//AmoebaWindow.instance().point.move(100, 100);
//AmoebaWindow.instance().mainVUI.updateCanvas();
}
}
/**
/**
...
@@ -390,12 +396,10 @@ public class SimpleReinforcement {
...
@@ -390,12 +396,10 @@ public class SimpleReinforcement {
double
oldX
=
x
;
double
oldX
=
x
;
x
=
x
+
action
;
x
=
x
+
action
;
if
(
x
<
-
50.0
||
x
>
50.0
)
{
if
(
x
<
-
50.0
||
x
>
50.0
)
{
x
=
RandomUtils
.
nextDouble
(
rand
,
-
50.0
,
Math
.
nextUp
(
50.0
));
reward
=
-
100.0
;
reward
=
-
100.0
;
}
else
if
(
x
==
0.0
||
sign
(
oldX
)
!=
sign
(
x
))
{
}
else
if
(
x
==
0.0
||
sign
(
oldX
)
!=
sign
(
x
))
{
// win !
// win !
reward
=
100.0
;
reward
=
100.0
;
x
=
RandomUtils
.
nextDouble
(
rand
,
-
50.0
,
Math
.
nextUp
(
50.0
));
}
else
{
}
else
{
reward
=
-
1.0
;
reward
=
-
1.0
;
}
}
...
@@ -408,7 +412,9 @@ public class SimpleReinforcement {
...
@@ -408,7 +412,9 @@ public class SimpleReinforcement {
public
HashMap
<
String
,
Double
>
reset
(){
public
HashMap
<
String
,
Double
>
reset
(){
x
=
RandomUtils
.
nextDouble
(
rand
,
-
50.0
,
Math
.
nextUp
(
50.0
));
x
=
RandomUtils
.
nextDouble
(
rand
,
-
50.0
,
Math
.
nextUp
(
50.0
));
x
=
Math
.
round
(
x
);
reward
=
0.0
;
reward
=
0.0
;
//pos.move(x+0.5, 0.5);
HashMap
<
String
,
Double
>
ret
=
new
HashMap
<>();
HashMap
<
String
,
Double
>
ret
=
new
HashMap
<>();
ret
.
put
(
"p1"
,
x
);
ret
.
put
(
"p1"
,
x
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment