def dataset_load(args, device): if systems[args.system] == 'emulator': dataset = EmulatorDataset(system=args.system, nsim=args.nsim, norm=args.norm, nsteps=args.nsteps, device=device, savedir=args.savedir, name='closedloop') else: dataset = FileDataset(system=args.system, nsim=args.nsim, norm=args.norm, nsteps=args.nsteps, device=device, savedir=args.savedir, name='closedloop') ny = args.ny if not ny == dataset.data['Y'].shape[1]: new_sequences = {'Y': dataset.data['Y'][:, :1]} dataset.add_data(new_sequences, overwrite=True) dataset.min_max_norms['Ymin'] = dataset.min_max_norms['Ymin'][0] dataset.min_max_norms['Ymax'] = dataset.min_max_norms['Ymax'][0] nsim = dataset.data['Y'].shape[0] nu = dataset.data['U'].shape[1] # new_sequences = {'Y_max': 0.8 * np.ones([nsim, 1]), 'Y_min': 0.2 * np.ones([nsim, 1]), new_sequences = {'Y_max': psl.Periodic(nx=1, nsim=nsim, numPeriods=30, xmax=0.9, xmin=0.6), 'Y_min': psl.Periodic(nx=1, nsim=nsim, numPeriods=25, xmax=0.4, xmin=0.1), 'U_max': np.ones([nsim, nu]), 'U_min': np.zeros([nsim, nu]), # 'R': psl.Steps(nx=1, nsim=nsim, randsteps=60, xmax=0.7, xmin=0.3), 'R': psl.Periodic(nx=1, nsim=nsim, numPeriods=20, xmax=0.8, xmin=0.2) # 'Y_ctrl_': psl.RandomWalk(nx=ny, nsim=nsim, xmax=[1.0] * ny, xmin=[0.0] * ny, sigma=0.05)} #'Y_ctrl_': psl.WhiteNoise(nx=ny, nsim=nsim, xmax=[1.0] * ny, xmin=[0.0] * ny)} } dataset.add_data(new_sequences) # dataset.dims['Rf'] = (9000, 1) return dataset
def dataset_load(args, device): if systems[args.system] == 'emulator': dataset = EmulatorDataset(system=args.system, nsim=args.nsim, norm=args.norm, nsteps=args.nsteps, device=device, savedir=args.savedir) else: dataset = FileDataset(system=args.system, nsim=args.nsim, norm=args.norm, nsteps=args.nsteps, device=device, savedir=args.savedir) return dataset
def dataset_load(args, device): if systems[args.system] == 'emulator': dataset = EmulatorDataset(system=args.system, nsim=args.nsim, norm=args.norm, nsteps=args.nsteps, device=device, savedir=args.savedir) else: dataset = FileDataset(system=args.system, nsim=args.nsim, norm=args.norm, nsteps=args.nsteps, device=device, savedir=args.savedir) new_sequences = {'Y': dataset.data['Y'][:, :1]} dataset.min_max_norms['Ymin'] = dataset.min_max_norms['Ymin'][0] dataset.min_max_norms['Ymax'] = dataset.min_max_norms['Ymax'][0] dataset.add_data(new_sequences, overwrite=True) return dataset
def dataset_load(args, device): if systems[args.system] == 'emulator': dataset = EmulatorDataset(system=args.system, nsim=args.nsim, norm=args.norm, nsteps=args.nsteps, device=device, savedir=args.savedir, name='closedloop') else: dataset = FileDataset(system=args.system, nsim=args.nsim, norm=args.norm, nsteps=args.nsteps, device=device, savedir=args.savedir, name='closedloop') nsim, ny = dataset.data['Y'].shape nu = dataset.data['U'].shape[1] new_sequences = { 'Y_max': 0.8 * np.ones([nsim, ny]), 'Y_min': 0.2 * np.ones([nsim, ny]), 'U_max': np.ones([nsim, nu]), 'U_min': np.zeros([nsim, nu]), 'R': psl.Steps(nx=1, nsim=nsim, randsteps=30, xmax=1, xmin=0), # 'R': psl.Periodic(nx=1, nsim=nsim, numPeriods=12, xmax=1, xmin=0), 'Y_ctrl_': psl.WhiteNoise(nx=ny, nsim=nsim, xmax=[1.0] * ny, xmin=[0.0] * ny) } dataset.add_data(new_sequences) return dataset
nsim) + SG2.sequence_generator(nsim) if __name__ == '__main__': model_file = './datasets/Flexy_air/best_model_flexy1.pth' load_model = torch.load(model_file, pickle_module=dill, map_location=torch.device('cpu')) estimator = load_model.components[0] dynamics = load_model.components[1] nsteps = 32 ny = load_model.components[1].fy.out_features dataset = FileDataset(system='flexy_air', nsim=10000, norm=['U', 'D', 'Y'], nsteps=nsteps, device='cpu') dataset.min_max_norms['Ymin'] = dataset.min_max_norms['Ymin'][0] dataset.min_max_norms['Ymax'] = dataset.min_max_norms['Ymax'][0] nsim = dataset.data['Y'].shape[0] nu = dataset.data['U'].shape[1] new_sequences = { 'Y_max': 0.8 * np.ones([nsim, 1]), 'Y_min': 0.2 * np.ones([nsim, 1]), 'U_max': np.ones([nsim, nu]), 'U_min': np.zeros([nsim, nu]), 'R': psl.Periodic(nx=1, nsim=nsim, numPeriods=20, xmax=0.7, xmin=0.3) } dataset.add_data(new_sequences) dynamics_generator = SignalGeneratorDynamics(dynamics,
D.append(d) if d is not None else None R.append(r) if r is not None else None Ymin.append(ymin) if ymin is not None else None Ymax.append(ymax) if ymax is not None else None Umin.append(umin) if umin is not None else None Umax.append(umax) if umax is not None else None return { 'Y': np.concatenate(Y, 0), 'X': np.concatenate(X, 0), 'U': np.concatenate(U, 0), 'D': np.concatenate(D, 0) if D else None, 'R': np.concatenate(R, 0) if R else None, 'Ymin': np.concatenate(Ymin, 0) if Ymin else None, 'Ymax': np.concatenate(Ymax, 0) if Ymax else None, 'Umin': np.concatenate(Umin, 0) if Umin else None, 'Umax': np.concatenate(Umax, 0) if Umax else None } if __name__ == '__main__': systems = {'Reno_full': 'emulator'} for system, data_type in systems.items(): if data_type == 'emulator': dataset = EmulatorDataset(system) elif data_type == 'datafile': dataset = FileDataset(system) nsim, ny = dataset.data['Y'].shape nu = dataset.data['U'].shape[1]
pickle_module=dill) policy = torch.load('../datasets/Flexy_air/device_test_models/' + model + '/best_policy_flexy.pth', pickle_module=dill) estimator = torch.load('../datasets/Flexy_air/device_test_models/' + model + '/best_estimator_flexy.pth', pickle_module=dill) estimator.input_keys[0] = 'Yp' policy.input_keys[0] = 'Yp' HW_emulator = Simulator(estimator=estimator, dynamics=dynamics) # dataset nsim = 3000 dataset = FileDataset(system='flexy_air', nsim=nsim, norm=['U', 'D', 'Y'], nsteps=estimator.nsteps) ny = 1 nu = 1 nsteps = policy.nsteps R = { 'steps': psl.Steps(nx=1, nsim=nsim, randsteps=30, xmax=0.7, xmin=0.3), 'periodic': psl.Periodic(nx=1, nsim=nsim, numPeriods=20, xmax=0.7, xmin=0.3) }[args.ref_type] if args.dynamic_constraints: bounds_reference = { 'Y_max':
pickle_module=dill) estimator = torch.load('../datasets/Flexy_air/device_test_models/' + model + '/best_estimator_flexy.pth', pickle_module=dill) estimator.input_keys[0] = 'Yp' policy.input_keys[0] = 'Yp' # temporary fix to be compatible with latest model change dynamics.fyu = None HW_emulator = Simulator(estimator=estimator, dynamics=dynamics) # dataset nsim = 9000 dataset = FileDataset(system='flexy_air', nsim=nsim, norm=['U', 'D', 'Y'], nsteps=estimator.nsteps) ny = 1 nu = 1 nsteps = policy.nsteps # mean the disturbance disturb_static = 0.44 # dataset.data['D'] = np.mean(dataset.data['D']) * np.ones((dataset.data['D']).shape) dataset.data['D'] = disturb_static * np.ones((dataset.data['D']).shape) # list(np.random.random(10)) R = { 'static': 0.5 * np.ones([nsim, 1]), # 'spline': psl.SplineSignal(nsim=nsim, values=[0.3, 0.7, 0.6, 0.8, 0.5, 0.7, 0.4, 0.75, 0.3]).reshape(nsim, 1),