Skip to content

Commit fab631f

Browse files
committed
Edit: update linear interpolation method
Signed-off-by: George Giovanis <[email protected]>
1 parent 0baa658 commit fab631f

File tree

2 files changed

+372
-373
lines changed

2 files changed

+372
-373
lines changed

user_definer_3D_Q.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import numpy as np
2+
import math
3+
import os
4+
5+
_bounds = np.array([[-5.0, 5.0],[-5.0, 5.0],[-3.1415, 3.1415]])
6+
_ptsEachDim = np.array([25, 25, 9, 81])
7+
_goal = np.array([[3.5, 3.5], [1.5707, 2.3562]])
8+
9+
# set _actions based on ranges and number of steps
10+
# format: range(lower bound, upper bound, number of steps)
11+
vValues = np.linspace(-2, 2, 9)
12+
wValues = np.linspace(-1, 1, 9)
13+
_actions = []
14+
for i in vValues:
15+
for j in wValues:
16+
_actions.append((i,j))
17+
_actions = np.array(_actions)
18+
19+
_gamma = np.array([0.93])
20+
_epsilon = np.array([.3])
21+
_maxIters = np.array([500])
22+
_trans = np.zeros([1, 4]) # size: [maximum number of transition states available x 4]
23+
_useNN = np.array([0])
24+
_fillVal = np.array([-400]) # Fill Value for linear interpolation
25+
26+
# Write results to file
27+
def writeResults(V, dir_path, file_name, just_values=False):
28+
# Create directory for results if one does not exist
29+
print("\nRecording results")
30+
try:
31+
os.mkdir(dir_path)
32+
print("Created directory: ", dir_path)
33+
except:
34+
print("Writing to: '", dir_path, "'")
35+
# Open file and write results
36+
f = open(dir_path + file_name, "w")
37+
for k in range(V.shape[2]):
38+
for i in range(V.shape[0]):
39+
for j in range(V.shape[1]):
40+
s = ""
41+
if not just_values:
42+
si = (( i / (_ptsEachDim[0] - 1) ) * (_bounds[0,1] - _bounds[0,0])) + _bounds[0,0]
43+
sj = (( j / (_ptsEachDim[1] - 1) ) * (_bounds[1,1] - _bounds[1,0])) + _bounds[1,0]
44+
sk = (( k / (_ptsEachDim[2] - 1) ) * (_bounds[2,1] - _bounds[2,0])) + _bounds[2,0]
45+
state = ("{:.4f}".format(si), "{:.4f}".format(sj), "{:.4f}".format(sk))
46+
s = str(state) + " " + str(max(V[(i,j,k)])) + '\n'
47+
else:
48+
s = str("{:.4f}".format(max(V[(i,j,k)]))) + ',\n'
49+
f.write(s)
50+
print("Finished recording results")

0 commit comments

Comments
 (0)