Skip to content

Commit

Permalink
added Phase-2 code
Browse files Browse the repository at this point in the history
  • Loading branch information
PranavNyati committed Jan 7, 2024
1 parent 085e33a commit f5dd2b4
Show file tree
Hide file tree
Showing 213 changed files with 26,434 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
############################
DDQN-CONFIGS AND HYPERPARAMS
############################

# define all the configurations and parameters here
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
learning_rate = 5e-4
buffer_size = int(1e5)
batch_size = 64
discount_factor = 0.99
update_target_freq = 5
tau = 1e-3
epsilon_start = 0.2
epsilon_end = 0.0002
epsilon_decay_rate = 1e-6
hidden_dim1 = 64
hidden_dim2 = 64
max_t = 6000 # maximum number of timesteps per episode
max_episodes = 300 # maximum number of episodes to train the agent
save_logs_freq = 25 # save logs after every save_logs_freq episodes
save_model_ckpts_freq = 25 # save model checkpoints after every save_model_ckpts_freq episodes
train_stats_print_freq = 5 # print training statistics after every train_stats_print_freq episodes
save_model_path = './train_logs/model_checkpoints/'
save_logs_path = './train_logs/logs/'



######################
ENVIRONMENT-CONFIGS
######################

# Circular path parameters
self.center = (self.window_size[0] // 2, self.window_size[1] // 2 - 50)
self.radius = 380
self.path_thickness = 80
self.no_path_radius = 180
self.no_path_outer_radius = self.radius + self.path_thickness + 20

# Stochastic wind parameters
self.wind_mean_x = 0.3
self.wind_variance_x = 0.05
self.wind_speed_x = np.random.normal(self.wind_mean_x, self.wind_variance_x)

self.wind_mean_y = 0.3
self.wind_variance_y = 0.05
self.wind_speed_y = np.random.normal(self.wind_mean_y, self.wind_variance_y)

# Car parameters
self.car_length = 30
self.car_width = 20
self.car_speed = 1.2
self.car_angle = math.pi / 2 # Start facing upward
self.car_x, self.car_y = self.center[0] + self.radius - (self.path_thickness//2), self.center[1]
self.start_pos_x, self.start_pos_y = self.car_x, self.car_y
self.half_lap = False
self.three_quarter_lap = False

# Radar parameters
self.num_rays = 5
self.ray_lengths = np.array([50, 60, 70, 60, 50])
self.ray_angles = np.array([-math.pi / 4, -math.pi / 8, 0, math.pi / 8, math.pi / 4])
self.ray_values = np.array([0] * self.num_rays) # Store radar ray values (1, -1, or 0)
self.ray_x = np.array([0] * self.num_rays)
self.ray_y = np.array([0] * self.num_rays)

# State parameters and action space
self.state_dim = self.num_rays + 3
self.action_dim = 3

# Rewards and score
self.reward_inside_path = 2
self.reward_outside_path = -15
self.score = 0
self.time_penalty = -1
self.angle_change_penalty = -10
self.goal_reward = 5000
self.three_quarter_lap_reward = 1500
self.no_access_hit_penalty = -200
self.obstacle_sense_penalty = -5
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
Episode,Loss
0,46.97676086425781
1,350.78729248046875
2,246.4852294921875
3,89.11424255371094
4,35061.25
5,755.3390502929688
6,1053.97509765625
7,1186.527099609375
8,182.76678466796875
9,617.65234375
10,968.5218505859375
11,2013.9727783203125
12,276.64483642578125
13,1139.0655517578125
14,784.6294555664062
15,705.278076171875
16,1086.9947509765625
17,236.15655517578125
18,210.43490600585938
19,582.9960327148438
20,1660.1112060546875
21,285.4600830078125
22,1001.1182861328125
23,658.727783203125
24,470.072265625
25,1727.394775390625
26,1044.6287841796875
27,336.47442626953125
28,2500.18310546875
29,1244.27734375
30,2103.3955078125
31,819.7290649414062
32,875.4436645507812
33,1124.598388671875
34,1243.79052734375
35,1880.600341796875
36,289.2767333984375
37,2439.1484375
38,401.39886474609375
39,194.1799774169922
40,1163.352783203125
41,505.58441162109375
42,386471.65625
43,206.86944580078125
44,342.10968017578125
45,1325.816650390625
46,410.22174072265625
47,1020.5517578125
48,605.8984985351562
49,1357.3321533203125
50,1886.571044921875
51,210.90013122558594
52,211.42311096191406
53,203.08203125
54,682.6439208984375
55,1682.65380859375
56,192.31179809570312
57,353.06134033203125
58,902.114501953125
59,639.5557250976562
60,655.00537109375
61,329.2009582519531
62,187.648193359375
63,108.52923583984375
64,113.84822082519531
65,798.8270263671875
66,213.05551147460938
67,1095.076171875
68,317.6368408203125
69,438.614501953125
70,57.4990234375
71,380.6076354980469
72,66.27198028564453
73,1677.48828125
74,2813.37646484375
75,471.6524658203125
76,1249.3409423828125
77,229.22091674804688
78,86.7664794921875
79,685.968994140625
80,1340.06201171875
81,89.82808685302734
82,275.87225341796875
83,1064.884033203125
84,213.00741577148438
85,740.108154296875
86,410.486328125
87,1077.50341796875
88,152.51947021484375
89,885.6062622070312
90,120.05599212646484
91,212.05149841308594
92,1128.4677734375
93,179.73696899414062
94,729.4700927734375
95,624.5028076171875
96,87.45598602294922
97,613.9696655273438
98,465.77850341796875
99,1176.76953125
100,1713.817138671875
101,109.18904113769531
102,484.53125
103,223.00367736816406
104,184.12435913085938
105,172.3700408935547
106,87.6129379272461
107,364.3734130859375
108,508.0361328125
109,77.96926879882812
110,116.11329650878906
111,266.626220703125
112,202.28152465820312
113,376.0977783203125
114,127.93818664550781
115,838.083984375
116,66.45230102539062
117,247.91183471679688
118,424.33404541015625
119,217.76974487304688
120,1662.1240234375
121,748.4871215820312
122,102.93913269042969
123,4314.5400390625
124,204.0469512939453
125,109.38993835449219
126,35079.82421875
127,1404.8218994140625
128,952.2924194335938
129,725.766357421875
130,901.718505859375
131,327.2513732910156
132,767.4285888671875
133,619.0957641601562
134,927.028564453125
135,347.1879577636719
136,232.33673095703125
137,222.27906799316406
138,82.94300842285156
139,144.34622192382812
140,179.94741821289062
141,221.91943359375
142,661.9664306640625
143,839.4801635742188
144,964.8612060546875
145,919.7672729492188
146,98.85664367675781
147,3154.924072265625
148,737.999755859375
149,113.01490783691406
150,4807.203125
151,469.78363037109375
152,416.414794921875
153,363.02398681640625
154,247.61309814453125
155,297.6471252441406
156,150.1171417236328
157,573.760986328125
158,188.0963134765625
159,305.11083984375
160,469.571044921875
161,1141.966552734375
162,282.51947021484375
163,640.5198974609375
164,251.78041076660156
165,3304.4404296875
166,324.857666015625
167,1349.5191650390625
168,337.8106689453125
169,788.873779296875
170,34615.78125
171,1620.6519775390625
172,3106.46435546875
173,443.064453125
174,558.744140625
175,2997.193115234375
176,96.51470184326172
177,2576.751953125
178,300.2566223144531
179,476.29315185546875
180,502.770751953125
181,54234.55078125
182,492.4431457519531
183,829.4091796875
184,3383.392578125
185,151.7763214111328
186,2096.01904296875
187,212.9459991455078
188,3276.21142578125
189,1330.978759765625
190,1938.218505859375
191,413.1387939453125
192,480.37872314453125
193,418.84039306640625
194,805.3323364257812
195,464.34356689453125
196,2148.400390625
197,602.6488647460938
198,417.49365234375
199,2744.437255859375
200,69.17740631103516
201,7419.19189453125
202,259.41253662109375
203,236.95880126953125
204,1396.227783203125
205,560.71240234375
206,676.3497314453125
207,1341.9593505859375
208,383.1351318359375
209,508.0167236328125
210,693.378173828125
211,442.42578125
212,317.98101806640625
213,253.62765502929688
214,603.0238037109375
215,1498.3974609375
216,2047.898193359375
217,1206.361083984375
218,854.2302856445312
219,1257.2398681640625
220,876.58642578125
221,468.96343994140625
222,287.5798034667969
223,1048.658935546875
224,3740.224609375
225,380.68096923828125
226,1930.039794921875
227,945.2046508789062
228,870.4012451171875
229,207.75
230,1282.3114013671875
231,170.57391357421875
232,34035.11328125
233,824.1802978515625
234,1321.4935302734375
235,544.4994506835938
236,418.048828125
237,245.936767578125
238,288.75482177734375
239,376.4176940917969
240,396.01513671875
241,421.2037048339844
242,1241.68505859375
243,581.6722412109375
244,1282.613525390625
245,1006.0900268554688
246,600.6984252929688
247,398.2529296875
248,35698.90234375
249,1157.1995849609375
250,773.305908203125
251,552.0653686523438
252,1699.5013427734375
253,283.8804626464844
254,562.9462280273438
255,667.875
256,466.95709228515625
257,399.7000732421875
258,474.777099609375
259,1725.865966796875
260,310.0705871582031
261,199.14935302734375
262,338.11907958984375
263,308.2383117675781
264,405.7358703613281
265,680.1403198242188
266,119.51339721679688
267,197.7222900390625
268,538.3505859375
269,612.3535766601562
270,2835.82861328125
271,2891.37548828125
272,461.57391357421875
273,609.6471557617188
274,229.94732666015625
275,3409.61181640625
276,37065.28515625
277,999.9266357421875
278,27983.87890625
279,301.8092346191406
280,1595.364990234375
281,838.091064453125
282,3710.05224609375
283,1089.48046875
284,1759.3096923828125
285,1162.30322265625
286,444.10955810546875
287,3477.90234375
288,1392.64013671875
289,829.9650268554688
290,442.4349060058594
291,140.54620361328125
292,1919.3917236328125
293,510.51446533203125
294,2170.2197265625
295,1404.8033447265625
296,311.72698974609375
297,440.96160888671875
298,587.8609619140625
299,483.2724914550781
Loading

0 comments on commit f5dd2b4

Please sign in to comment.