MCPcopy Create free account
hub / github.com/BIT-MCS/DRL-eFresh / spatial_att_feed_forward_generator

Method spatial_att_feed_forward_generator

storage.py:205–281  ·  view source on GitHub ↗
(self, advantages)

Source from the content-addressed store, hash-verified

203 temporal_hidden_states
204
205 def spatial_att_feed_forward_generator(self, advantages):
206 # mini_batch_size = (self.num_steps- params.rnn_seq_len) // self.mini_batch_num # 500-5/4
207 mini_batch_size = params.batch_size
208 sampler = BatchSampler(SubsetRandomSampler(range(self.num_steps - params.rnn_seq_len)), mini_batch_size,
209 drop_last=True)
210 T = params.rnn_seq_len
211 N = mini_batch_size
212 for indices in sampler:
213 obs_batch = self.obs[indices]
214 uav_aoi_batch = self.uav_aoi[indices]
215 uav_snr_batch = self.uav_snr[indices]
216 uav_tuse_batch = self.uav_tuse[indices]
217 uav_effort_batch = self.uav_effort[indices]
218 action_dia_batch = self.action_dia[indices]
219 value_pred_batch = self.value_preds[indices]
220 return_batch = self.returns[indices]
221 old_action_log_probs_batch = self.action_log_probs[indices]
222 advantages_batch = advantages[indices]
223 masks_batch = self.masks[indices]
224 temporal_hidden_states = self.temporal_hidden_states[indices]
225 spatial_hidden_states=self.spatial_hidden_states[indices]
226 sample_index = np.array(indices)
227 for t in range(1, params.rnn_seq_len):
228 cur_index = sample_index + t
229 cur_index = cur_index.tolist()
230 obs_batch_i = self.obs[cur_index]
231 uav_aoi_batch_i = self.uav_aoi[cur_index]
232 uav_snr_batch_i = self.uav_snr[cur_index]
233 uav_tuse_batch_i = self.uav_tuse[cur_index]
234 uav_effort_batch_i = self.uav_effort[cur_index]
235 action_dia_batch_i = self.action_dia[cur_index]
236 value_pred_batch_i = self.value_preds[cur_index]
237 return_batch_i = self.returns[cur_index]
238 old_action_log_probs_batch_i = self.action_log_probs[cur_index]
239 advantages_batch_i = advantages[cur_index]
240 masks_batch_i = self.masks[cur_index]
241 if t == 1:
242 obs_batch = torch.stack((obs_batch, obs_batch_i))
243 uav_aoi_batch = torch.stack((uav_aoi_batch, uav_aoi_batch_i))
244 uav_snr_batch = torch.stack((uav_snr_batch, uav_snr_batch_i))
245 uav_tuse_batch = torch.stack((uav_tuse_batch, uav_tuse_batch_i))
246 uav_effort_batch = torch.stack((uav_effort_batch, uav_effort_batch_i))
247 action_dia_batch = torch.stack((action_dia_batch, action_dia_batch_i))
248 value_pred_batch = torch.stack((value_pred_batch, value_pred_batch_i))
249 return_batch = torch.stack((return_batch, return_batch_i))
250 old_action_log_probs_batch = torch.stack((old_action_log_probs_batch, old_action_log_probs_batch_i))
251 advantages_batch = torch.stack((advantages_batch, advantages_batch_i))
252 masks_batch = torch.stack((masks_batch, masks_batch_i))
253 else:
254 obs_batch = torch.cat((obs_batch, obs_batch_i.unsqueeze(0)), dim=0)
255 uav_aoi_batch = torch.cat((uav_aoi_batch, uav_aoi_batch_i.unsqueeze(0)), dim=0)
256 uav_snr_batch = torch.cat((uav_snr_batch, uav_snr_batch_i.unsqueeze(0)), dim=0)
257 uav_tuse_batch = torch.cat((uav_tuse_batch, uav_tuse_batch_i.unsqueeze(0)), dim=0)
258 uav_effort_batch = torch.cat((uav_effort_batch, uav_effort_batch_i.unsqueeze(0)), dim=0)
259 action_dia_batch = torch.cat((action_dia_batch, action_dia_batch_i.unsqueeze(0)), dim=0)
260 value_pred_batch = torch.cat((value_pred_batch, value_pred_batch_i.unsqueeze(0)), dim=0)
261 return_batch = torch.cat((return_batch, return_batch_i.unsqueeze(0)), dim=0)
262 old_action_log_probs_batch = torch.cat(

Callers 1

trainFunction · 0.95

Calls 1

_flatten_helperFunction · 0.85

Tested by

no test coverage detected