You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

bddkb.py 2.0 kB

3 months ago
3 months ago
3 months ago
3 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # -*- coding: utf-8 -*-
  2. from ablkit.reasoning import KBBase
  3. class BDDKB(KBBase):
  4. def __init__(self, pseudo_label_list=None):
  5. if pseudo_label_list is None:
  6. pseudo_label_list = [0, 1]
  7. super().__init__(pseudo_label_list)
  8. def logic_forward(self, attrs):
  9. """
  10. Abduction space
  11. (0, 1, 0, 0) 610812
  12. (0, 1, 0, 1) 75012
  13. (0, 1, 1, 0) 75012
  14. (0, 1, 1, 1) 9212
  15. (1, 0, 0, 0) 12996
  16. (1, 0, 0, 1) 1596
  17. (1, 0, 1, 0) 1596
  18. (1, 0, 1, 1) 196
  19. """
  20. assert len(attrs) == 21
  21. (
  22. green_light,
  23. follow,
  24. road_clear,
  25. red_light,
  26. traffic_sign,
  27. car,
  28. person,
  29. rider,
  30. other_obstacle,
  31. left_lane,
  32. left_green_light,
  33. left_follow,
  34. no_left_lane,
  35. left_obstacle,
  36. left_solid_line,
  37. right_lane,
  38. right_green_light,
  39. right_follow,
  40. no_right_lane,
  41. right_obstacle,
  42. right_solid_line,
  43. ) = attrs
  44. illegal_return = (0, 0, 0, 0)
  45. if red_light == green_light == 1:
  46. return illegal_return
  47. obstacle = car or person or rider or other_obstacle
  48. if road_clear == obstacle:
  49. return illegal_return
  50. move_forward = green_light or follow or road_clear
  51. stop = red_light or traffic_sign or obstacle
  52. if stop:
  53. move_forward = 0
  54. can_turn_left = left_lane or left_green_light or left_follow
  55. cannot_turn_left = no_left_lane or left_obstacle or left_solid_line
  56. turn_left = can_turn_left and int(not cannot_turn_left)
  57. can_turn_right = right_lane or right_green_light or right_follow
  58. cannot_turn_right = no_right_lane or right_obstacle or right_solid_line
  59. turn_right = can_turn_right and int(not cannot_turn_right)
  60. return move_forward, stop, turn_left, turn_right

An efficient Python toolkit for Abductive Learning (ABL), a novel paradigm that integrates machine learning and logical reasoning in a unified framework.