alpaca/alpacka/agents/stochastic_mcts.py
def rate_new_leaves_with_rollouts(
    leaf,
    observation,
    model,
    discount,
    rollout_agent_class=core.RandomAgent,
    rollout_time_limit=100,
):
    """Basic rate_new_leaves_fn based on rollouts with an Agent.

    Args:
        leaf (TreeNode): Node whose children are to be rated.
        observation (np.ndarray): Observation received at leaf.
        model (gym.Env): Model environment.
        discount (float): Discount factor.
        rollout_agent_class (type): Agent class to use for rollouts.
        rollout_time_limit (int): Maximum number of timesteps for rollouts.

    Yields:
        Network prediction requests.

    Returns:
        list: List of pairs (reward, value) for all actions played from leaf.
    """
    del leaf
    agent = rollout_agent_class(model.action_space)
    init_state = model.clone_state()

    child_ratings = []
    for init_action in range(model.action_space.n):
        (observation, init_reward, done, _) = model.step(init_action)
        value = 0
        total_discount = 1
        time = 0
        while not done and time < rollout_time_limit:
            (action, _) = yield from agent.act(observation)
            (observation, reward, done, _) = model.step(action)
            value += total_discount * reward
            total_discount *= discount
            time += 1
        child_ratings.append((init_reward, value))
        model.restore_state(init_state)
    return child_ratings
Basic rate_new_leaves_fn based on rollouts with an Agent.

    Args:
        leaf (TreeNode): Node whose children are to be rated.
        observation (np.ndarray): Observation received at leaf.
        model (gym.Env): Model environment.
        discount (float): Discount factor.
        rollout_agent_class (type): Agent class to use for rollouts.
        rollout_time_limit (int): Maximum number of timesteps for rollouts.

    Yields:
        Network prediction requests.

    Returns:
        list: List of pairs (reward, value) for all actions played from leaf.
    
Basic rate_new_leaves_fn based on rollouts with an Agent.
Basic rate_new_leaves_fn based on rollouts with an Agent .
def rate_new_leaves_with_rollouts(
    leaf,
    observation,
    model,
    discount,
    rollout_agent_class=core.RandomAgent,
    rollout_time_limit=100,
):
    del leaf
    agent = rollout_agent_class(model.action_space)
    init_state = model.clone_state()
    child_ratings = []
    for init_action in range(model.action_space.n):
        (observation, init_reward, done, _) = model.step(init_action)
        value = 0
        total_discount = 1
        time = 0
        while not done and time < rollout_time_limit:
            (action, _) = yield from agent.act(observation)
            (observation, reward, done, _) = model.step(action)
            value += total_discount * reward
            total_discount *= discount
            time += 1
        child_ratings.append((init_reward, value))
        model.restore_state(init_state)
    return child_ratings
def rate_new_leaves_with_rollouts ( leaf , observation , model , discount , rollout_agent_class = core . RandomAgent , rollout_time_limit = 100 , ) : del leaf agent = rollout_agent_class ( model . action_space ) init_state = model . clone_state ( ) child_ratings = [ ] for init_action in range ( model . action_space . n ) : ( observation , init_reward , done , _ ) = model . step ( init_action ) value = 0 total_discount = 1 time = 0 while not done and time < rollout_time_limit : ( action , _ ) = yield from agent . act ( observation ) ( observation , reward , done , _ ) = model . step ( action ) value += total_discount * reward total_discount *= discount time += 1 child_ratings . append ( ( init_reward , value ) ) model . restore_state ( init_state ) return child_ratings
Basic rate_new_leaves_fn based on rollouts with an Agent.
Basic rate_new_leaves_fn based on rollouts with an Agent .
"""Basic rate_new_leaves_fn based on rollouts with an Agent.

    Args:
        leaf (TreeNode): Node whose children are to be rated.
        observation (np.ndarray): Observation received at leaf.
        model (gym.Env): Model environment.
        discount (float): Discount factor.
        rollout_agent_class (type): Agent class to use for rollouts.
        rollout_time_limit (int): Maximum number of timesteps for rollouts.

    Yields:
        Network prediction requests.

    Returns:
        list: List of pairs (reward, value) for all actions played from leaf.
    """
Network prediction requests.
Network prediction requests .
List of pairs (reward, value) for all actions played from leaf.
List of pairs ( reward value ) for all actions played from leaf .
list
leaf
Node whose children are to be rated.
Node whose children are to be rated .
observation
Observation received at leaf.
Observation received at leaf .
model
None
discount
None
rollout_agent_class
Agent class to use for rollouts.
Agent class to use for rollouts .
rollout_time_limit
Maximum number of timesteps for rollouts.
Maximum number of timesteps for rollouts .