Exemplo n.º 1
0
 def genValMap(self) -> None:
     """
     Generate `valmap` by inverting `nummap`.
     """
     if self.nummap is None:
         self.valmap = None
     else:
         self.valmap = {hashable_val(val): num for num, val in self.nummap.items()}
Exemplo n.º 2
0
 def mapVal(self) -> None:
     """
     Map the output value to a number or array of numbers.
     """
     if self.valmap is None:
         self.num = np.array(self.val)
     elif self.isscalar:
         self.num = np.array(self.valmap[hashable_val(self.val)])
     else:
         num = np.array(self.val, dtype='object')
         if len(self.shape) == 1:
             for i in range(self.shape[0]):
                 num[i] = self.valmap[hashable_val(self.val[i])]
         else:
             for i in range(self.shape[0]):
                 for j in range(self.shape[1]):
                     num[i][j] = self.valmap[hashable_val(self.val[i][j])]
         self.num = np.array(num, dtype='float')
Exemplo n.º 3
0
 def genNumMap(self) -> None:
     """
     Invert the valmap to get a nummap.
     """
     if self.valmap is None:
         self.nummap = None
     else:
         self.nummap = {
             hashable_val(np.array(num)): val
             for val, num in self.valmap.items()
         }
Exemplo n.º 4
0
 def extractValMap(self) -> None:
     """
     Parse the output value and extract a valmap.
     """
     vals_flattened = flatten([self.val])
     if all((isinstance(x, bool) or isinstance(x, np.bool_))
            for x in vals_flattened):
         self.valmap = {True: 1, False: 0}
     elif any(not is_num(x) for x in vals_flattened):
         sorted_vals = sorted(set(hashable_val(x) for x in vals_flattened))
         self.valmap = {val: idx for idx, val in enumerate(sorted_vals)}
Exemplo n.º 5
0
 def genValMap(self) -> None:
     """
     Generate the valmap based on the nummap.
     """
     if self.nummap is None:
         self.valmap = None
     else:
         self.valmap = {
             hashable_val(val): num
             for num, val in self.nummap.items()
         }