z_indices=z_indices, unexp_z_indices=unexp_z_indices, parameters=cstrs_plant_parameters, exp_dist_indices=exp_dist_indices, seed=50, tsteps_steady=5) cstrs_offline_simulator = _get_cstrs_offline_simulator( cstrs_mpc_controller, cstrs_plant_parameters, z_indices, unexp_z_indices, exp_dist_indices, Nsim=150000, num_data_gen_task=1, num_process_per_task=1, conservative_factor=1.02, seed=1) # Create a dictionary with the required data. cstrs_parameters = dict(plant=cstrs, mpc=cstrs_mpc_controller, us=cstrs_us_controller, satdlqr=cstrs_satdlqr_controller, short_horizon=cstrs_sh_controller, offline_simulator=cstrs_offline_simulator, online_test_scenarios=cstrs_online_test_scenarios, cstrs_plant_parameters=cstrs_plant_parameters) #cstrs_parameters = dict(online_test_scenarios=cstrs_online_test_scenarios, # cstrs_plant_parameters=cstrs_plant_parameters) # Save data. PickleTool.save(data_object=cstrs_parameters, filename='cstrs_parameters.pickle')
scale=True) # Get a NN controller. regulator_dims = [72, 224, 224, 224, 6] nn_controller = create_nn_controller(regulator_dims=regulator_dims) # Train the NN controller. (nn_controller, training_time) = train_nn_controller(nn_controller, training_data, stdout_filename='cstrs_train_unstd.txt', ckpt_path='cstrs_train_unstd.ckpt') # Get the best weights. nn_controller.load_weights('cstrs_train_unstd.ckpt') trained_regulator_weights = nn_controller.get_weights() # Get the NN memory footprints. memory_footprint = PickleTool.get_nn_memory_footprint(regulator_weights= trained_regulator_weights, filename='cstrs_trained_weights_unstd.pickle') # Save the weights. cstrs_training_data = dict(trained_regulator_weights=trained_regulator_weights, training_time=training_time, memory_footprint=memory_footprint, xscale=xscale, regulator_dims=regulator_dims) # Save data. PickleTool.save(data_object=cstrs_training_data, filename='cstrs_train_unstd.pickle')
nn_controller, training_data, stdout_filename=str(train_architecture) + '-cstrs_train.txt', ckpt_path=str(train_architecture) + '-cstrs_train.ckpt') # Load and save the best weights. nn_controller.load_weights(str(train_architecture) + '-cstrs_train.ckpt') trained_regulator_weights.append(nn_controller.get_weights()) # Get the overall NN design time. data_generation_time = num_sample / num_samples[-1] data_generation_time = data_generation_time * raw_data['data_gen_time'] data_generation_times.append(data_generation_time) training_times.append(training_time) # Get the NN memory footprints. memory_footprint = PickleTool.get_nn_memory_footprint( regulator_weights=trained_regulator_weights[-1], filename=str(train_architecture) + '-cstrs_trained_weights.pickle') memory_footprints.append(memory_footprint) # Save the weights. cstrs_training_data = dict(trained_regulator_weights=trained_regulator_weights, num_architectures=len(regulator_dims), num_samples=num_samples, data_generation_times=data_generation_times, training_times=training_times, memory_footprints=memory_footprints, xscale=xscale, regulator_dims=regulator_dims) # Save data. PickleTool.save(data_object=cstrs_training_data, filename=str(train_architecture) + '-cstrs_train.pickle')