def __init__(self): self.bus = bus.Bus() self.memory = memory.Memory(self.bus) self.L2C0 = L2.L2(0, self.bus, self.memory) self.L2C1 = L2.L2(1, self.bus, self.memory) self.directoryController = directoryController.DirectoryController( self.L2C0, self.L2C1, self.memory, self.bus) self.C0 = chip.Chip(0, self.memory, self.bus, self.directoryController, self.L2C0) self.C1 = chip.Chip(1, self.memory, self.bus, self.directoryController, self.L2C1) self.window = Tk() self.tableL1P0C0 = Treeview(self.window, height=2) self.tableL1P1C0 = Treeview(self.window, height=2) self.tableL1P0C1 = Treeview(self.window, height=2) self.tableL1P1C1 = Treeview(self.window, height=2) self.tableL2C0 = Treeview(self.window, height=4) self.tableL2C1 = Treeview(self.window, height=4) self.tableMemory = Treeview(self.window, height=16) self.t1 = threading.Thread(target=self.C0.run) self.t2 = threading.Thread(target=self.C1.run) self.t3 = threading.Thread(target=self.directoryController.runL2toMem) self.t4 = threading.Thread(target=self.directoryController.runMemtoL2) self.t5 = threading.Thread(target=self.updateMemories)
def __init__( self, outputs, memorySize, discountFactor, learningRate, learnStart, img_rows, img_cols, img_channels, ): """ Parameters: - outputs: output size - memorySize: size of the memory that will store each state - discountFactor: the discount factor (gamma) - learningRate: learning rate - learnStart: steps to happen before for learning. Set to 128 """ self.img_rows = img_rows self.img_cols = img_cols self.img_channels = img_channels self.output_size = outputs self.memory = memory.Memory(memorySize) self.discountFactor = discountFactor self.learnStart = learnStart self.learningRate = learningRate
def __init__(self, fm_infile, seed_hv_infile, is_early_fusion=True, use_3_seed=False): # Feature Memory self.feature_memory = memory.FeatureMemory(fm_infile) self.feature_memory.normalize() self.feature_memory.downSample(self.downsample_interval) self.feature_memory.discretize() self.feature_memory.genTrainData(self.learning_rate) # Seed HV progress over time self.seed_hv = memory.Memory(seed_hv_infile) # Associative Memory memory.AssociativeMemory.dimension = self.dimension self.associative_memory = memory.AssociativeMemory() # Spatial Encoder spatial_encoder.SpatialEncoder.dimension = self.dimension self.spatial_encoder_GSR = spatial_encoder.SpatialEncoder( self.num_channel_GSR) self.spatial_encoder_ECG = spatial_encoder.SpatialEncoder( self.num_channel_ECG) self.spatial_encoder_EEG = spatial_encoder.SpatialEncoder( self.num_channel_EEG) # Temporal Encoder temporal_encoder.TemporalEncoder.dimension = self.dimension temporal_encoder.TemporalEncoder.ngram_size = self.ngram_size self.temporal_encoder = temporal_encoder.TemporalEncoder( ) # used only when is_early_fusion is True self.temporal_encoder_GSR = temporal_encoder.TemporalEncoder( ) # used only when is_early_fusion is False self.temporal_encoder_ECG = temporal_encoder.TemporalEncoder( ) # used only when is_early_fusion is False self.temporal_encoder_EEG = temporal_encoder.TemporalEncoder( ) # used only when is_early_fusion is False self.is_early_fusion = is_early_fusion self.use_3_seed = use_3_seed # Prediction Statistics self.correct_prediction = 0 self.wrong_prediction = 0 self.prediction_success_rate = 0 self.correct_v_prediction = 0 self.wrong_v_prediction = 0 self.prediction_v_success_rate = 0 self.correct_a_prediction = 0 self.wrong_a_prediction = 0 self.prediction_a_success_rate = 0 self.predicted_v_history = [] self.predicted_a_history = []
def __init__(self, inputs, outputs, memorySize, discountFactor, learningRate, learnStart): self.input_size = inputs self.output_size = outputs self.memory = memory.Memory(memorySize) self.discountFactor = discountFactor self.learnStart = learnStart self.learningRate = learningRate
def __init__(self, duration): self.memory = memory.Memory() self.duration = duration for i in range(4): name = "CPU" + str(i) tmp_cpu = Cpu(system=self,name=name) self.cpus.append(tmp_cpu) pass
def __init__(self, txrx): import memory import gpio import eder_logger self._txrx = txrx self.memory = memory.Memory() self.rpi = gpio.EderGpio() self.logger = eder_logger.EderLogger()
def main(): # how far we want to be from the target goal_distance = 1 # create the vrep environment env = vrep_env.make(goal_distance, rewarder=rewards.graduated(goal_distance)) mem = memory.Memory(MEMORY_CAPACITY, dims=2 * env.state_dim + env.action_dim + 1) # path to follow, just keep moving right #path = ["R"] * 20 + ["exit"] path = ["F"] * 7 + ["R"] * 7 + ["B"] * 7 + ["L"] * 7 + ["exit"] # moves the target we are trying to fallow mover = TargetMover(env.client_id, target_handle=env.target_handle, path=path) # tells us what actions to take actor = SimpleActor(goal_distance) cumulative_reward = 0 for ep in range(MAX_EPISODES): print("Episode: %d, Memory: %d, Average Reward: %f" % (ep, mem.pointer, cumulative_reward / (ep + 1))) # done loading sample points if mem.pointer > MEMORY_CAPACITY: break # reset environment and mover mover.reset() s = env.reset() # keep going tell mover or env say stop while True: done = mover.step() if done: break a = actor.choose_action(s) s_, r, done = env.step(a) mem.store_transition(s, a, r, s_) s = s_ cumulative_reward += r print("X Pos: %f, Y Pos : %f, Velocity: L %f R %f, Reward: %f" % (s[0], s[1], a[0], a[1], r)) if done: break #time.sleep(0.1) print("Average Reward: " + str(cumulative_reward / MAX_EPISODES)) mem.save("/tmp/learn_to_follow_mem_10k") env.stop()
def __init__(self, actor, critic, memory_size=100000000, minibatch_size=300): self.actor = actor self.critic = critic self.memory = memory.Memory(memory_size) self.minibatch_size = minibatch_size
def __init__(self,outputs,memorySize,discountFactor,learningRate,learnStart,img_rows,img_cols,img_channels): self.output_size=outputs self.memory=memory.Memory(memorySize) self.discountFactor=discountFactor self.learnStart=learnStart self.learningRate=learningRate self.img_rows=img_rows self.img_cols=img_cols self.img_channels=img_channels
def load(rom_path, config_path=None): prog_rom = extract.extract(rom_path) mem = memory.Memory() mem.map_prog_rom(prog_rom) del prog_rom program = dasm_objects.Program(mem) load_config(config_path, program.symbols, program.config) return program
def test_empty_init(self): """Test default Memory creation""" # 1. Create default Jumps object mymem = memory.Memory() # 2. Make sure it has the default values self.assertEqual(mymem.part2, False) self.assertEqual(mymem.banks, [])
def __init__(self, instructions, opcode, opcodeStr, dataval, address, arg1, arg2, arg3, arg1Str, arg2Str, arg3Str, numInstructions, destReg, src1Reg, src2Reg): self.instructions = instructions self.opcode = opcode self.opcodeStr = opcodeStr self.dataval = dataval self.address = address self.arg1 = arg1 self.arg2 = arg2 self.arg3 = arg3 self.arg1Str = arg1Str self.arg2Str = arg2Str self.arg3Str = arg3Str self.numInstructions = numInstructions self.destReg = destReg self.src1Reg = src1Reg self.src2Reg = src2Reg self.PC = 96 self.cycle = 1 ### LISTS ### self.cycleList = [0] self.R = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] self.postMemBuff = [-1, -1] # first number is value, second is instr index self.postALUBuff = [-1, -1] self.preMemBuff = [-1, -1] self.preALUBuff = [-1, -1] self.preIssueBuff = [-1, -1, -1, -1] ### OBJECTS ### self.WB = writeBack.WriteBack(self.R, self.postMemBuff, self.postALUBuff, destReg) self.cache = cache.Cache(numInstructions, instructions, dataval, address) self.ALU = alu.ALU(self.R, self.postALUBuff, self.preALUBuff, opcodeStr, arg1, arg2, arg3) self.MEM = memory.Memory(self.R, self.postMemBuff, self.preMemBuff, opcodeStr, arg1, arg2, arg3, dataval, self.numInstructions, self.cache, self.cycleList) self.issue = issue.Issue(instructions, opcodeStr, dataval, address, arg1, arg2, arg3, self.numInstructions, destReg, src1Reg, src2Reg, self.R, self.preIssueBuff, self.preMemBuff, self.postMemBuff, self.preALUBuff, self.postALUBuff) self.fetch = fetch.Fetch(instructions, opcodeStr, dataval, address, arg1, arg2, arg3, self.numInstructions, destReg, src1Reg, src2Reg, self.R, self.preIssueBuff, self.preMemBuff, self.postMemBuff, self.preALUBuff, self.postALUBuff, self.PC, self.cache) self.outputFileName = Setup.get_output_filename()
def __init__(self, endpoints, cert, ca_cert, interval, items, handlers, defaults): from urlparse import urlparse from jinja2 import Environment env = Environment() self.items = { n: (Template(n, env.from_string(n)), Template(v, env.from_string(v))) for (n, v) in items } self.handlers = { n: (Template(n, env.from_string(n)), Template(v, env.from_string(v))) for (n, v) in handlers } self.interval = interval parsed_endpoints = map(urlparse, endpoints.split(',')) if len(parsed_endpoints) <= 0: raise ValueError("Endpoint parameter is empty or missing") scheme = parsed_endpoints[0].scheme if scheme == "stdout": self.client = StdoutClient() else: self.client = EtcdClient( tuple( map( lambda e: (e.hostname, e.port if e.port else 80 if e.scheme == "http" else 443), parsed_endpoints)), scheme, cert, ca_cert) self.defaults = TemplateDict( {n: Template(v, env.from_string(v)) for (n, v) in defaults}) self.context = Context() import cpu import memory import disk import host import systemd import os_support self.context.add_module(cpu.Cpu()) self.context.add_module(memory.Memory()) self.context.add_module(disk.Disk()) self.context.add_module(host.Host()) self.context.add_module(systemd.Systemd()) self.context.add_module(os_support.OS()) for n in self.handlers: self.client.add_handler(self.context, self.defaults, n, *(self.handlers[n]))
def __init__(self, inputs, outputs, memorySize, discountFactor, learningRate, learnStart, maxMargin): self.sess = k_b.get_session() self.input_size = inputs self.output_size = outputs self.memory = memory.Memory(memorySize) self.discount_factor = discountFactor self.learning_rate = learningRate self.learn_start = learnStart self.max_margin = maxMargin
def create_database(self): if os.path.exists("../Database/episodes.npz"): print("Database exists!") self.__memory = memory.Memory() else: self.__memory = memory.Memory(DATABASE_SIZE) for i in range(DATABASE_SIZE): if i % 1000 == 0: print("{}% completed".format(i / 100)) if (self.__done): self.reset_environment() action = self.__agent.action_space.sample() next_obs, reward, done = self.execute_action(action) # only include non-terminal states # assuming game is never ending if not done: self.__memory.append( [self.__obs, action, next_obs, reward]) self.__memory.save_database()
def __init__(self, obs_space, action_space,memorySize, discountFactor, \ learningRate,useTargetNetwork): self.memory = memory.Memory(memorySize) self.discountFactor = discountFactor self.learningRate = learningRate self.useTargetNetwork = useTargetNetwork self.count_steps = 0 self.obs_space = obs_space self.action_space = action_space self.initNetworks()
def setup_computer(self, start_ip): """Build the computer.""" self.reg = cpu.Registers() self.mem = memory.Memory() self.alu = cpu.ArithmeticLogicUnit() self.decoder_obj = decoder.Decoder(self.reg, self.mem, self.alu) self.clock = cpu.Clock(self.reg, self.decoder_obj) self.reg.ip = start_ip
def test_save_load(): mem = memory.Memory(10, dims=2 * STATE_DIM + ACTION_DIM + 1) for i in range(100): s = i % 4 a = [i % 3, i % 3] r = i % 2 - 1 s_ = s + 1 mem.store_transition(s, a, r, s_) saved_data = mem.data mem.save("/tmp/test_mem_save") mem = memory.Memory(12, dims=2 * STATE_DIM + ACTION_DIM + 1) mem.store_transition(1, [1, 1], 1, 1) mem.load("/tmp/test_mem_save") assert np.array_equal(saved_data, mem.data) # memory is full should be pointing to the end assert mem.pointer == len(mem.data) - 1 assert mem.capacity == 10
def __init__(self, N_ACTIONS, memory_path=None): if memory_path == None: ### MEMORY HYPERPARAMETERS # Number of experiences the Memory can keep self.memory = memory.Memory(1000000) else: self.memory = pkl.load(open(memory_path, 'rb')) self.model = dqn.DQN() # Set up tensorboard self.model.set_up_board()
def setUp(self): self.reg = cpu.Registers() self.mem = memory.Memory() self.alu = cpu.ArithmeticLogicUnit() self.mem_if = decoder.MemoryInterface(self.mem) self.instr = decoder.Instructions(reg=self.reg, mem=self.mem, alu=self.alu) self.mem.write(ADDR1, VAL1)
def setup_computer(): """Build the computer.""" reg = cpu.Registers() mem = memory.Memory() alu = cpu.ArithmeticLogicUnit() decoder_obj = decoder.Decoder(reg, mem, alu) clock = cpu.Clock(reg, decoder_obj) reg.ip = ADDR(0x20) return mem, clock
def interpret(ast : List[Node]) -> memory.Memory: """Interprets an AST Tree into a memory object Args: ast (List): An AST Tree Returns: memory.Memory: The memory object with the interpreted AST tree inside of it """ mem = memory.Memory() return interpret_rec(ast, mem)
def test_empty_init(self): "Test the default Memory creation" # 1. Create default Memory object myobj = memory.Memory() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(myobj.age, None) self.assertEqual(myobj.turn, 0) self.assertEqual(myobj.numbers, {})
def __init__(self): self.logger = logging.getLogger('Borg.Brain.BodyController') self.memory = memory.Memory() self.emergency = False self.use_marytts = USE_MARYTTS self.use_ivona = IVONA self.remote_speech = False if self.remote_speech: self.ivona_pub = rospy.Publisher('/ivona_speech', String) print "[BodyController] using remote ivona speech." elif self.use_ivona: pygame.init()
def test_text_init(self): """Test Memory creation from text""" # 1. Create Jumps object from text mymem = memory.Memory(text=aoc_06.from_text(P1_EXAMPLES_TEXT)[0]) # 2. Make sure it has the specified values self.assertEqual(mymem.part2, False) self.assertEqual(len(mymem.banks), 4) self.assertEqual(mymem.banks, [0, 2, 7, 0]) # 3. Check methods self.assertEqual(mymem.cycle_until_seen(verbose=False, limit=9), 5)
def basic_test(address): prog = extract.extract("smb.nes") mem = memory.Memory() mem.map_prog_rom(prog) del prog for _ in range(0, 50): instruction = dasm.disassemble_instruction(mem, address) assert instruction.address == address address += instruction.size print("0x{addr:04X}: {asm}".format(addr=instruction.address, asm=instruction.assembly_string))
def train(session, graph, saver): ri = RunInfo( session=session, graph=graph, memory=m.Memory(), ) for epoch_idx in range(1, config.NUM_EPOCHS + 1): train_epoch(ri, epoch_idx) print("Saving!") saver.save(session, config.CHECKPOINT_FILENAME) if epoch_idx % config.NUM_EPOCHS_PER_EVAL == 0: play.evaluate_performance(session, graph, training_mode=False)
def __init__(self, factory=None, params=None, ds=None): if self.__class__ == Workspace and not factory: import memory mem = memory.Memory() self._store = mem._store else : if ds: self._store = ds elif factory: self._store = factory.createDataStore(params) else: raise Exception('Workspace requires a data store or a factory') self.factory = factory self.params = params
def setUp(self): params = configparse.ParameterDict() self.IP = '192.168.0.1' params.add_option('general', 'robot_ip', self.IP ) params.add_option('vision_controller', 'video_source_name', 'test') params.add_option('general', 'starting_behavior', 'test1') params.add_option('speech_controller', 'modules', '') #no speech modules, we'll add a test socket later on params.add_option('speech_controller', 'start_speech', 'true') #no speech modules, we'll add a test socket later on params.add_option('body','number_of_naos','0') params.add_option('body','number_of_pioneers','0') self.mem = memory.Memory() self.mem.clear() self.si = sensorintegrator.SensorIntegrator(params)
def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the puzzle solver solver = memory.Memory(part2=True, text=input_lines[0]) # 2. Determine number of redistribution cycles solution = solver.cycle_until_seen(verbose=args.verbose, limit=args.limit) if solution is None: print("No configuration repeats") else: print("A previous configuration was seen in %d redistribution cycles" % (solution)) # 3. Return result return solution is not None