args = get_argparser().parse_args() # Select the data set data_set_name = args.mode or "skyline" # Experiment ex_dir = setup_experiment(TSPred.name, ADNPolicy.name) # Set seed if desired pyrado.set_seed(args.seed, verbose=True) # Load the data if data_set_name == "skyline": dt = 0.01 _, vals = skyline(dt=dt, t_end=20.0, t_intvl_space=BoxSpace(0.5, 3, shape=(1, )), val_space=BoxSpace(-2.0, 3.0, shape=(1, ))) data = to.from_numpy(vals).to(dtype=to.get_default_dtype()).view(-1, 1) else: data = pd.read_csv( osp.join(pyrado.PERMA_DIR, "misc", f"{data_set_name}.csv")) if data_set_name == "daily_min_temperatures": data = to.tensor(data["Temp"].values, dtype=to.get_default_dtype()).view(-1, 1) dt = 1.0 elif data_set_name == "monthly_sunspots": data = to.tensor(data["Sunspots"].values, dtype=to.get_default_dtype()).view(-1, 1) dt = 1.0 elif "oscillation" in data_set_name: data = to.tensor(data["Positions"].values,
def test_skyline(dt: Union[int, float], t_end: Union[int, float], t_intvl_space: BoxSpace, val_space: BoxSpace): # Create the skyline function t, vals = skyline(dt, t_end, t_intvl_space, val_space) assert isinstance(t, np.ndarray) and isinstance(vals, np.ndarray) assert len(t) == len(vals)
def default_randomizer(): return DomainRandomizer( NormalDomainParam(name="mass", mean=1.2, std=0.1, clip_lo=10, clip_up=100), UniformDomainParam(name="special", mean=0, halfspan=42, clip_lo=-7.4, roundint=True), NormalDomainParam(name="length", mean=4, std=0.6, clip_up=50.1), UniformDomainParam(name="time_delay", mean=13, halfspan=6, clip_up=17, roundint=True), MultivariateNormalDomainParam(name="multidim", mean=10 * to.ones((2,)), cov=2 * to.eye(2), clip_up=11), ) # -------------- # Other Fixtures # -------------- @pytest.fixture( scope="function", params=[ (skyline(0.02, 20.0, BoxSpace(0.5, 3, shape=(1,)), BoxSpace(-2.0, 3.0, shape=(1,)))[1], 0.7, 50, False, True), ], ids=["skyline_0.8_50_notstdized_scaled"], ) def dataset_ts(request): return TimeSeriesDataSet( data=to.from_numpy(request.param[0]).to(dtype=to.get_default_dtype()), ratio_train=request.param[1], window_size=request.param[2], standardize_data=request.param[3], scale_min_max_data=request.param[4], )
from pyrado.policies.feed_forward.linear import LinearPolicy from pyrado.policies.features import * from pyrado.policies.recurrent.two_headed_rnn import TwoHeadedRNNPolicyBase from pyrado.sampling.rollout import rollout from pyrado.sampling.step_sequence import StepSequence from pyrado.utils.data_sets import TimeSeriesDataSet from pyrado.utils.data_types import RenderMode from pyrado.utils.functions import skyline from pyrado.utils.nn_layers import IndiNonlinLayer from tests.conftest import m_needs_bullet, m_needs_mujoco, m_needs_rcs, m_needs_libtorch from tests.environment_wrappers.mock_env import MockEnv @pytest.fixture(scope='function', params=[ (skyline(0.02, 20., BoxSpace(0.5, 3, shape=(1,)), BoxSpace(-2., 3., shape=(1,)))[1], 0.7, 50, False, True), ], ids=['skyline_0.8_50_notstdized_scaled']) def tsdataset(request): return TimeSeriesDataSet( data=to.from_numpy(request.param[0]), ratio_train=request.param[1], window_size=request.param[2], standardize_data=request.param[3], scale_min_max_data=request.param[4] ) @pytest.mark.features @pytest.mark.parametrize(
eq_constraint= f"{QQubeSwingUpReal.name}, {QCartPoleSwingUpReal.name} or {WAMReal.name}" ) print_cbt(f"Set the {env_real.name} environment.", "g") # Create the policy if args.mode.lower() == "chirp": def fcn_of_time(t: float): act = max_amp * chirp(t, f0=3, f1=0, t1=t_end, method="linear") return act.repeat(env_real.act_space.flat_dim) elif args.mode.lower() == "skyline": t_intvl_space = BoxSpace(dt, 100 * dt, shape=(1, )) val_space = BoxSpace(-abs(max_amp), abs(max_amp), shape=(1, )) act_predef = skyline(dt, t_end, t_intvl_space, val_space)[1] def fcn_of_time(t: float): act = act_predef[int(t / dt)] return act.repeat(env_real.act_space.flat_dim) elif args.mode.lower() == "sin": def fcn_of_time(t: float): act = max_amp * np.sin(2 * np.pi * t * 2.0) # 2 Hz return act.repeat(env_real.act_space.flat_dim) elif args.mode.lower() == "wam_sin": fcn_of_time = wam_jsp_7dof_sin else: