def __init__(self): super().__init__(screenWidth, screenHeight, "Sumo") file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) arcade.set_background_color(arcade.color.GRAY_BLUE) self.a = sumo.arena.Arena((screenWidth, screenHeight)) self.tDown = False self.speedMode = False self.bot0LeftMotor = 0.0 self.bot0RightMotor = 0.0 self.bot0Boost = False self.bot1LeftMotor = 0.0 self.bot1RightMotor = 0.0 self.bot1Boost = False ########################### Create Agents ########################### # Sensors: arena distance from center, angle relative to center, distance from opponent, angle to opponent, angle between opponents, boost # Actions: Left motor, right motor, boost self.cs = pyswarm.PyComputeSystem(16) numInputs = 6 numActions = 3 numLayers = 2 inputSize = pyswarm.PyInt3(1, 1, numInputs) lds = [] for i in range(numLayers): l = pyswarm.PyLayerDesc() l._layerType = "conv" l._filterRadius = 0 l._numMaps = numActions if i == numLayers - 1 else 24 l._recurrent = False if i == numLayers - 1 else True l._actScalar = 6.0 lds.append(l) self.h0 = pyswarm.PyHierarchy(self.cs, inputSize, lds, 32) self.h1 = pyswarm.PyHierarchy(self.cs, inputSize, lds, 32) self.h0.setOptAlpha(0.001) self.h1.setOptAlpha(0.001) self.rewardNoise = 0.0
import pyswarm import numpy as np import gym env = gym.make('CartPole-v0') numInputs = env.observation_space.shape[0] cs = pyswarm.PyComputeSystem(16, seed=np.random.randint(0, 99999)) inputSize = pyswarm.PyInt3(1, 1, numInputs) lds = [] numLayers = 2 for i in range(numLayers): l = pyswarm.PyLayerDesc() l._layerType = "conv" l._filterRadius = 0 # Dense l._numMaps = 16 if i < numLayers - 1 else 1 l._recurrent = i < numLayers - 1 l._actScalar = 6.0 lds.append(l) h = pyswarm.PyHierarchy(cs, inputSize, lds, 32) h.setOptAlpha(0.01)
import pyswarm import numpy as np import gym import gym_ple import lycon from copy import copy import scipy.misc env = gym.make('Catcher-v0') imageSize = (16, 16) numActions = env.action_space.n cs = pyswarm.PyComputeSystem(16) inputSize = pyswarm.PyInt3(imageSize[0], imageSize[1], 1) lds = [] numLayers = 5 for i in range(numLayers): l = pyswarm.PyLayerDesc() if i % 2 == 0: l._layerType = "conv" l._filterRadius = 2 l._numMaps = 4 + i * 2 if i < numLayers - 1 else numActions l._recurrent = True if i == numLayers - 2 else False
import pyswarm import numpy as np import gym env = gym.make('BipedalWalker-v2') numInputs = env.observation_space.shape[0] numActions = env.action_space.shape[0] cs = pyswarm.PyComputeSystem(16, 1234) inputSize = pyswarm.PyInt3(1, 1, numInputs) lds = [] numLayers = 2 for i in range(numLayers): l = pyswarm.PyLayerDesc() l._layerType = "conv" l._filterRadius = 0 # Dense l._numMaps = 16 if i != numLayers - 1 else numActions l._recurrent = i != numLayers - 1 l._actScalar = 6.0 lds.append(l) h = pyswarm.PyHierarchy(cs, inputSize, lds, 32)