MCPcopy Create free account
hub / github.com/BindsNET/bindsnet / compute_reward

Method compute_reward

bindsnet/environment/dot_simulator.py:364–425  ·  view source on GitHub ↗

Computes reward according to the chosen fitness function. Returns reward and flag indicating a successful intercept.

(self)

Source from the content-addressed store, hash-verified

362 )
363
364 def compute_reward(self):
365 """
366 Computes reward according to the chosen fitness function.
367 Returns reward and flag indicating a successful intercept.
368 """
369 # Add bull's eye reward (if we're using it)
370 if (
371 self.bullseye != 0
372 and self.dots[0].row[0] == self.netDot.row[0]
373 and self.dots[0].col[0] == self.netDot.col[0]
374 ):
375 return self.bullseye, True
376
377 reward = 0.0
378
379 # Euclidean distance
380 if self.fit_func == 0:
381 reward = -np.hypot(
382 self.dots[0].row[0] - self.netDot.row[0],
383 self.dots[0].col[0] - self.netDot.col[0],
384 )
385
386 # Displacement tensor
387 elif self.fit_func == 1:
388 reward = torch.Tensor(
389 [
390 self.dots[0].row[0] - self.netDot.row[0],
391 self.dots[0].col[0] - self.netDot.col[0],
392 ]
393 )
394
395 # Range rings; default range ring size = 2
396 elif self.fit_func == 2:
397 reward = (
398 -np.hypot(
399 self.dots[0].row[0] - self.netDot.row[0],
400 self.dots[0].col[0] - self.netDot.col[0],
401 )
402 // self.ring_size
403 )
404
405 # Directional
406 elif self.fit_func == 3:
407 rd1 = abs(self.dots[0].row[0] - self.prevRow)
408 rd2 = abs(self.dots[0].row[0] - self.netDot.row[0])
409 cd1 = abs(self.dots[0].col[0] - self.prevCol)
410 cd2 = abs(self.dots[0].col[0] - self.netDot.col[0])
411
412 if rd2 < rd1:
413 reward += 1.0 # right row movement
414 elif rd1 < rd2:
415 reward -= 1.0 # wrong row movement
416 if cd2 < cd1:
417 reward += 1.0 # right col movement
418 elif cd1 < cd2:
419 reward -= 1.0 # wrong col movement
420
421 # Woops

Callers 1

stepMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected