Infernce Q-Value.
        
        Args:
            next_action_arr:     `np.ndarray` of action.
        
        Returns:
            `np.ndarray` of Q-Values.
323898
def inference_q(self, next_action_arr):
        '''
        
        '''
        q_arr = next_action_arr.reshape((next_action_arr.shape[0], -1))
        self.__q_arr_list.append(q_arr)
        while len(self.__q_arr_list) > self.__seq_len:
            self.__q_arr_list = self.__q_arr_list[1:]
        while len(self.__q_arr_list) < self.__seq_len:
            self.__q_arr_list.append(self.__q_arr_list[-1])

        q_arr = np.array(self.__q_arr_list)
        q_arr = q_arr.transpose((1, 0, 2))
        q_arr = self.__lstm_model.inference(q_arr)
        return q_arr[:, -1].reshape((q_arr.shape[0], 1))
1370289
def update_q(self, state_key, action_key, reward_value, next_max_q):
        '''
        

        '''
        # Now Q-Value.
        q = self.extract_q_df(state_key, action_key)
        # Update Q-Value.
        new_q = q + self.alpha_value * (reward_value + (self.gamma_value * next_max_q) - q)
        # Save updated Q-Value.
        self.save_q_df(state_key, action_key, new_q)
194440
def forward(self, observations, input_actions=None):
        
        observations = self.input_block(observations)

        if input_actions is not None:
            actions = input_actions

            value_input = torch.cat([observations, actions], dim=1)
            value_hidden = self.value_backbone(value_input)

            values = self.critic_head(value_hidden)
        else:
            policy_hidden = self.policy_backbone(observations)
            actions = self.action_head(policy_hidden)

            value_input = torch.cat([observations, actions], dim=1)
            value_hidden = self.value_backbone(value_input)

            values = self.critic_head(value_hidden)

        return actions, values
1039696
def _create_lookup(self, branched_action_space):
        
        possible_vals = [range(_num) for _num in branched_action_space]
        all_actions = [list(_action) for _action in itertools.product(*possible_vals)]
        # Dict should be faster than List for large action spaces
        action_lookup = {_scalar: _action for (_scalar, _action) in enumerate(all_actions)}
        return action_lookup
46486
def get_list_qtype(array):
    '''
    '''
    if not isinstance(array, numpy.ndarray):
        raise ValueError('array parameter is expected to be of type: numpy.ndarray, got: %s' % type(array))

    if isinstance(array, QList):
        return -abs(array.meta.qtype)

    qtype = None

    if str(array.dtype) in ('|S1', '<U1', '>U1', '|U1') :
        qtype = QCHAR

    if qtype is None:
        qtype = Q_TYPE.get(array.dtype.type, None)

    if qtype is None and array.dtype.type in (numpy.datetime64, numpy.timedelta64):
        qtype = TEMPORAL_PY_TYPE.get(str(array.dtype), None)

    if qtype is None:
        # determinate type based on first element of the numpy array
        qtype = Q_TYPE.get(type(array[0]), QGENERAL_LIST)

    return qtype
75247
def select_action(self, q_values):
        
        # We can't use BGE during testing, since we don't have access to the
        # action_counts at the end of training.
        assert self.agent.training, "BoltzmannGumbelQPolicy should only be used for training, not testing"

        assert q_values.ndim == 1, q_values.ndim
        q_values = q_values.astype('float64')

        # If we are starting training, we should reset the action_counts.
        # Otherwise, action_counts should already be initialized, since we
        # always do so when we begin training.
        if self.agent.step == 0:
            self.action_counts = np.ones(q_values.shape)
        assert self.action_counts is not None, self.agent.step
        assert self.action_counts.shape == q_values.shape, (self.action_counts.shape, q_values.shape)

        beta = self.C/np.sqrt(self.action_counts)
        Z = np.random.gumbel(size=q_values.shape)

        perturbation = beta * Z
        perturbed_q_values = q_values + perturbation
        action = np.argmax(perturbed_q_values)

        self.action_counts[action] += 1
        return action
668136
def get_next_action(self, request, application, label, roles):
        
        actions = self.get_actions(request, application, roles)
        if label is None and \
                'is_applicant' in roles and 'is_admin' not in roles:
            # applicant, admin, leader can reopen an application
            for action in actions:
                if action in request.POST:
                    return action
            return render(
                template_name='kgapplications/common_declined.html',
                context={
                    'application': application,
                    'actions': actions,
                    'roles': roles
                },
                request=request)
        return super(StateDeclined, self).get_next_action(
            request, application, label, roles)
1266143
def get_action(self, parent, undo_stack: QUndoStack, sel_range, protocol: ProtocolAnalyzer, view: int):
        
        min_row, max_row, start, end = sel_range
        if min_row == -1 or max_row == -1 or start == -1 or end == -1:
            return None

        if max_row != min_row:
            return None

        end = protocol.convert_index(end, view, 0, True, message_indx=min_row)[0]
        # factor = 1 if view == 0 else 4 if view == 1 else 8

        self.command = MessageBreakAction(protocol, max_row, end)
        action = QAction(self.command.text(), parent)
        action.triggered.connect(self.action_triggered)
        self.undo_stack = undo_stack
        return action
