def policy_rollout(GP_model, depth_h,bounds): # caluc policy function if depth_h > 1: func2minimize = lambda x : -1*ei(x,bounds,GP_model) else: func2minimize = lambda x : gpmean(x,bounds,GP_model) query = minimize(func2minimize, bounds) return query
def policy_rollout_ei(GP_model, func_cost, depth_c, threthold, bounds): # caluc policy function if depth_c > threthold: func2minimize = lambda x: -1 * ei(x, bounds, GP_model) else: func2minimize = lambda x: gpmean(x, bounds, GP_model) query = minimize(func2minimize, bounds) return query
content_target = K.variable(content_net.predict(content_image)) # 7 - Calculate the loss and gradients respect to input # 7.1 - Content loss loss = K.mean(K.square(content_net.output - content_target)) grads = K.gradients(loss, content_net.input) # 7.4 - Create a callable function that uses the symbolic variables we have created loss_grads = K.function(inputs=[content_net.input], outputs=[loss] + grads) # 7.5 - Wrapper function def get_loss_and_grads_wrapper(x_vec): ''' Takes a 1D vector, reshape it into an image, calculate loss and gradient and flatten each vector back casting into float64 ''' l, g = loss_grads([x_vec.reshape(*batch_shape)]) return l.astype(np.float64), g.flatten().astype(np.float64) final_image, history = minimize(get_loss_and_grads_wrapper, 10, batch_shape) plt.imshow(scale_(final_image)) plt.savefig(os.path.join(path_to_save, 'content_decoded.png')) plt.show() plt.plot(history) plt.savefig('history.png') plt.show()
kB = unit.BOLTZMANN_CONSTANT_kB * unit.AVOGADRO_CONSTANT_NA density = reduced_density / (sigma**3) temperature = reduced_temperature * epsilon / kB pressure = reduced_pressure * epsilon / (sigma**3) kT = kB * temperature # Create the Lennard-Jones fluid. testsystem = testsystems.LennardJonesFluid(nparticles=nparticles, mass=mass, sigma=sigma, epsilon=epsilon, reduced_density=reduced_density) # Construct initial positions by minimization. print "Minimizing positions..." initial_positions = utils.minimize(testsystem.system, testsystem.positions) # Write initial positions. print "Writing initial positions to initial.pdb" utils.write_pdb('initial.pdb', initial_positions) # Create NetCDF file to store data. ncfile = utils.create_netcdf_datastore(netcdf_filename, testsystem.system, initial_positions, nreplicates, niterations, observation_interval) # Run replicates of the simulation. for replicate in range(nreplicates): # Reconstitute System object. print "Reconstituting System object..." system = openmm.System()
def policy_naive(GP_model, depth_h,bounds): # caluc naive policy function func2minimize = lambda x : -1*ei(x,bounds,GP_model) query = minimize(func2minimize, bounds) return query
def policy_mu(GP_model, bounds): # caluc naive policy function func2minimize = lambda x: gpmean(x, bounds, GP_model) query = minimize(func2minimize, bounds) return query
def policy_naive_eipercost(GP_model, func_cost, depth_c, threthold, bounds): # caluc naive policy function func2minimize = lambda x: -1 * ei_per_cost(x, func_cost, bounds, GP_model) query = minimize(func2minimize, bounds) return query
nsteps_per_iteration = barostat_frequency observation_interval = timestep * nsteps_per_iteration # Compute real units. kB = unit.BOLTZMANN_CONSTANT_kB * unit.AVOGADRO_CONSTANT_NA density = reduced_density / (sigma**3) temperature = reduced_temperature * epsilon / kB pressure = reduced_pressure * epsilon / (sigma**3) kT = kB * temperature # Create the Lennard-Jones fluid. testsystem = testsystems.LennardJonesFluid(nparticles=nparticles, mass=mass, sigma=sigma, epsilon=epsilon, reduced_density=reduced_density) # Construct initial positions by minimization. print "Minimizing positions..." initial_positions = utils.minimize(testsystem.system, testsystem.positions) # Write initial positions. print "Writing initial positions to initial.pdb" utils.write_pdb('initial.pdb', initial_positions) # Create NetCDF file to store data. ncfile = utils.create_netcdf_datastore(netcdf_filename, testsystem.system, initial_positions, nreplicates, niterations, observation_interval) # Run replicates of the simulation. for replicate in range(nreplicates): # Reconstitute System object. print "Reconstituting System object..." system = openmm.System() system.__setstate__(str(ncfile.variables['system'][0]))