Exemplo n.º 1
0
def main( epoch_budget, count, gen_type, gen_args, agent_type, agent_args, env_type, env_args, file_prefix ):
    """
    @arg epochs: Maximum number of epochs to use
    @arg count: Number of options to learn
    @arg agent_type: String name of agent
    @arg agent_args: Arguments to the agent constructor
    @arg env_type: String name of environment
    @arg env_args: Arguments to the environment constructor
    """

    env = env_type.create( *env_args )

    if gen_type == "betweenness":
        options = OptionGenerator.learn_options_from_betweenness( epoch_budget, count, env, env_args, agent_type, agent_args )
    elif gen_type == "optimal-betweenness":
        options = OptionGenerator.optimal_options_from_betweenness( env, count )
    elif gen_type == "small-world":
        options = OptionGenerator.learn_options_from_small_world( epoch_budget, count, env, env_args, agent_type, agent_args, *gen_args )
    elif gen_type == "optimal-small-world":
        options = OptionGenerator.optimal_options_from_small_world( env, count, *gen_args )
    else:
        raise NotImplemented()

    # Save options
    f = open("%s.options"%( file_prefix ), "w")
    pickle.dump( options, f )
    f.close()
    def create(height, width, scheme="none", count=20, *args):
        """
        @spec - Specification (size, endpoints, barriers); either exactly
                specified in a file, or with numeric values in a list
        @option_scheme - none|manual|optimal|small-world|random|ozgur's betweenness|ozgur's randomness|end
        @n_actions - Number of steps that need to taken
        comment : optimal(shortest path to destination)??|random|ozgur's betweenness|ozgur's randomness
        """

        env = ArbitraryNavigation.create(height, width)
        g = env.to_graph()
        gr = g.reverse()

        # Percentage
        if isinstance(count, str):
            count = int(count[:-1])
            count = count * env.S / 100

        # Add options for all the optimal states
        O = []
        if scheme == "none":
            pass
        elif scheme == "random-node":
            O = OptionGenerator.optimal_options_from_random_nodes(env, count, *args)
        elif scheme == "random-path":
            O = OptionGenerator.optimal_options_from_random_paths(env, count, *args)
        elif scheme == "betweenness":
            O = OptionGenerator.optimal_options_from_betweenness(env, count, *args)
        elif scheme == "small-world":
            O = OptionGenerator.optimal_options_from_small_world(env, count, *args)
        elif scheme == "betweenness+small-world":
            O = OptionEnvironment.optimal_options_from_betweenness(env, count)
            count_ = count - len(O)
            O += OptionEnvironment.optimal_options_from_small_world(env, count_, *args)
        elif scheme == "load":
            O = OptionGenerator.options_from_file(*args)[:count]
        else:
            raise NotImplemented()

        return OptionEnvironment(
            ArbitraryNavigationOptions, env.S, env.A, env.P, env.R, env.R_bias, env.start_set, env.end_set, O
        )
Exemplo n.º 3
0
    def create( height, width, scheme = 'none', count = 20, *args ):
        """
        @spec - Specification (size, endpoints, barriers); either exactly
                specified in a file, or with numeric values in a list
        @option_scheme - none|manual|optimal|small-world|random|ozgur's betweenness|ozgur's randomness|end
        @n_actions - Number of steps that need to taken
        comment : optimal(shortest path to destination)??|random|ozgur's betweenness|ozgur's randomness
        """

        env = ArbitraryNavigation.create( height, width )
        g = env.to_graph()
        gr = g.reverse()

        # Percentage
        if isinstance(count,str):
            count = int(count[:-1])
            count = count*env.S/100

        # Add options for all the optimal states
        O = []
        if scheme == "none":
            pass
        elif scheme == "random-node":
            O = OptionGenerator.optimal_options_from_random_nodes( env, count, *args )
        elif scheme == "random-path":
            O = OptionGenerator.optimal_options_from_random_paths( env, count, *args )
        elif scheme == "betweenness":
            O = OptionGenerator.optimal_options_from_betweenness( env, count, *args )
        elif scheme == "small-world":
            O = OptionGenerator.optimal_options_from_small_world( env, count, *args )
        elif scheme == "betweenness+small-world":
            O = OptionEnvironment.optimal_options_from_betweenness( env, count )
            count_ = count - len( O ) 
            O += OptionEnvironment.optimal_options_from_small_world( env, count_, *args )
        elif scheme == "load":
            O = OptionGenerator.options_from_file( *args )[:count]
        else:
            raise NotImplemented() 

        return OptionEnvironment( ArbitraryNavigationOptions, env.S, env.A, env.P, env.R, env.R_bias, env.start_set, env.end_set, O )
        comment : optimal(shortest path to destination)??|random|ozgur's betweenness|ozgur's randomness
        """

        env = Rooms.create( spec, K )

        # Percentage
        if isinstance(count,str):
            count = int(count[:-1])
            count = count*env.S/100

        # Add options for all the optimal states
        O = []
        if scheme == "none":
            pass
        elif scheme == "random-node":
            O = OptionGenerator.optimal_options_from_random_nodes( env, count, *args )
        elif scheme == "random-path":
            O = OptionGenerator.optimal_options_from_random_paths( env, count, *args )
        elif scheme == "betweenness":
            O = OptionGenerator.optimal_options_from_betweenness( env, count, *args )
        elif scheme == "small-world":
            O = OptionGenerator.optimal_options_from_small_world( env, count, *args )
        elif scheme == "betweenness+small-world":
            O = OptionEnvironment.optimal_options_from_betweenness( env, count )
            count_ = count - len( O ) 
            O += OptionEnvironment.optimal_options_from_small_world( env, count_, *args )
        elif scheme == "load":
            O = OptionGenerator.options_from_file( count, *args )
        else:
            raise NotImplemented() 
Exemplo n.º 5
0
        comment : optimal(shortest path to destination)??|random|ozgur's betweenness|ozgur's randomness
        """

        env = Rooms.create( spec, K )

        # Percentage
        if isinstance(count,str):
            count = int(count[:-1])
            count = count*env.S/100

        # Add options for all the optimal states
        O = []
        if scheme == "none":
            pass
        elif scheme == "random-node":
            O = OptionGenerator.optimal_options_from_random_nodes( env, count, *args )
        elif scheme == "random-path":
            O = OptionGenerator.optimal_options_from_random_paths( env, count, *args )
        elif scheme == "betweenness":
            O = OptionGenerator.optimal_options_from_betweenness( env, count, *args )
        elif scheme == "small-world":
            O = OptionGenerator.optimal_options_from_small_world( env, count, *args )
        elif scheme == "betweenness+small-world":
            O = OptionEnvironment.optimal_options_from_betweenness( env, count )
            count_ = count - len( O ) 
            O += OptionEnvironment.optimal_options_from_small_world( env, count_, *args )
        elif scheme == "load":
            O = OptionGenerator.options_from_file( count, *args )
        else:
            raise NotImplemented()