Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lab5
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tddc17-coolkidz
lab5
Commits
6fb04eef
Commit
6fb04eef
authored
5 years ago
by
nambh713
Browse files
Options
Downloads
Patches
Plain Diff
added comments again
parent
e173a575
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
QLearning/bin/StateAndReward.class
+0
-0
0 additions, 0 deletions
QLearning/bin/StateAndReward.class
QLearning/src/StateAndReward.java
+7
-3
7 additions, 3 deletions
QLearning/src/StateAndReward.java
with
7 additions
and
3 deletions
QLearning/bin/StateAndReward.class
+
0
−
0
View file @
6fb04eef
No preview for this file type
This diff is collapsed.
Click to expand it.
QLearning/src/StateAndReward.java
+
7
−
3
View file @
6fb04eef
...
@@ -12,6 +12,7 @@ public class StateAndReward {
...
@@ -12,6 +12,7 @@ public class StateAndReward {
//State 3 is veering right
//State 3 is veering right
//State 1,2 is quite good as it is within Pi/8 angle from normal
//State 1,2 is quite good as it is within Pi/8 angle from normal
//state = String.valueOf(angle);
//state = String.valueOf(angle);
//concate _S to make the state more readable in terminal
return
state
.
concat
(
"_S"
);
return
state
.
concat
(
"_S"
);
}
}
...
@@ -24,7 +25,7 @@ public class StateAndReward {
...
@@ -24,7 +25,7 @@ public class StateAndReward {
int
state
=
discretize
(
angle
,
4
,
-
3.14
/
8
,
3.14
/
8
);
int
state
=
discretize
(
angle
,
4
,
-
3.14
/
8
,
3.14
/
8
);
//if state is 1 or 2, reward with positives
//if state is 1 or 2, reward with positives
//else
-5
//else
penalize
switch
(
state
)
{
switch
(
state
)
{
case
1
:
case
1
:
case
2
:
case
2
:
...
@@ -48,7 +49,10 @@ public class StateAndReward {
...
@@ -48,7 +49,10 @@ public class StateAndReward {
String
state
=
"OneStateToRuleThemAll2"
;
String
state
=
"OneStateToRuleThemAll2"
;
String
angle_state
=
String
.
valueOf
(
discretize
(
angle
,
5
,
-
3.14
/
8
,
3.14
/
8
));
String
angle_state
=
String
.
valueOf
(
discretize
(
angle
,
5
,
-
3.14
/
8
,
3.14
/
8
));
String
vy_state
=
String
.
valueOf
(
discretize
(
vy
,
5
,
-
1
,
1
))
;
String
vy_state
=
String
.
valueOf
(
discretize
(
vy
,
5
,
-
1
,
1
))
;
//add extra emphasis on value of vy being very close to 0
//but do not penalize if it cannot reach such value
String
vy_state_acc
=
String
.
valueOf
(
discretize
(
vy
,
3
,
-
0.1
,
0.1
));
String
vy_state_acc
=
String
.
valueOf
(
discretize
(
vy
,
3
,
-
0.1
,
0.1
));
//small emphasis on vx because having the angle be upright already compensate for vx
String
vx_state
=
String
.
valueOf
(
discretize
(
vx
,
3
,
-
0.5
,
0.5
));
String
vx_state
=
String
.
valueOf
(
discretize
(
vx
,
3
,
-
0.5
,
0.5
));
state
=
angle_state
+
"_"
+
vy_state
+
"_"
+
vy_state_acc
+
"_"
+
vx_state
;
state
=
angle_state
+
"_"
+
vy_state
+
"_"
+
vy_state_acc
+
"_"
+
vx_state
;
return
state
;
return
state
;
...
@@ -57,12 +61,12 @@ public class StateAndReward {
...
@@ -57,12 +61,12 @@ public class StateAndReward {
/* Reward function for the full hover controller */
/* Reward function for the full hover controller */
public
static
double
getRewardHover
(
double
angle
,
double
vx
,
double
vy
)
{
public
static
double
getRewardHover
(
double
angle
,
double
vx
,
double
vy
)
{
/* TODO: IMPLEMENT THIS FUNCTION */
double
reward
=
0
;
double
reward
=
0
;
String
state
=
getStateHover
(
angle
,
vx
,
vy
);
String
state
=
getStateHover
(
angle
,
vx
,
vy
);
//Separate state to its component
String
[]
state_str
=
state
.
split
(
"_"
);
String
[]
state_str
=
state
.
split
(
"_"
);
int
[]
state_int
=
new
int
[
state_str
.
length
];
int
[]
state_int
=
new
int
[
state_str
.
length
];
//Cast the strings to int for each comparison
for
(
int
i
=
0
;
i
<
state_int
.
length
;
i
++){
for
(
int
i
=
0
;
i
<
state_int
.
length
;
i
++){
state_int
[
i
]
=
Integer
.
valueOf
(
state_str
[
i
]);
state_int
[
i
]
=
Integer
.
valueOf
(
state_str
[
i
]);
}
}
...
...
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