280943
def step(self, observation, argmax_sampling=False):
        
        action_pd_params, value_output = self(observation)
        actions = self.action_head.sample(action_pd_params, argmax_sampling=argmax_sampling)

        # log likelihood of selected action
        logprobs = self.action_head.logprob(actions, action_pd_params)

        return {
            'actions': actions,
            'values': value_output,
            'action:logprobs': logprobs
        }
895713
def observe_reward_value(self, state_arr, action_arr):
        '''
        
        '''
        if self.__check_goal_flag(action_arr) is True:
            return 1.0
        else:
            self.__move_enemy(action_arr)

            x, y = np.where(action_arr[-1] == 1)
            x, y = x[0], y[0]

            e_dist_sum = 0.0
            for e in range(self.__enemy_num):
                e_dist = np.sqrt(
                    ((x - self.__enemy_pos_list[e][0]) ** 2) + ((y - self.__enemy_pos_list[e][1]) ** 2)
                )
                e_dist_sum += e_dist

            e_dist_penalty = e_dist_sum / self.__enemy_num
            goal_x, goal_y = self.__goal_pos
            
            if x == goal_x and y == goal_y:
                distance = 0.0
            else:
                distance = np.sqrt(((x - goal_x) ** 2) + (y - goal_y) ** 2)

            if (x, y) in self.__route_long_memory_list:
                repeating_penalty = self.__repeating_penalty
            else:
                repeating_penalty = 0.0

            return 1.0 - distance - repeating_penalty + e_dist_penalty
464938
def _get_action(self, action):
        

        # If we don't have an action named that, bail out
        if action not in self.wsgi_actions:
            return None

        # Generate an ActionDescriptor if necessary
        if action not in self.wsgi_descriptors:
            self.wsgi_descriptors[action] = actions.ActionDescriptor(
                self.wsgi_actions[action],
                self.wsgi_extensions.get(action, []),
                self.wsgi_resp_type)

        # OK, return the method descriptor
        return self.wsgi_descriptors[action]
779716
def set_expected_action(self, expected_response_action):
        
        if expected_response_action.upper() not in ['APPROVED', 'APPROVE', 'DECLINED', 'DECLINE']:
            return False

        self.expected_response_action = expected_response_action.upper()
        return True
52220
def q(self, val):
        
        self._q = np.asarray(val)
        self.Q = cumsum(val)
654634
def _get_action(self, action_meta):
        '''
        
        '''
        conf = {
            'fun': list(action_meta.keys())[0],
            'arg': [],
            'kwargs': {},
        }
        if not len(conf['fun'].split('.')) - 1:
            conf['salt.int.intfunc'] = True

        action_meta = action_meta[conf['fun']]
        info = action_meta.get('info', 'Action for {}'.format(conf['fun']))
        for arg in action_meta.get('args') or []:
            if not isinstance(arg, dict):
                conf['arg'].append(arg)
            else:
                conf['kwargs'].update(arg)

        return info, action_meta.get('output'), conf
1111945
def get_limit_action(self, criticity, stat_name=""):
        
        # Get the action for stat + header
        # Exemple: network_wlan0_rx_careful_action
        # Action key available ?
        ret = [(stat_name + '_' + criticity + '_action', False),
               (stat_name + '_' + criticity + '_action_repeat', True),
               (self.plugin_name + '_' + criticity + '_action', False),
               (self.plugin_name + '_' + criticity + '_action_repeat', True)]
        for r in ret:
            if r[0] in self._limits:
                return self._limits[r[0]], r[1]

        # No key found, the raise an error
        raise KeyError
890316
def account_distance(A1, A2):
    
    return (sum([action.alpha for action in A1]) -
            sum([action.alpha for action in A2]))
594161
def learn(self, state_arr, limit=1000):
        '''
        
        '''
        while self.t <= limit:
            # Draw samples of next possible actions from any distribution.
            next_action_arr = self.extract_possible_actions(state_arr)
            # Inference Q-Values.
            predicted_q_arr = self.__function_approximator.inference_q(next_action_arr)
            # Set `np.ndarray` of rewards and next Q-Values.
            reward_value_arr = np.empty((next_action_arr.shape[0], 1))
            next_max_q_arr = np.empty((next_action_arr.shape[0], 1))
            for i in range(reward_value_arr.shape[0]):
                # Observe reward values.
                reward_value_arr[i] = self.observe_reward_value(state_arr, next_action_arr[i])
                # Inference the Max-Q-Value in next action time.
                next_next_action_arr = self.extract_possible_actions(next_action_arr[i])
                next_max_q_arr[i] = self.__function_approximator.inference_q(next_next_action_arr).max()

            # Select action.
            action_arr, predicted_q = self.select_action(next_action_arr, predicted_q_arr)
            # Update real Q-Values.
            real_q_arr = self.update_q(
                predicted_q_arr,
                reward_value_arr,
                next_max_q_arr
            )

            # Maximum of predicted and real Q-Values.
            real_q = real_q_arr[np.where(predicted_q_arr == predicted_q)[0][0]]
            if self.__q_logs_arr.shape[0] > 0:
                self.__q_logs_arr = np.r_[
                    self.__q_logs_arr,
                    np.array([predicted_q, real_q]).reshape(1, 2)
                ]
            else:
                self.__q_logs_arr = np.array([predicted_q, real_q]).reshape(1, 2)

            # Learn Q-Values.
            self.learn_q(predicted_q_arr, real_q_arr)
            # 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