import numpy as np from GA_Config import Config from GA_Network import Network config = Config() #copies all the weights to a another network object def copy_net(old_net): new_net = Network(config) new_net.w_in = np.copy(old_net.w_in) for i in range(config.num_layers): new_net.w_hidden[i] = np.copy(old_net.w_hidden[i]) new_net.w_out = np.copy(old_net.w_out) return new_net #weights are mutated by adding random noise def mutation(policy): noise = np.random.randn(policy.total_num) noise *= config.sigma policy.w_in += noise[:policy.num_in].reshape(policy.w_in.shape) curr = policy.num_in for i in range(config.num_layers): policy.w_hidden[i] += noise[curr:curr+policy.num_weights[i]].reshape(policy.w_hidden[i].shape) curr += policy.num_weights[i] policy.w_out += noise[policy.total_num - policy.num_out:].reshape(policy.w_out.shape)
from scipy import stats import GPy import matplotlib.pyplot as plt import matplotlib.patches as mpatch import gym import os import sys sys.path.insert(0, '../../..') import GP_Games sys.path.insert(0, '../../../Genetic_Algorithms') from GA_Config import Config from GA_Network import Network config = Config() config.num_layers = 2 config.num_hidden = 128 config.env_name = 'GP_Water-v0' config.a_size = 4 network = Network(config) generations = 100 steps = 100 iters = 1 actions = np.zeros([steps, generations, iters]) TargetTemp = 100 TargetMass = [0, 0.5, 0.5] StartTemp = 21
import numpy as np import gym import matplotlib.pyplot as plt import matplotlib.colors as mcolors import os import sys sys.path.insert(0, '../../../') import MultiAgent_Games sys.path.insert(0, '../../../MultiAgent_GA') from GA_Config import Config from GA_Network import Network config = Config() config.num_layers = 2 config.num_hidden = 128 config.env_name = 'Bees-v1' config.a_size = 5 network = Network(config) weights = np.load('./models/Bees-v1_11/10500.npz') network.w_in = weights['w_in'] network.w_hidden = weights['w_h'] network.w_out = weights['w_out'] env = gym.make(config.env_name).unwrapped env.engine.num_bees = 1 env.engine.num_flowers = 1 s = env.reset()
import numpy as np import gym import matplotlib.pyplot as plt import time from Tkinter import * import os import sys sys.path.insert(0, '../../..') import GP_Games sys.path.insert(0, '../../../Genetic_Algorithms') from GA_Config import Config from GA_Network import Network config = Config() config.num_layers = 2 config.num_hidden = 128 network = Network(config) weights = np.load('../../../Genetic_Algorithms/models/GP_Water-v0/126.npz') network.w_in = weights['w_in'] network.w_hidden = weights['w_h'] network.w_out = weights['w_out'] env = gym.make('GP_Water-v0') s = env.reset() print(env.unwrapped.TargetTemp, env.unwrapped.TargetMass) def plt_model(ind, s, r):