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
d2b27c41
Commit
d2b27c41
authored
5 years ago
by
Hugo Roussel
Browse files
Options
Downloads
Patches
Plain Diff
Add AmoebaQL
parent
587145c6
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
+50
-7
50 additions, 7 deletions
AMOEBAonAMAK/src/experiments/SimpleReinforcement.java
with
50 additions
and
7 deletions
AMOEBAonAMAK/src/experiments/SimpleReinforcement.java
+
50
−
7
View file @
d2b27c41
...
...
@@ -31,13 +31,13 @@ import utils.XmlConfigGenerator;
public
class
SimpleReinforcement
{
/* Learn and Test */
public
static
final
int
MAX_STEP_PER_EPISODE
=
200
;
public
static
final
int
N_LEARN
=
2
00
;
public
static
final
int
N_TEST
=
10
;
public
static
final
int
N_LEARN
=
1
00
;
public
static
final
int
N_TEST
=
10
0
;
/* Exploration */
public
static
final
int
N_EXPLORE_LINE
=
0
;
public
static
final
int
N_EXPLORE_LINE
=
6
0
;
public
static
final
double
MIN_EXPLO_RATE
=
0.02
;
public
static
final
double
EXPLO_RATE_DIMINUTION_FACTOR
=
0.0
;
public
static
final
double
EXPLO_RATE_DIMINUTION_FACTOR
=
0.0
1
;
public
static
final
double
EXPLO_RATE_BASE
=
1
;
public
static
final
String
EXPLORATION_STRATEGY
=
"random"
;
// can be "random" or "line"
private
static
int
exploreLine
;
...
...
@@ -57,16 +57,59 @@ public class SimpleReinforcement {
public
void
learn
(
HashMap
<
String
,
Double
>
state
,
HashMap
<
String
,
Double
>
state2
,
HashMap
<
String
,
Double
>
action
,
boolean
done
);
}
public
static
class
AmoebaQL
implements
LearningAgent
{
public
AMOEBA
amoeba
;
public
double
lr
=
0.8
;
public
double
gamma
=
0.9
;
private
Random
rand
=
new
Random
();
public
AmoebaQL
()
{
amoeba
=
setup
();
amoeba
.
setLocalModel
(
TypeLocalModel
.
MILLER_REGRESSION
);
amoeba
.
getEnvironment
().
setMappingErrorAllowed
(
0.04
);
}
@Override
public
double
choose
(
HashMap
<
String
,
Double
>
state
)
{
double
a
=
amoeba
.
maximize
(
state
).
getOrDefault
(
"a1"
,
0.0
);
if
(
a
==
0.0
)
{
a
=
rand
.
nextBoolean
()
?
-
1
:
1
;
}
return
a
;
}
@Override
public
void
learn
(
HashMap
<
String
,
Double
>
state
,
HashMap
<
String
,
Double
>
state2
,
HashMap
<
String
,
Double
>
action
,
boolean
done
)
{
HashMap
<
String
,
Double
>
state2Copy
=
new
HashMap
<>(
state2
);
state2Copy
.
remove
(
"oracle"
);
double
reward
=
state2
.
get
(
"oracle"
);
double
q
;
if
(!
done
)
{
double
expectedReward
=
amoeba
.
request
(
action
);
double
futureAction
=
this
.
choose
(
state2Copy
);
q
=
reward
+
gamma
*
futureAction
-
expectedReward
;
}
else
{
q
=
reward
;
}
HashMap
<
String
,
Double
>
learn
=
new
HashMap
<>(
action
);
learn
.
put
(
"oracle"
,
lr
*
q
);
amoeba
.
learn
(
learn
);
}
}
/**
* Wrapper for AMOEBA
* @author Hugo
*
*/
public
static
class
Amoeba
implements
LearningAgent
{
public
static
class
Amoeba
Coop
implements
LearningAgent
{
public
AMOEBA
amoeba
;
private
Random
rand
=
new
Random
();
public
Amoeba
()
{
public
Amoeba
Coop
()
{
amoeba
=
setup
();
amoeba
.
setLocalModel
(
TypeLocalModel
.
COOP_MILLER_REGRESSION
);
amoeba
.
getEnvironment
().
setMappingErrorAllowed
(
0.009
);
...
...
@@ -139,7 +182,7 @@ public class SimpleReinforcement {
//poc(true);
//Configuration.commandLineMode = true;
System
.
out
.
println
(
"----- AMOEBA -----"
);
learning
(
new
Amoeba
());
learning
(
new
Amoeba
QL
());
System
.
out
.
println
(
"----- END AMOEBA -----"
);
/*System.out.println("\n\n----- QLEARNING -----");
learning(new QLearning());
...
...
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