Exemplo n.º 1
0
def get_uniform_masses_lengths_randomizer_qq(frac_halfspan: float):
    """
    Get a uniform randomizer that applies to all masses and lengths of the Quanser Qube according to a fraction of their
    nominal parameter values

    :param frac_halfspan: fraction of the nominal parameter value
    :return: `DomainRandomizer` with uniformly distributed masses and lengths
    """
    from pyrado.environments.pysim.quanser_qube import QQubeSim
    dp_nom = QQubeSim.get_nominal_domain_param()
    return DomainRandomizer(
        UniformDomainParam(name='Mp',
                           mean=dp_nom['Mp'],
                           halfspan=dp_nom['Mp'] / frac_halfspan,
                           clip_lo=1e-3),
        UniformDomainParam(name='Mr',
                           mean=dp_nom['Mr'],
                           halfspan=dp_nom['Mr'] / frac_halfspan,
                           clip_lo=1e-3),
        UniformDomainParam(name='Lr',
                           mean=dp_nom['Lr'],
                           halfspan=dp_nom['Lr'] / frac_halfspan,
                           clip_lo=1e-2),
        UniformDomainParam(name='Lp',
                           mean=dp_nom['Lp'],
                           halfspan=dp_nom['Lp'] / frac_halfspan,
                           clip_lo=1e-2),
    )
Exemplo n.º 2
0
def create_default_randomizer_qq() -> DomainRandomizer:
    """
    Create the default randomizer for the `QQubeSim`.

    :return: randomizer based on the nominal domain parameter values
    """
    from pyrado.environments.pysim.quanser_qube import QQubeSim

    dp_nom = QQubeSim.get_nominal_domain_param()
    return DomainRandomizer(
        NormalDomainParam(name="gravity_const",
                          mean=dp_nom["gravity_const"],
                          std=dp_nom["gravity_const"] / 10,
                          clip_lo=1e-3),
        NormalDomainParam(name="motor_resistance",
                          mean=dp_nom["motor_resistance"],
                          std=dp_nom["motor_resistance"] / 5,
                          clip_lo=1e-3),
        NormalDomainParam(name="motor_back_emf",
                          mean=dp_nom["motor_back_emf"],
                          std=dp_nom["motor_back_emf"] / 5,
                          clip_lo=1e-4),
        NormalDomainParam(name="mass_rot_pole",
                          mean=dp_nom["mass_rot_pole"],
                          std=dp_nom["mass_rot_pole"] / 5,
                          clip_lo=1e-4),
        NormalDomainParam(name="length_rot_pole",
                          mean=dp_nom["length_rot_pole"],
                          std=dp_nom["length_rot_pole"] / 5,
                          clip_lo=1e-4),
        NormalDomainParam(name="damping_rot_pole",
                          mean=dp_nom["damping_rot_pole"],
                          std=dp_nom["damping_rot_pole"] / 4,
                          clip_lo=1e-9),
        NormalDomainParam(name="mass_pend_pole",
                          mean=dp_nom["mass_pend_pole"],
                          std=dp_nom["mass_pend_pole"] / 5,
                          clip_lo=1e-4),
        NormalDomainParam(name="length_pend_pole",
                          mean=dp_nom["length_pend_pole"],
                          std=dp_nom["length_pend_pole"] / 5,
                          clip_lo=1e-4),
        NormalDomainParam(
            name="damping_pend_pole",
            mean=dp_nom["damping_pend_pole"],
            std=dp_nom["damping_pend_pole"] / 4,
            clip_lo=1e-9,
        ),
    )
