Infernce.
        
        Args:
            state_arr:    `np.ndarray` of state.
            limit:        The number of inferencing.
        
        Returns:
            `list of `np.ndarray` of an optimal route.
16402
def inference(self, state_arr, limit=1000):
        '''
        
        '''
        self.__inferencing_flag = True

        agent_x, agent_y = np.where(state_arr[0] == 1)
        agent_x, agent_y = agent_x[0], agent_y[0]
        self.__create_enemy(self.__map_arr)
        result_list = [(agent_x, agent_y, 0.0)]
        result_val_list = [agent_x, agent_y]
        for e in range(self.__enemy_num):
            result_val_list.append(self.__enemy_pos_list[e][0])
            result_val_list.append(self.__enemy_pos_list[e][1])
        result_val_list.append(0.0)
        result_list.append(tuple(result_val_list))

        self.t = 0
        while self.t < limit:
            next_action_arr = self.extract_possible_actions(state_arr)
            next_q_arr = self.function_approximator.inference_q(next_action_arr)
            action_arr, q = self.select_action(next_action_arr, next_q_arr)
            self.__move_enemy(action_arr)

            agent_x, agent_y = np.where(action_arr[0] == 1)
            agent_x, agent_y = agent_x[0], agent_y[0]
            
            result_val_list = [agent_x, agent_y]
            for e in range(self.__enemy_num):
                result_val_list.append(self.__enemy_pos_list[e][0])
                result_val_list.append(self.__enemy_pos_list[e][1])
            try:
                result_val_list.append(q[0])
            except IndexError:
                result_val_list.append(q)

            result_list.append(tuple(result_val_list))

            # Update State.
            state_arr = self.update_state(state_arr, action_arr)

            # Epsode.
            self.t += 1
            # Check.
            end_flag = self.check_the_end_flag(state_arr)
            if end_flag is True:
                break

        return result_list
854019
def update_state(self, state_arr, action_arr):
        '''
        
        '''
        x, y = np.where(action_arr[-1] == 1)
        self.__agent_pos = (x[0], y[0])
        self.__route_memory_list.append((x[0], y[0]))
        self.__route_long_memory_list.append((x[0], y[0]))
        self.__route_long_memory_list = list(set(self.__route_long_memory_list))
        while len(self.__route_memory_list) > self.__memory_num:
            self.__route_memory_list = self.__route_memory_list[1:]

        return self.extract_now_state()
1082002
def p_state_invariant_list(self, p):
        ''''''
        if len(p) == 3:
            p[1].append(p[2])
            p[0] = p[1]
        elif len(p) == 2:
            p[0] = [p[1]]
554152
def ffill(arr, dim=None, limit=None):
    ''''''
    import bottleneck as bn

    axis = arr.get_axis_num(dim)

    # work around for bottleneck 178
    _limit = limit if limit is not None else arr.shape[axis]

    return apply_ufunc(bn.push, arr,
                       dask='parallelized',
                       keep_attrs=True,
                       output_dtypes=[arr.dtype],
                       kwargs=dict(n=_limit, axis=axis)).transpose(*arr.dims)
1204599
def state_full(self):
        
    
        if self.is_valid_state:
            return STATES[self.country.upper()].get(self.state.upper())
819263
def p_state_cons_list(self, p):
        ''''''
        if len(p) == 3:
            p[1].append(p[2])
            p[0] = p[1]
        elif len(p) == 2:
            p[0] = [p[1]]
34483
function(state,statePointer,nbr,isInv)
		{
			for (var i = 0; i < nbr; i++)
			{
				if(isInv)
				{
					var tmp = state[statePointer + 3];
					for (var j = 3; j > 0; j--)
						state[statePointer + j] = state[statePointer + j-1];
					state[statePointer] = tmp;
				}
				else
				{
					var tmp = state[statePointer];
					for (var j = 0; j < 3; j++)
						state[statePointer + j] = state[statePointer + j+1];
					state[statePointer + 3] = tmp;
				}
			}
			return state;
		}
884501
def get_next_state(self, state, ret, oper):
        
        if oper == fw_const.FW_CR_OP:
            return self.get_next_create_state(state, ret)
        else:
            return self.get_next_del_state(state, ret)
1317224
def npArrInfo(arr):
    
    from utool.DynamicStruct import DynStruct
    info = DynStruct()
    info.shapestr  = '[' + ' x '.join([str(x) for x in arr.shape]) + ']'
    info.dtypestr  = str(arr.dtype)
    if info.dtypestr == 'bool':
        info.bittotal = 'T=%d, F=%d' % (sum(arr), sum(1 - arr))
    elif info.dtypestr == 'object':
        info.minmaxstr = 'NA'
    elif info.dtypestr[0] == '|':
        info.minmaxstr = 'NA'
    else:
        if arr.size > 0:
            info.minmaxstr = '(%r, %r)' % (arr.min(), arr.max())
        else:
            info.minmaxstr = '(None)'
    return info
657357
def states(self, states):
        
        # First safely remove all existing states (recursively!), as they will be replaced
        state_ids = list(self.states.keys())
        for state_id in state_ids:
            # Do not remove decider state, if teh new list of states doesn't contain an alternative one
            if state_id == UNIQUE_DECIDER_STATE_ID and UNIQUE_DECIDER_STATE_ID not in states:
                continue
            self.remove_state(state_id)
        if states is not None:
            if not isinstance(states, dict):
                raise TypeError("states must be of type dict")
            # Ensure that the decider state is added first, as transition to this states will automatically be
            # created when adding further states
            decider_state = states.pop(UNIQUE_DECIDER_STATE_ID, None)
            if decider_state is not None:
                self.add_state(decider_state)
            for state in states.values():
                self.add_state(state)
1371820
def state_dict(self) -> Dict[str, Any]:
        
        return {key: value for key, value in self.__dict__.items() if key != 'optimizer'}
1065244
def forward_state(self, sequence, state=None):
        
        if state is None:
            state = self.zero_state(sequence.size(0))

        data = self.input_block(sequence)

        state_outputs = []

        # for layer_length, layer in zip(self.hidden_layers, self.recurrent_layers):
        for idx in range(len(self.recurrent_layers)):
            layer_length = self.recurrent_layers[idx].state_dim

            # Partition hidden state, for each layer we have layer_length of h state and layer_length of c state
            current_state = state[:, :, :layer_length]
            state = state[:, :, layer_length:]

            # Propagate through the GRU state
            data, new_h = self.recurrent_layers[idx](data, current_state)

            if self.dropout_layers:
                data = self.dropout_layers[idx](data)

            state_outputs.append(new_h)

        output_data = self.output_activation(self.output_layer(data))

        concatenated_hidden_output = torch.cat(state_outputs, dim=2)

        return output_data, concatenated_hidden_output
926889
def getStateIndex(self,state):
        
        statecodes = self.getStateCode(state)
        return np.searchsorted(self.codes,statecodes).astype(int)
488111
def limit(self, limit):
    
    params = join_params(self.parameters, {"limit": limit})

    return self.__class__(**params)
95956
def actions(self, state):
        ''''''
        rows = string_to_list(state)
        row_e, col_e = find_location(rows, 'e')

        actions = []
        if row_e > 0:
            actions.append(rows[row_e - 1][col_e])
        if row_e < 2:
            actions.append(rows[row_e + 1][col_e])
        if col_e > 0:
            actions.append(rows[row_e][col_e - 1])
        if col_e < 2:
            actions.append(rows[row_e][col_e + 1])

        return actions
1101675
def _states(self, state, processedstates=[]): #pylint: disable=dangerous-default-value
        """"""
        processedstates.append(state)

        for nextstate in state.epsilon:
            if not nextstate in processedstates:
                self._states(nextstate, processedstates)

        for _, nextstate in state.transitions:
            if not nextstate in processedstates:
                self._states(nextstate, processedstates)

        return processedstates
661070
def getSensors(self):
        
        Pd = array([b.p_demand for b in self.case.buses if b.type == PQ])
        logger.info("State: %s" % list(Pd))
        return Pd