@@ -20,9 +20,9 @@ class UniqueImageData(Data):
2020
2121 def __init__ (
2222 self ,
23- imaged : Optional [list ["Target" ]] = None ,
23+ imaged : Optional [set ["Target" ]] = None ,
2424 duplicates : int = 0 ,
25- known : Optional [list ["Target" ]] = None ,
25+ known : Optional [set ["Target" ]] = None ,
2626 ) -> None :
2727 """Construct unit of data to record unique images.
2828
@@ -36,12 +36,12 @@ def __init__(
3636 known: List of targets that are known to exist (imaged and unimaged).
3737 """
3838 if imaged is None :
39- imaged = []
40- self .imaged = list ( set (imaged ) )
39+ imaged = set ()
40+ self .imaged = set (imaged )
4141 self .duplicates = duplicates + len (imaged ) - len (self .imaged )
4242 if known is None :
43- known = []
44- self .known = list ( set (known ) )
43+ known = set ()
44+ self .known = set (known )
4545
4646 def __add__ (self , other : "UniqueImageData" ) -> "UniqueImageData" :
4747 """Combine two units of data.
@@ -52,15 +52,15 @@ def __add__(self, other: "UniqueImageData") -> "UniqueImageData":
5252 Returns:
5353 Combined unit of data.
5454 """
55- imaged = list ( set ( self .imaged + other .imaged ))
55+ imaged = self .imaged | other .imaged
5656 duplicates = (
5757 self .duplicates
5858 + other .duplicates
5959 + len (self .imaged )
6060 + len (other .imaged )
6161 - len (imaged )
6262 )
63- known = list ( set ( self .known + other .known ))
63+ known = self .known | other .known
6464 return self .__class__ (imaged = imaged , duplicates = duplicates , known = known )
6565
6666
@@ -104,7 +104,7 @@ def compare_log_states(
104104 else :
105105 assert self .satellite .latest_target is not None
106106 self .update_target_colors ([self .satellite .latest_target ])
107- return UniqueImageData (imaged = [ self .satellite .latest_target ] )
107+ return UniqueImageData (imaged = { self .satellite .latest_target } )
108108
109109 @vizard .visualize
110110 def update_target_colors (self , targets , vizInstance = None , vizSupport = None ):
@@ -177,16 +177,16 @@ def calculate_reward(
177177 reward: Cumulative reward across satellites for one step
178178 """
179179 reward = {}
180- imaged_targets = sum (
181- [ new_data .imaged for new_data in new_data_dict .values ()], []
180+ imaged_targets = set (). union (
181+ * ( new_data .imaged for new_data in new_data_dict .values ())
182182 )
183183 for sat_id , new_data in new_data_dict .items ():
184184 reward [sat_id ] = 0.0
185185 for target in new_data .imaged :
186186 if target not in self .data .imaged :
187187 reward [sat_id ] += self .reward_fn (
188188 target .priority
189- ) / imaged_targets .count (target )
189+ ) # / imaged_targets.count(target). # TODO dont double award
190190
191191 return reward
192192
0 commit comments