Exemplo n.º 3
0
def get_default_randomizer_qq() -> DomainRandomizer:
    """
    Get the default randomizer for the `QQubeSim`.

    :return: randomizer based on the nominal domain parameter values
    """
    from pyrado.environments.pysim.quanser_qube import QQubeSim
    dp_nom = QQubeSim.get_nominal_domain_param()
    return DomainRandomizer(
        NormalDomainParam(name='g',
                          mean=dp_nom['g'],
                          std=dp_nom['g'] / 5,
                          clip_lo=1e-3),
        NormalDomainParam(name='Rm',
                          mean=dp_nom['Rm'],
                          std=dp_nom['Rm'] / 5,
                          clip_lo=1e-3),
        NormalDomainParam(name='km',
                          mean=dp_nom['km'],
                          std=dp_nom['km'] / 5,
                          clip_lo=1e-4),
        NormalDomainParam(name='Mr',
                          mean=dp_nom['Mr'],
                          std=dp_nom['Mr'] / 5,
                          clip_lo=1e-4),
        NormalDomainParam(name='Lr',
                          mean=dp_nom['Lr'],
                          std=dp_nom['Lr'] / 5,
                          clip_lo=1e-4),
        NormalDomainParam(name='Dr',
                          mean=dp_nom['Dr'],
                          std=dp_nom['Dr'] / 5,
                          clip_lo=1e-9),
        NormalDomainParam(name='Mp',
                          mean=dp_nom['Mp'],
                          std=dp_nom['Mp'] / 5,
                          clip_lo=1e-4),
        NormalDomainParam(name='Lp',
                          mean=dp_nom['Lp'],
                          std=dp_nom['Lp'] / 5,
                          clip_lo=1e-4),
        NormalDomainParam(name='Dp',
                          mean=dp_nom['Dp'],
                          std=dp_nom['Dp'] / 5,
                          clip_lo=1e-9))
Exemplo n.º 4
0
    # Subroutine
    subroutine_hparam = dict(
        max_iter=20,
        pop_size=50,
        num_rollouts=10,
        num_is_samples=25,
        expl_std_init=2.0,
        expl_std_min=0.02,
        symm_sampling=False,
        num_sampler_envs=8,
    )
    power = PoWER(ex_dir, env_sim, policy, **subroutine_hparam)

    # Set the boundaries for the GP
    dp_nom = QQubeSim.get_nominal_domain_param()
    # bounds = to.tensor(
    #     [[0.8*dp_nom['Mp'], dp_nom['Mp']/2000],
    #      [1.2*dp_nom['Mp'], dp_nom['Mp']/1000]])
    bounds = to.tensor([[
        0.9 * dp_nom['Mp'], dp_nom['Mp'] / 5000, 0.9 * dp_nom['Mr'],
        dp_nom['Mr'] / 5000
    ],
                        [
                            1.1 * dp_nom['Mp'], dp_nom['Mp'] / 4999,
                            1.1 * dp_nom['Mr'], dp_nom['Mr'] / 4999
                        ]])
    # bounds = to.tensor(
    #     [[0.9*dp_nom['Mp'], dp_nom['Mp']/1000, 0.9*dp_nom['Mr'], dp_nom['Mr']/1000,
    #       0.9*dp_nom['Lp'], dp_nom['Lp']/1000, 0.9*dp_nom['Lr'], dp_nom['Lr']/1000],
    #      [1.1*dp_nom['Mp'], dp_nom['Mp']/20, 1.1*dp_nom['Mr'], dp_nom['Mr']/20,
Exemplo n.º 5
0
        print_cbt(f'Set maximum number of time steps to {args.max_steps}', 'y')

    # ex_dir = input('Enter a root directory that contains one or more experiment directories:\n')
    # Get the experiment's directory to load from
    ex_dir = ask_for_experiment()
    dirs = [x[0] for x in os.walk(ex_dir)][1:]
    num_policies = len(dirs)
    print(f'Found {num_policies} policies.')

    # Specify domain parameters
    param_names = ['Dp', 'Dr', 'Mp', 'Mr', 'Lp', 'Lr']
    num_param = len(param_names)
    num_samples = 10

    # Create one-dim evaluation grid for multiple parameters
    nom_params = QQubeSim.get_nominal_domain_param()
    param_values = dict(
        Dp=np.logspace(-8, -4, num_samples),
        Dr=np.logspace(-8, -4, num_samples),
        Mp=np.linspace(0.6 * nom_params['Mp'], 1.5 * nom_params['Mp'],
                       num_samples),
        Mr=np.linspace(0.6 * nom_params['Mr'], 1.5 * nom_params['Mr'],
                       num_samples),
        Lp=np.linspace(0.6 * nom_params['Lp'], 1.5 * nom_params['Lp'],
                       num_samples),
        Lr=np.linspace(0.6 * nom_params['Lr'], 1.5 * nom_params['Lr'],
                       num_samples),
    )

    # Set up the environment
    env = ActNormWrapper(QQubeSim(dt=1 / 100., max_steps=args.max_steps))