Пример #1
0
    def read_output(self, settings):
        # output_file = open(self.output_dir + "/output/banjo/top.graph.txt", 'r')

        output_file = open(self.output_dir + "./output/banjo/top.graph.txt", "r")

        import re

        network = []
        for i in range(len(self.gene_list)):
            row = []
            for j in range(len(self.gene_list)):
                row.append(0)
            network.append(row)

        lines = output_file.readlines()

        for i, line in enumerate(lines):
            line = line.strip()
            if line != "" and line[0] == '"':
                line = re.sub(r"\(.*?\)", "", line).replace('"', "").replace(";", "").strip().replace("->", "")
                # print line

                ls = line.split()
                edge = ls[1]
                gene = ls[0]
                network[int(gene)][int(edge)] = 1
                network[int(edge)][int(gene)] = 1
        net = Network()
        net.read_netmatrix(network, self.gene_list)
        self.network = net
Пример #2
0
def l4_sendto(node, dest_nid, data):

	# get port table for this node and set values for destination target
	PortTable = node.GetPortTable()
	for link in PortTable:
		info = PortTable[link]

		if info[0] == dest_nid:
			dest_port = info[2]

	# get md5 hash of data for checksum
	m = hashlib.md5()
	m.update(data)
	checksum = m.hexdigest()


	# build datagram
	frame = {}
	frame['source_nid'] = node.GetNID()
	frame['source_port'] = node.GetPort()
	frame['destination_nid'] = dest_nid
	frame['destination_port'] = dest_port
	frame['sequence_number'] = 1
	frame['ack_number'] = 1
	frame['window_size'] = 15
	frame['checksum'] = checksum
	frame['data'] = data

	# encode payload
	payload = json.dumps(frame)

	Network.l3_sendto(node, dest_nid, payload)
Пример #3
0
    def read_output(self,settings):
      # Code to write for collecting the output files from the algorithm, writes to the
      # output list in the object
      # What we want to do here is get the prediction rate on the last time
      # point and the network so we can compare it against a gold std.
      # This file is a bunch of zscores, so we have to load the cutoff we want
      output_file = open(self.output_dir + "/output/ranked_edges.txt", 'r')
      topn = None
      if "top_n_edges" in settings["genie3"].keys():
        topn = settings["genie3"]["top_n_edges"]
      else:
        topn = len(self.gene_list)
      zscores = []
      for line in output_file:
          gene1, gene2, zscore = line.split()
          zscore = float(zscore)
          zscores.append((gene1, gene2, zscore))
      zscores = sorted(zscores, key=lambda zscore: abs(zscore[2]), reverse=True)

      self.zscores = zscores[:]
      network = []

      #for i,zscore in enumerate(zscores):
          #if i < topn:
            #gene1, gene2, zscore = zscore
            #zscores[i] = (gene1, gene2, 1)
          #else:
            #gene1, gene2, zscore = zscore
            #zscores[i] = (gene1, gene2, 0)
      net = Network()
      net.read_networklist(zscores)
      net.gene_list = self.gene_list
      self.network = net

      return self.zscores
Пример #4
0
def launch(name):
    # Game
    game = Game.Game()
    
    # Try to connect 
    socket = Network.connect("192.168.0.3", 8080)
    Protocol.setName(socket, name)
    
    # Thread for inputs
    q = queue.Queue()
    t = None
    startThread(t, q)
    
        
    # Main event loop
    data = bytes()
    while True:
        # Send commands
        try:  
            line = q.get_nowait()
            interpretCommand(line, socket)
        except queue.Empty:
            pass
        
        # Get order
        order = Network.getOrder(socket)
        
        try:
            if order is not None:
                Protocol.manageOrder(socket, order, game)
        except Protocol.ByeException:
            break    
    
    socket.close()
Пример #5
0
def memberVarience(population, alpha):
    diffSum = 0.0
    for member in population:
        mg = Network.vectorizeMatrix(member.genome)
        ag = Network.vectorizeMatrix(alpha.genome)
        diffSum = diffSum + Network.outputError(mg, ag)
    return diffSum / len(population)
 def getRooms(self):
     if (self.ipResidence == None):
         self.ipResidence = util.getResidenceIp()
     if (self.ipResidence != "Residence is offline"):
         tmp = util.httpGetRequest(self.ipResidence, 5432,"getRooms")
         self.rooms = json.loads(tmp).keys()
     else:
         self.ipResidence = None
 def run(self):
     """Método que roda as funções bloqueantes da classe Servidor Bluetooth
     """
     while True:
         self.serverBlue.waitRequisition()
         self.room = self.serverBlue.receiveInformation()
         print("passei")
         params = {"nameRoom": self.room}
         util.httpPostRequest(self.ipResidence, 5432, "setRoomOfControl", params)
Пример #8
0
 def handle_help(command):
   mainString = "Try out the website! {}\n(Password: "******")"
   try:
     return mainString.format(Network.getIPAddress())
   except RuntimeError:
     IP = Network.readIPFile()
     if IP:
       return mainString.format(Network.readIPFile() + " (hopefully...)")
     return mainString.format("I have no idea what it is, but it probably exists! (Go yell at Daniel)")
Пример #9
0
    def read_output(self, settings):
        # Code to write for collecting the output files from the algorithm, writes to the
        # output list in the object
        # What we want to do here is get the prediction rate on the last time
        # point and the network so we can compare it against a gold std.
        output_file = self.output_dir + "/output/" + "/nir_output.txt"

        net = Network()
        net.read_netmatrix_file(output_file, self.gene_list)
        self.network = net
def testUpdate():
    
    input = [0.35,0.9] 
    MyNetwork = Network( (2,2,1) )
    
    MyNetwork.layers[0].nodes = np.array(input)
    MyNetwork.layers[1].weights = np.array([ [0.1,0.8],[0.4,0.6] ])
    MyNetwork.layers[2].weights = np.array([ [0.3,0.9] ])
       
    MyNetwork.update()      
 def exit(self):
     """Método que encerra a conexão com Residência
     """
     params = {"nameRoom": self.room.getName()}
     try:
         print util.httpPostRequest(self.ipResidence, 5432, "removeRoom", params)
     except AttributeError:
         print "Parametros insuficientes"
     cherrypy.engine.exit()
     os._exit(0)
Пример #12
0
	def sendMsg(self, to_nick, format, *args):
		#sends a message to a nick as this client
		#eventually, will use the client's preferred notification method, for now it's PRIVMSGs
		#Network.sendMsg(IRCMessage(":", self.nick, "PRIVMSG", to_nick, format % args))
		if(isinstance(format, types.StringTypes)):
			text=format % args
		else:
			text=format
		
		for line in IRCMessage.wrapText(text):
			Network.sendMsg(IRCMessage(":", self.nick, "PRIVMSG", to_nick, line))
Пример #13
0
    def testHandshake(self):
        s = TestServer()
        c = TestConnection()
        c.connect("localhost")

        c.sendPacket("moikka")

        Network.communicate(100)
        client = s.clients.values()[0]
        assert client.packet == "moikka"
        assert client.id == 1
    def read_output(self,settings):
        # Code to write for collecting the output files from the algorithm, writes to the
      # output list in the object
      # What we want to do here is get the prediction rate on the last time
      # point and the network so we can compare it against a gold std.
      # This file is a bunch of zscores, so we have to load the cutoff we want
      output_file = self.output_dir + "/output/inferelator_output.csv"

      net = Network()
      net.read_netmatrix_file(output_file, self.gene_list)
      self.network = net

      return self.network
    def powerEquipmentsNewRoom(self, roomConfiguration, nameRoom):
        """Método que liga os equipamentos do novo cômodo
        :Param data: Dicionário contendo os aparelhos e os comandos
        :Type data: Dicionário
        :Param nameRoom: Nome do novo cômodo
        :Type nameRoom: String
        """
        infoRoom = self.__searchRoom(nameRoom.lower())
        ip = infoRoom[0]
        port = infoRoom[1]

        params = {"configuration": str(roomConfiguration)}
        method = "setNewConfiguration"
        util.httpPostRequest(ip, port, method, params)
Пример #16
0
    def run(self, name, datafiles, goldnet_file):
        import numpy

        os.chdir(os.environ["gene_path"])

        datastore = ReadData(datafiles[0], "steadystate")
        for file in datafiles[1:]:
            datastore.combine(ReadData(file, "steadystate"))
        datastore.normalize()

        settings = {}
        settings = ReadConfig(settings)
        # TODO: CHANGE ME
        settings["global"]["working_dir"] = os.getcwd() + '/'

        # Setup job manager
        print "Starting new job manager"
        jobman = JobManager(settings)

        # Make GENIE3 jobs
        genie3 = GENIE3()
        genie3.setup(datastore, settings, name)

        print "Queuing job..."
        jobman.queueJob(genie3)

        print jobman.queue
        print "Running queue..."
        jobman.runQueue()
        jobman.waitToClear()

        print "Queue finished"
        job = jobman.finished[0]
        print job.alg.gene_list
        print job.alg.read_output(settings)
        jobnet = job.alg.network
        print "PREDICTED NETWORK:"
        print job.alg.network.network
        print jobnet.original_network

        if goldnet_file != None:
            goldnet = Network()
            goldnet.read_goldstd(goldnet_file)
            print "GOLD NETWORK:"
            print goldnet.network
            print jobnet.analyzeMotifs(goldnet).ToString()
            print jobnet.calculateAccuracy(goldnet)

        return jobnet.original_network
Пример #17
0
def create_empty_network():
    """
    Args:
        None
    Returns:
        hidden_layers:  list of Neuron object lists representing the hidden layers
        output_layer:   list of Neuron objects representing the output layer
    Notes:

    """
    hidden_layers = []
    for item in range(const.NUM_HIDDEN_LAYERS):
        hidden_layers.append(Network.make_hidden_layer())
    output_layer = Network.make_output_layer()
    return hidden_layers, output_layer
Пример #18
0
 def __init__(self,speed=None,health=None,max_health=None,dmg=None,armor=None,size=None,brain=None,name="Yuval",location=None,turns=0):
     if speed == None:
         speed = attribute()
     if health == None:
         health = attribute()
     if max_health == None:
         max_health = attribute()
     if dmg == None:
         dmg = attribute()
     if armor == None:
         armor = attribute()
     if size == None:
         size = attribute()
     if location == None:
         location = [400,400]
     self.location = location
     if brain == None:
         brain = [3,2,3]
     brain1 = Network.network(brain)
     self.brain = brain1
     self.speed = speed
     self.health = health
     self.max_health = max_health
     self.dmg = dmg
     self.armor = armor
     self.size = size
     self.name = name
     self.speed.value = 20
     self.turns = turns
Пример #19
0
    def search_by_tvrage_string(self):
        """
        Search using TVRage's search API, with a string show name input.
        If it matches exactly (ignoring hyphens), then consider it a 100% match.
        Otherwise, score each potential match starting from the start_score.
        """
        for show_name in self.show_names:
            url = tvrage.SEARCH_URL % String.Quote(show_name, True)
            xml = Network.fetch_xml(url)

            i = 0
            for show_xml in xml.xpath("//show"):
                i += 1
                result_show = str(show_xml.xpath("./name")[0].text)

                if tvrage.sanitize_show_name(show_name) == tvrage.sanitize_show_name(result_show):
                    Log("Found exact match in title %s" % result_show)
                    score = 100
                else:
                    score = self.start_score - i

                nextResult = MetadataSearchResult(id=str(show_xml.xpath("./showid")[0].text),
                                                  name=result_show,
                                                  year=show_xml.xpath("./started")[0].text,
                                                  score=score,
                                                  lang=self.lang)
                self.results.Append(nextResult)
                Log(repr(nextResult))
def testBackprop2():
    
    input = [1,0,1,0] 
    MyNetwork = Network( (4,3,2) )
    
    MyNetwork.layers[0].nodes = np.array(input)
    MyNetwork.layers[1].weights = np.array([ [0.1,0.8],[0.4,0.6] ])
    MyNetwork.layers[2].weights = np.array([ [0.3,0.9] ])
       
    print MyNetwork.update()
    for i in xrange(500):
        MyNetwork.backprop([0.5])
        MyNetwork.update() 
    print MyNetwork.update()      
Пример #21
0
def tryConnect():
    global IsConnected
    try:
        networkCheckCount = 0
        while (
            Network.isConnected() == False and networkCheckCount < 5
        ):  # we check a number of times to give the network more time to start up.
            networkCheckCount = networkCheckCount + 1
            sleep(2)
        if Network.isConnected() == False:
            logging.error("failed to set up network connection")
        else:
            # make certain that the device & it's features are defined in the cloudapp
            IOT.connect()
            # IOT.addAsset(TempSensorPin, TempSensorName, "temperature", False, "number", "Secondary")
            # IOT.addAsset(WaterLevelSensorPin, WaterLevelSensorName, "Water level", False, "number", "Secondary")
            IOT.addAsset(LightsRelaisPin, LightsRelaisName, "Turn the lights on/off", True, "boolean", "Primary")
            IOT.addAsset(WaterRelaisPin, WaterRelaisName, "Turn the water flow on/off", True, "boolean", "Primary")
            IOT.addAsset(
                ConfigSeasonId,
                ConfigSeasonName,
                "Configure the season",
                True,
                "{'type': 'string','enum': ['grow', 'flower']}",
                "Config",
            )
            try:
                season = IOT.getAssetState(ConfigSeasonId)
            except:
                logging.exception("failed to get asset state")
            LoadConfig(
                season
            )  # load the cloud settings into the appbefore closing the http connection. otherwise this call fails.
            IOT.subscribe()  # starts the bi-directional communication
            sleep(
                2
            )  # wait 2 seconds until the subscription has succeeded (bit of a hack, better would be to use the callback)
            IsConnected = True
            IOT.send(
                str(LightRelaisState).lower(), LightsRelaisPin
            )  # provide feedback to the platform of the current state of the light (after startup), this failed while loading config, cause mqtt is not yet set up.
            IOT.send(str(WaterRelaisState).lower(), WaterRelaisPin)
    except:
        logging.exception("failed to set up the connection with the cloud")
        IsConnected = False
Пример #22
0
def avgSigma(population):
    sigSum = 0.0
    sigCount = 0
    for member in population:
        ms = Network.vectorizeMatrix(member.sigmas)
        for singleSigma in ms:
            sigSum = sigSum + singleSigma
            sigCount = sigCount + 1
    return sigSum / sigCount
Пример #23
0
	def introduce(self):
		svr=Server.getLinkedServer()
		msg=None
		if(svr.protoctl["NICKv2"]):
			if(svr.protoctl["CLK"]): #NICKv2 and CLK
				if(svr.protoctl["NICKIP"]): #NICKv2 and CLK and NICKIP
					msg=IRCMessage(None, None, "nick", self.nick, self.hopcount, self.timestamp, self.username, self.hostname, self.server, self.servicestamp, self.usermodes, self.virtualhost, self.cloakedhost, self.nickipaddr, self.realname)
				else: #NICKv2 and CLK
					msg=IRCMessage(None, None, "nick", self.nick, self.hopcount, self.timestamp, self.username, self.hostname, self.server, self.servicestamp, self.usermodes, self.virtualhost, self.cloakedhost, self.realname)
			else: #NICKv2 but not CLK
				if(svr.protoctl["NICKIP"]): #NICKv2 and NICKIP
					msg=IRCMessage(None, None, "nick", self.nick, self.hopcount, self.timestamp, self.username, self.hostname, self.server, self.servicestamp, self.usermodes, self.virtualhost, self.nickipaddr, self.realname)
				else: #nickv2, no clk, no nickip
					msg=IRCMessage(None, None, "nick", self.nick, self.hopcount, self.timestamp, self.username, self.hostname, self.server, self.servicestamp, self.usermodes, self.virtualhost, self.realname)
		else: #normal
			msg=IRCMessage(None, None, "nick", self.nick, self.hopcount, self.timestamp, self.username, self.hostname, self.server, self.servicestamp, self.realname)
		
		Network.sendMsg(msg)
    def read_output(self,settings):
      import scipy
      # Code to write for collecting the output files from the algorithm, writes to the
      # output list in the object
      # What we want to do here is get the prediction rate on the last time
      # point and the network so we can compare it against a gold std.
      # This file is a bunch of zscores, so we have to load the cutoff we want
      co_output = scipy.io.loadmat(self.output_dir + "/output/" + \
              "/convex_optimization_output.mat")

      self.raw_network = co_output["A"].tolist()


      net = Network()
      net.read_netmatrix(self.raw_network, self.gene_list)
      self.network = net

      return self.network
    def notificaComodoControle(self, nameRoom, status):
        """Método que notifica ao cômodo se o controle se encontra ou não dentro dele
        :Param nameRoom: Nome do cômodo
        :Type nameRoom: String
        :Param status: String do boolean correspondente a sua presença
        :Type status: String
        """
        infoRoom = self.__searchRoom(nameRoom.lower())
        print("Passandoo 1")
        if(infoRoom != False):
            ip = infoRoom[0]
            port = infoRoom[1]
            print("Passandoo 2")

            params = {"isFound" : status}
            method = "controlIsFound"
            
            print("Passandoo 3")
            util.httpPostRequest(ip, port, method, params)
Пример #26
0
    def exchange(self):
        """ This is the main method, is where the individuals
        are exchanged """

        if not self.isReady():
            return

        # Client section --------------------------------------
        # How many will migrate ?
        pool = self.selectPool(self.getNumIndividuals())

        for individual in pool:
            # (code, group name, individual)
            networkObject = (Consts.CDefNetworkIndividual,
                             self.getGroupName(), individual)
            networkData = Network.pickleAndCompress(
                networkObject, self.getCompressionLevel())
            # Send the individuals to the topology
            self.clientThread.addData(networkData)

        # Server section --------------------------------------
        pool = []
        while self.serverThread.isReady():
            # (IP source, data)
            networkData = self.serverThread.popPool()
            networkObject = Network.unpickleAndDecompress(networkData[1])
            # (code, group name, individual)
            pool.append(networkObject)

        # No individuals received
        if len(pool) <= 0:
            return

        population = self.GAEngine.getPopulation()

        for i in xrange(self.getNumReplacement()):
            if len(pool) <= 0:
                break
            choice = rand_choice(pool)
            pool.remove(choice)

            # replace the worst
            population[len(population) - 1 - i] = choice[2]
Пример #27
0
def groupDailyDuties():
  log.group("Starting daily duties!")
  for group in getGroupList(MainGroup): #Go through all the MainGroups to check for events that have ended
    group.checkForEndedEvents()
    
  if Network.hasIPChanged():
    log.group("IP has changed! Updating bots of all groups")
    for group in getGroupList():
      if group.bot:
        group.handler.updateBots(group.bot)
        
    def powerOffEquipmentsRoom(self):
        """Método que desliga todos os equipamentos do cômodo
        """
        for roomTemp in self.rooms.items():
            print("---------------------------------", roomTemp)
            nameRoomTemp = roomTemp[0]
            ipRoomTemp = roomTemp[1][0]
            portRoomTemp = roomTemp[1][1]
            method = "getNumberOfPeoples"
            result = util.httpGetRequest(ipRoomTemp, portRoomTemp, method)

            if(result == False):
                self.removeRoom(nameRoomTemp)
            elif(result == "0"):
                params = {"equipment": "all", "command": "poweroff"}
                method = "controlEquipment"
                util.httpPostRequest(ipRoomTemp, portRoomTemp, method, params)

        time.sleep(15)
        self.powerOffEquipmentsRoom()
 def startThreadResidence(self):
     self.pbar.show()
     self.residenceButton.set_sensitive(False)
     self.pbar.set_text("Iniciando residência")
     status = util.getResidenceIp()
     self.pbar.hide()
     self.clickedResidence = True
     if (status == "Residence is offline"):
         self.residenceButton.set_label("Residência iniciada")
         os.system("python " + os.path.abspath("Residencia/server.py"))
     else:
         self.residenceButton.set_label("Residência iniciada na rede")
Пример #30
0
    def read_output(self,settings):
        # Code to write for collecting the output files from the algorithm, writes to the
      # output list in the object
      # What we want to do here is get the prediction rate on the last time
      # point and the network so we can compare it against a gold std.
      # This file is a bunch of zscores, so we have to load the cutoff we want
      output_file = open(self.output_dir + "/output/mcz_output.txt", 'r')

      output_file = output_file.readlines()
      zscores = []
      for g1, line in enumerate(output_file[1:]):
          for g2, val in enumerate(line.split('\t')[1:]):
              zscores.append((self.gene_list[g2], self.gene_list[g1], float(line.split()[1:][g2])))
      topn = settings["mcz"]["top_n_edges"]
      #for line in output_file:
          #gene1, gene2, zscore = line.split()
          #zscore = float(zscore)
          #zscores.append((gene1, gene2, zscore))
      zscores = sorted(zscores, key=lambda zscore: abs(zscore[2]), reverse=True)

      self.zscores = zscores[:]
      network = []

      #for i,zscore in enumerate(zscores):
          #if i < topn:
            #gene1, gene2, zscore = zscore
            #if zscore > 0:
                #zscores[i] = (gene1, gene2, 1)
            #if zscore < 0:
                #zscores[i] = (gene1, gene2, -1)

          #else:
            #gene1, gene2, zscore = zscore
            #zscores[i] = (gene1, gene2, 0)
      net = Network()
      net.read_networklist(zscores)
      net.gene_list = self.gene_list
      self.network = net

      return self.network
Пример #31
0
def ewc_train(network,
              optimizer,
              dataset,
              loader,
              ewc,
              lam,
              num_epochs,
              type="ewc",
              test=None):
    for epoch in range(num_epochs):
        total_loss = 0
        total_correct = 0

        for batch in loader:
            images, labels = batch

            preds = network(images)
            loss1 = F.cross_entropy(preds, labels)

            if type == "L2":
                loss2 = lam * ewc.penalty_l2(network)
            else:
                loss2 = lam * ewc.penalty_ewc(network)

            loss = loss1 + loss2

            optimizer.zero_grad()
            loss.backward()
            optimizer.step()

            total_loss += loss.item()
            total_correct += Network.get_num_correct(preds, labels)

        accuracy = (total_correct / len(dataset)) * 100
        print(
            f'epoch: {epoch}, loss: {total_loss}, total_correct: {total_correct} / {len(dataset)}, --> {Fore.LIGHTCYAN_EX}Accuracy: {accuracy}{Style.RESET_ALL}'
        )

        #test is for printing epoch accuracies of past tasks
        if test is not None:
            for t in test:
                print(
                    f"\t\t\t\t {Fore.LIGHTGREEN_EX}Testing back... {Network.testing(network, t[0], t[1])}{Style.RESET_ALL}"
                )
Пример #32
0
    def __init__(self):
        super(Window, self).__init__()
        self.screen = self.get_screen()
        self.set_accept_focus(False)
        self.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
        self.override_background_color(Gtk.StateType.NORMAL,
                                       Gdk.RGBA(0, 0, 0, 1))

        self.overlay = Gtk.Overlay()
        self.image = Gtk.Image()
        self.overlay.add(self.image)
        self.add(self.overlay)

        self.headerbar = Gtk.HeaderBar()
        self.headerbar.set_valign(Gtk.Align.END)
        self.headerbar.set_halign(Gtk.Align.FILL)
        style = self.headerbar.get_style_context()
        style.add_class("frame")
        style.add_class("action-bar")

        self.headerbar.pack_start(GnoMenu.Button())
        self.headerbar.pack_start(Gtk.Separator.new(Gtk.Orientation.VERTICAL))
        self.headerbar.pack_end(Session.Button())
        self.headerbar.pack_end(Gtk.Separator.new(Gtk.Orientation.VERTICAL))
        self.headerbar.pack_end(Sound.Button())
        self.headerbar.pack_end(Network.Button())
        self.overlay.add_overlay(self.headerbar)

        self.move(0, 0)
        self.resize_to_geometry(self.screen.get_width(),
                                self.screen.get_height())
        self.show_all()

        try:
            self.update_strut()
        except:
            pass

        try:
            self.update_background()
        except:
            pass

        GObject.timeout_add(100, self.update_clock)
Пример #33
0
def main():
    global args
    global best_acc
    best_acc = 0
    args = parse_arguments()
    transfrom = get_transform()
    train_dataset = Dataset.TrackData_SL(args.train_data, transfrom)
    test_dataset = Dataset.TrackData_SL(args.test_data, transfrom)
    train_loader = DataLoader(train_dataset,
                              num_workers=args.num_workers,
                              shuffle=True,
                              batch_size=args.batch_size)
    test_loader = DataLoader(test_dataset,
                             num_workers=args.num_workers,
                             shuffle=False,
                             batch_size=args.batch_size)

    net = Network.Tracknet()
    net.cuda()
    optimizer = torch.optim.Adam(net.parameters(), args.lr)

    start_epoch = 0
    if args.resume:
        if args.resume:
            ckpt = torch.load(args.resume)
            net.load_state_dict(ckpt['state_dict'])
            optimizer.load_state_dict(ckpt['optimizer'])
            best_acc = ckpt['best_accuracy']
            start_epoch = ckpt['epoch']

    for e in range(start_epoch, args.max_epochs):
        train(e, net, optimizer, train_loader)
        if e % args.test_freq == 0:
            acc = test(e, net, test_loader)
            is_best = acc > best_acc
            best_acc = max(best_acc, acc)
            # save model
            save_checkpoint(
                {
                    'epoch': e + 1,
                    'state_dict': net.state_dict(),
                    'best_accuracy': best_acc,
                    'optimizer': optimizer.state_dict()
                }, is_best)
Пример #34
0
    def __init__(self):
        logging.basicConfig(format="%(levelname)s (%(asctime)s): %(message)s", datefmt="%I:%M:%S %p", level=logging.INFO, filename="/var/tmp/R2D2.log")        
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)
        atexit.register(self.Exit)
        self.MCP3008 = MCP3008(spi=SPI.SpiDev(0, 0))
        self.Voltage = VoltageDivider(self.MCP3008, 0, 984.0, 101.0)
        self.Current = ACS711EX(self.MCP3008, 1)
        self.BrightnessControl = Potentiometer(self.MCP3008, 2)
        self.Battery = LiPo(self.Voltage, self.Current, 6, 10)
        
        self.DomeLightsRelay = self.Relay1 = Relay(16)
        self.DomeServosRelay = self.Relay2 = Relay(17)
        self.DomeMotorRelay = self.Relay3 = Relay(18)
        self.Relay4 = Relay(19)
        self.Relay5 = Relay(20)
        self.SoundRelay = self.Relay6 = Relay(21)
        self.BodyServosRelay = self.Relay7 = Relay(22)
        self.BodyLightsRelay = self.Relay8 = Relay(23)
        self.Relay9 = Relay(24)
        self.Relay10 = Relay(25)
        self.Relay11 = Relay(26)
        self.Relay12 = Relay(27)

        self.Network = Network()
        
        self.Head = HeadMotor(self.DomeMotorRelay)
        self.Sound = Sound()
        self.StatusDisplay = StatusDisplay(self)

        self.FrontLogicDisplay = FrontLogicDisplay(self.DomeLightsRelay)
        self.RearLogicDisplay = RearLogicDisplay(self.DomeLightsRelay)
        self.FrontProcessStateIndicator = FrontProcessStateIndicator(self.DomeLightsRelay)
        self.RearProcessStateIndicator = RearProcessStateIndicator(self.DomeLightsRelay)
        self.FrontHoloProjector = FrontHoloProjector(self.DomeLightsRelay)
        self.TopHoloProjector = TopHoloProjector(self.DomeLightsRelay)
        self.RearHoloProjector = RearHoloProjector(self.DomeLightsRelay)
        self.MagicPanel = MagicPanel(self.DomeLightsRelay)
        self.LifeFormScanner = LifeFormScanner(self.DomeServosRelay)
        self.DomePanels = Panels()
        
        self.BodyServos = Maestro("00126418")
        self.LeftUtilityArm = MaestroServo(self.BodyServos, 16, 2390, 1520, 20, 1)
        self.RightUtilityArm = MaestroServo(self.BodyServos, 17, 2390, 1520, 20, 1)
Пример #35
0
	def __init__(self,rng, max_hidden_units, size=50, limittup=(-1,1)):
		self.dimtup = pimadataf.get_dimension()
		rest_set, test_set = pimadataf.give_data()
		tup = pimadataf.give_datainshared()
		self.rng=rng
		self.size = size
		self.max_hidden_units = max_hidden_units
		self.list_chromo = self.aux_pop(size, limittup) #a numpy array
		self.fits_pops = []
				
		self.trainx = rest_set[0]
		self.trainy = rest_set[1]
		self.testx = test_set[0]
		self.testy = test_set[1]
		
		self.strainx, self.strainy = tup[0]
		self.stestx, self.stesty = tup[1]
		self.net_err = Network.Neterr(inputdim=self.dimtup[0], outputdim=self.dimtup[1], arr_of_net=self.list_chromo, trainx=self.trainx, trainy=self.trainy, testx=self.testx, testy=self.testy,strainx=self.strainx, strainy=self.strainy, stestx=self.stestx, stesty=self.stesty)
		self.net_dict={} #dictionary of networks for back-propagation, one for each n_hid
def Build_network(session, robot_num):
    '''
    Network_set = []
    for i in range(robot_num - 1):
        Network_set.append(Network.three_robot_network(str(10+i+1)))
    for item in Network_set:
        item.restore_parameter(session, three_robot_Network_Path)
    with tf.name_scope('Smallest_value'):
        smaller_value_list = [Network_set[0].value]
        for i in range(len(Network_set)-1):
            smaller_value_list.append(tf.minimum(smaller_value_list[i], Network_set[i+1].value))
        smallest_value = smaller_value_list[-1]
    '''
    Network_set = [Network.Three_robot_network('123')]
    
    for item in Network_set:
        item.restore_parameter(session, three_robot_Network_Path)
    smallest_value = Network_set[0].value
    return smallest_value, Network_set
Пример #37
0
	def __init__(self,rng, max_hidden_units, size=5, limittup=(-1,1)):
		self.dimtup = pimadataf.get_dimension()
		rest_set, test_set = pimadataf.give_data()
		restx=rest_set[0]
		resty=rest_set[1]
		testx=test_set[0]
		testy=test_set[1]
		resty=np.ravel(resty)
		testy=np.ravel(testy)
		self.rng=rng
		self.size = size
		self.max_hidden_units = max_hidden_units
		self.list_chromo = self.aux_pop(size, limittup) #a numpy array
		self.fits_pops = []
		restn=538										#a flaw here ,one has to know no. of datapoints in both set before opening it(inside program)
		testn=230		
		print("here you",rest_set[1].shape)
		self.rest_setx=tf.Variable(initial_value=np.zeros((restn,self.dimtup[0])),name='rest_setx',dtype=tf.float64)
		self.rest_sety=tf.Variable(initial_value=np.zeros((restn,)),name='rest_sety',dtype=tf.int32)
		self.test_setx=tf.Variable(initial_value=np.zeros((testn,self.dimtup[0])),name='rest_sety',dtype=tf.float64)
		self.test_sety=tf.Variable(initial_value=np.zeros((testn,)),name='test_sety',dtype=tf.int32)
		if not os.path.isfile('/home/robita/forgit/neuro-evolution/05/state/tf/indep_pima/input/model.ckpt.meta'):
			

			

			rxn=self.rest_setx.assign(restx)
			ryn=self.rest_sety.assign(resty)
			txn=self.test_setx.assign(testx)
			tyn=self.test_sety.assign(testy)
			var_lis=[self.rest_setx,self.rest_sety,self.test_setx,self.test_sety]
			nodelis=[rxn,ryn,txn,tyn]
			savo=tf.train.Saver(var_list=var_lis)
			with tf.Session() as sess:
				sess.run([i for i in nodelis])
				print("saving checkpoint")
				save_path = savo.save(sess, "/home/robita/forgit/neuro-evolution/05/state/tf/indep_pima/input/model.ckpt")

		
		
		
		self.net_err = Network.Neterr(inputdim=self.dimtup[0], outputdim=self.dimtup[1], arr_of_net=self.list_chromo,rest_setx=self.rest_setx,rest_sety=self.rest_sety,test_setx=self.test_setx,test_sety=self.test_sety,rng=self.rng)
		self.net_dict={} #dictionary of networks for back-propagation, one for each n_hid
Пример #38
0
    def __init__(self, parent, controller):
        self.controller = controller
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="Create New Simulation", font=LARGE_FONT)
        label.pack(pady=10, padx=10)

        self.networkName = ""
        self.networkType = ""

        fr_networkName = tk.Frame(self, parent)
        fr_networkName.pack(pady=10)

        fr_networkType = tk.Frame(self, parent)
        fr_networkType.pack(pady=10)

        fr_buttons = tk.Frame(self, parent)
        fr_buttons.pack(pady=10)

        lb_networkName = tk.Label(fr_networkName,
                                  text="Network Name: ",
                                  anchor=tk.W)
        self.tb_networkName = ttk.Entry(fr_networkName)
        lb_networkType = tk.Label(fr_networkType,
                                  text="Network Type:",
                                  anchor=tk.W)
        self.tb_networkType = ttk.Entry(fr_networkType)
        bt_createNetwork = ttk.Button(
            fr_buttons,
            text="Create",
            command=lambda: self.saveNetwork(controller))
        bt_cancelNetwork = ttk.Button(
            fr_buttons,
            text="Cancel",
            command=lambda: controller.show_frame(StartPage))

        lb_networkName.grid(row=0)
        self.tb_networkName.grid(row=0, column=2)
        lb_networkType.grid(row=0)
        self.tb_networkType.grid(row=0, column=2)
        bt_createNetwork.grid(row=0)
        bt_cancelNetwork.grid(row=0, column=2)

        self.nw = nw.Network(self.getNetworkName(), self.getNetworkType())
Пример #39
0
 def __init__(self,checkpoint_path='../checkpoint',logs_path='../logs',BATCH_SIZE=5):
     self.net=Network()
     self.forward=self.net.vgg     #选择需要的网络
     self.datasets = None
     self.label = None
     self.test_data = None
     self.test_label = None
     self.checkpoint_path = checkpoint_path
     self.logs_path = logs_path
     self.input_data = tf.compat.v1.placeholder(tf.float32, [None,224,224,3], name = "input_data")#定义输入
     self.supervised_label = tf.compat.v1.placeholder(tf.float32, [None, 2], name = "label")#定义标签
     self.BATCH_SIZE=BATCH_SIZE
     self.STEPS = 10000000           #最大步数
     self.LEARNING_RATE_BASE = 0.00001  # 最初学习率
     self.LEARNING_RATE_DECAY = 0.99  # 学习率的衰减率
     self.LEARNING_RATE_STEP = 1000  # 喂入多少轮BATCH-SIZE以后,更新一次学习率。一般为总样本数量/mini_batch
     self.global_step =tf.compat.v1.train.get_or_create_global_step() #步数
     self.learning_rate = tf.compat.v1.train.exponential_decay(self.LEARNING_RATE_BASE, self.global_step, self.LEARNING_RATE_STEP, self.LEARNING_RATE_DECAY, staircase=True)#学习率衰减
     self.is_training = tf.compat.v1.placeholder(tf.bool, name="is_training")
Пример #40
0
    def init_gui(self):
        self.text_edit = QTextEdit()
        self.setCentralWidget(self.text_edit)
        self.statusBar()
        self.network = Network.Network(X_SIZE, Y_SIZE, FUNCTION, MOMENTUM,
                                       INPUT_NEURONS, OUTPUT_NEURONS,
                                       HIDDEN_NEURONS)

        self.progress_label = QLabel(self)
        self.progress_label.move(20, 120)
        self.progress_bar = QProgressBar(self)
        self.progress_bar.setGeometry(20, 150, 200, 25)
        self.progress_bar.hide()

        open_training_file = QAction(QIcon('open.png'), 'Run train File', self)
        open_training_file.setShortcut('Ctrl+T')
        open_training_file.setStatusTip('Open new File')
        open_training_file.triggered.connect(self.load_train_file)

        open_start_value_file = QAction(QIcon('open.png'), 'Open start Values',
                                        self)
        open_start_value_file.setShortcut('Ctrl+S')
        open_start_value_file.setStatusTip('Open new File')
        open_start_value_file.triggered.connect(self.loadStartValues)

        menu_bar = self.menuBar()
        file_menu = menu_bar.addMenu('&File')
        file_menu.addAction(open_training_file)
        file_menu.addAction(open_start_value_file)

        self.evaluate_button = QPushButton('Evaluate', self)
        self.evaluate_button.move(20, 50)
        self.evaluate_button.clicked.connect(self.evaluate)

        self.result = QLabel(self)
        self.result.setText("Result: " + str(self.network.result)[:8])
        self.result.move(X_SIZE - 100, Y_SIZE - 100)

        self.init_grids()

        self.setGeometry(300, 300, X_SIZE, Y_SIZE)
        self.setWindowTitle('Artificial Neural Network')
        self.show()
Пример #41
0
    def test_Two_routes_4_5_compute_shortest_path_with_weight(self):
        r = Network.Network(
            *["Input/RATP_GTFS_METRO_4", "Input/RATP_GTFS_METRO_5"])

        time = datetime.datetime.strptime('20190321 15:25', '%Y%m%d %H:%M')

        parcours, duration = r.compute_shortest_path("Château d'Eau",
                                                     "Jacques-Bonsergent",
                                                     time)
        print(parcours, duration)
        ref = [(2153, 'transfer', 0), (2208, '4', 1), (2076, 'transfer', 3),
               (1898, '5', 5)]
        # [("Château d'Eau", 'transfer', 0),
        #        ("Gare de l'Est (Verdun)", '4', 1),
        #        ("Gare de l'Est (Verdun)", 'transfer', 3),
        #        ('Jacques-Bonsergent', '5', 5)]
        self.assertEqual(ref, parcours)
        self.assertEqual(5, duration)

        time = datetime.datetime.strptime('20190321 15:25', '%Y%m%d %H:%M')

        parcours, duration = r.compute_shortest_path("Jacques-Bonsergent",
                                                     "Porte de Clignancourt",
                                                     time)
        print(parcours, duration)
        ref = [(1898, 'transfer', 0), (2294, 'transfer', 0), (2125, '5', 3),
               (2208, 'transfer', 5), (2212, '4', 7), (2110, '4', 9),
               (2152, '4', 10), (2535, '4', 11), (2478, '4', 12),
               (2420, '4', 14), (1742, 'transfer', 14)]
        # [('Jacques-Bonsergent', 'transfer', 0),
        #        ('Jacques-Bonsergent', 'transfer', 0),
        #        ("Gare de l'Est (Verdun)", '5', 3),
        #        ("Gare de l'Est (Verdun)", 'transfer', 5),
        #        ('Gare du Nord', '4', 7),
        #        ('Barbès-Rochechouart', '4', 9),
        #        ('Château Rouge', '4', 10),
        #        ('Marcadet-Poissonniers', '4', 11),
        #        ('Simplon', '4', 12),
        #        ('Porte de Clignancourt', '4', 14),
        #        ('Porte de Clignancourt', 'transfer', 14)]
        self.assertEqual(ref, parcours)
        self.assertEqual(14, duration)
Пример #42
0
    def runOnAllStartpoints(self):
        '''Runs both algorithms using, in turn, each node at the begining of a regular flow as starting point. Then average the results.'''
        for i in range(self.nExp):
            self.n = Network(self.n.nNodes, self.n.nFlows, self.n.nChannels,
                             self.n.eFork, self.n.schedulingMethod)
            startpoints = [path[0] for path in self.n.H]
            for node in startpoints:
                SFSA = self.runSFSA(node)
                OBSSA = self.runOBSSA(node)
                self.schedulability[i][0] += SFSA[0]
                self.nStolenFlows[i][0] += SFSA[1]
                self.nStolenFlowsScheduled[i][0] += SFSA[0] * SFSA[1]
                self.schedulability[i][1] += OBSSA[0]
                self.nStolenFlows[i][1] += OBSSA[1]
                self.nStolenFlowsScheduled[i][1] += OBSSA[0] * OBSSA[1]
                # if OBSSA[0]<SFSA[0]:
                #     print(SFSA)
                #     print(OBSSA)
                #     print(self.n.intersections)
                #     for k,v in enumerate(self.n.W):
                #         print(k, " ", v)

        for i in range(self.nExp):
            if self.schedulability[i][0] != 0:
                self.nStolenFlowsScheduled[i][0] = self.nStolenFlowsScheduled[
                    i][0] / self.schedulability[i][0]
            else:
                self.nStolenFlowsScheduled[i][0] = 0
            if self.schedulability[i][1] != 0:
                self.nStolenFlowsScheduled[i][1] = self.nStolenFlowsScheduled[
                    i][1] / self.schedulability[i][1]
            else:
                self.nStolenFlowsScheduled[i][1] = 0
        self.nStolenFlowsScheduled = np.true_divide(
            self.nStolenFlowsScheduled.sum(0),
            (self.nStolenFlowsScheduled != 0).sum(0))
        self.schedulability = np.mean(self.schedulability, 0)
        self.schedulability /= (len(startpoints)
                                )  #*(self.n.globalPeriod-self.eFlowDeadLine)
        self.nStolenFlows = np.mean(self.nStolenFlows, 0)
        self.nStolenFlows /= (len(startpoints)
                              )  #*(self.n.globalPeriod-self.eFlowDeadLine)
Пример #43
0
 def __init__(self, parent):
     wx.Panel.__init__(self, parent)
     
     sizer = wx.BoxSizer(wx.HORIZONTAL)
     
     text = wx.TextCtrl(self, style = wx.TE_MULTILINE | wx.TE_READONLY)
     text.AppendText(u'系统信息:\n\n')
     text.AppendText(u'网络信息:\n')
     text.AppendText(Network.GetInfoString());
     text.Bind(wx.EVT_CHAR, self.OnChar)
     sizer.Add(text, 1, wx.EXPAND)
     sizer.AddSpacer(20)
     button = wx.Button(self, -1, u'关于...')
     sizer.Add(button, 0, flag = wx.ALIGN_RIGHT)
     
     self.SetSizer(Util.CreateCenterSizer(sizer, 20))
     
     self.Bind(wx.EVT_BUTTON, self.OnAbout, button)
     
     self.keybuf = ''
Пример #44
0
def execute_generate_play(nnet_path,
                          multiplikator=configs.SIMS_FAKTOR,
                          exponent=configs.SIMS_EXPONENT):
    gc.collect()
    os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
    nnet = Network.get_net(configs.FILTERS, configs.HIDDEN_SIZE,
                           configs.OUT_FILTERS, configs.NUM_ACTIONS,
                           configs.INPUT_SIZE, None, configs.NUM_RESIDUAL)
    nnet.load_weights(nnet_path)
    env = MillEnv.MillEnv()
    mcts_ = mcts.MonteCarloTreeSearch(
        mcts.State(zeros((1, 24)), 0, -env.isPlaying, env))
    stmem = mcts_.generatePlay(nnet, multiplikator, exponent)
    del mcts_
    del env
    keras.backend.clear_session()
    tf.compat.v1.reset_default_graph()
    del nnet
    gc.collect()
    return stmem
	def OnManageNetworkClick(self):
		""" action - display network page
		"""
		if(not self.pm.installRequired()):
			try:
				self.network
			except:
				self.network = Network()
			try:
				self.widgets['nodes']
			except:
				self.widgets['nodes'] = {}
			for v in self.widgets['nodes'].values():
				v.grid_forget()
			self.widgets['nodes'] = {}
			self.listNodes()
			self.scheduler.addTask('network_nodes', self.updateNodes, 5)
		else:
			self.open()
			self.pm.addManager()
Пример #46
0
def selectAccount(accountInfos):
    lostRate = []
    avgTime = []
    for account in accountInfos:
        netinfo = Network._runping(account[0])
        lostRate.append(netinfo[0])
        if len(netinfo) > 1:
            avgTime.append(netinfo[1])
        else:
            avgTime.append(sys.maxsize)
    minRate = min(lostRate)
    minAvgTime = sys.maxsize
    minIndex = -1
    for i in range(len(lostRate)):
        if lostRate[i] == minRate:
            if avgTime[i] < minAvgTime:
                minAvgTime = avgTime[i]
                minIndex = i
    accountInfos[minIndex].append(minAvgTime)
    return accountInfos[minIndex]
Пример #47
0
 def On_PluginInit(self):
     if not Plugin.IniExists("Settings"):
         Plugin.CreateIni("Settings")
         ini = Plugin.GetIni("Settings")
         ini.AddSetting("Settings", "Command", "/say")
         ini.AddSetting("Settings", "Popup time", "10")
         ini.AddSetting("Allowed Ranks", "Users", "false")
         ini.AddSetting("Allowed Ranks", "Moderators", "true")
         ini.AddSetting("Allowed Ranks", "Admins", "true")
         ini.Save()
     ini = Plugin.GetIni("Settings")
     DataStore.Add("BroadCast", "Timer", int(ini.GetSetting("Settings", "Popup time")) * 1000)
     DataStore.Add("BroadCast", "Users", ini.GetBoolSetting("Allowed Ranks", "Users"))
     DataStore.Add("BroadCast", "Mod", ini.GetBoolSetting("Allowed Ranks", "Moderators"))
     DataStore.Add("BroadCast", "Admin", ini.GetBoolSetting("Allowed Ranks", "Admins"))
     DataStore.Add("BroadCast", "Command", ini.GetSetting("Settings", "Command").Replace("/", ""))
     command = ini.GetSetting("Settings", "Command").Replace("/", "")
     Commands.Register(command).setCallback("command")
     for Player in Server.ActivePlayers:
         CommunityEntity.ServerInstance.ClientRPCEx(Network.SendInfo(Player.basePlayer.net.connection), None, "DestroyUI", Facepunch.ObjectList("broadcastui"))
Пример #48
0
    def run(self):
        """
        シミュレーション回数だけシミュレーションを実行する.
        """
        try:
            os.makedirs('../{}/{}'.format(self.fig_dir, self.simu_dir))
        except OSError as exc:
            pass
        
        try:
            os.makedirs('../{}/{}'.format(self.csv_dir, self.simu_dir))
        except OSError as exc:
            pass

        time_start = time.time()

        for n in range(self.try_num):
            graph = Network.Topology(self.node, self.site, self.conn,  self.prob, self.t_type)
            model = Model.Model(graph)
            simu  = Simulator.Simulator(graph, model, self.lb_max, self.ln_max, self.sig_max, self.sig_div, self.vm_add)

            fname   = '../{}/{}/{}-割当前.svg'.format(self.fig_dir, self.simu_dir, n + 1)
            fname_a = '../{}/{}/{}-割当後.svg'.format(self.fig_dir, self.simu_dir, n + 1)

            print ''
            print '<{}回目>'.format(n + 1)
            
            graph.generate_images(filename=fname, first=True)
            for i in range(self.vm_add):
                simu.solve(info=True)
            graph.generate_images(filename=fname_a, first=False, costList=simu.x_sig)

            print'[Site]',
            for k in simu.vm_num:
                print '{0:2d}:{1:2d}, '.format(k, simu.vm_num[k]),
            print ''

            self.make_data(simu, n)
        self.make_csv()

        print '[Time of simulation] : {}'.format(time.time() - time_start)
Пример #49
0
def classifier(nn_params, log, exp, train_path, val_path, test_path,
               save_logs):

    # create model and train it
    model = Network.CNN(nn_params)
    if nn_params["load_model"] is not None:
        with open(nn_params["load_model"], 'rb') as pickle_file:
            model2 = pickle.load(pickle_file)
        model.init_weights(model2)

    model, mean, std = train_model(model, nn_params, log, exp, train_path,
                                   val_path, save_logs)

    # test model
    X_test, Y_test = read_data(test_path, nn_params, "test")

    # apply z score scaling
    if nn_params["z_scale"]:
        X_test, _, __ = z_scaling(X_test.copy(), mean, std)

    test_model(model, nn_params, exp, X_test, Y_test, save_logs, "test")
Пример #50
0
	def train(self,col = -1):
		if mdf.empty:
			print("Empty dataframe. Data is needed to train. Use import to import data")
		else:
			if col == -1:
				col = int(input("Which column is output data "))
			
			col = int(col)
			outdata = mdf.iloc[:,col-1:col]
			indata = mdf.drop(mdf.columns[col-1],axis=1)
			
			inTrain, inTest, outTrain, outTest = train_test_split(indata, outdata, test_size=0.3, random_state=101)

			#print(inTrain)
			#print(inTest)
			#print(outTrain)
			#print(outTest)

			neural = Network(inTrain.values,outTrain.values)
			Network.train(neural, 1000)
			Network.run(neural, inTest)
Пример #51
0
 def sendCommand(self, nameRoom, equipment, command):
     """Método que envia os comandos para o cômodo
     :Param nameRoom: O nome do cômodo
     :Type nameRoom: String
     :Param equipment: O equipamento
     :Type equipment: String
     :Param command: O comando a ser executado
     :Type command: String
     :Return: A requisição Http Post do Cômodo
     :Rtype: Requisição Http Post
     """
     nameRoom = nameRoom.lower()
     infoRoom = self.__searchRoom(nameRoom)
     if (infoRoom != False):
         ip = infoRoom[0]
         port = infoRoom[1]
         params = {"equipment": equipment, "command": command}
         method = "controlEquipment"
         return util.httpPostRequest(ip, port, method, params)
     else:
         return "Comodo nao existe"
Пример #52
0
    def __init__(self, game, name, dimensions, a_size, trainer, model_path, global_episodes):
        self.name = "worker_" + str(name)
        self.number = name
        self.model_path = model_path
        self.trainer = trainer
        self.global_episodes = global_episodes
        self.increment = self.global_episodes.assign_add(1)
        self.episode_rewards = []
        self.episode_lengths = []
        self.episode_mean_values = []
        self.summary_writer = tf.summary.FileWriter("train_" + str(self.number))

        self.height, self.width, depth, self.s_size = dimensions

        # Create the local copy of the network and the tensorflow op to copy global paramters to local network
        self.local_AC = Network(self.height, self.width, depth, self.s_size, a_size, self.name, trainer)
        self.update_local_ops = update_target_graph('global', self.name)

        self.actions = range(a_size)
        # End Doom set-up
        self.env = gym.make(game)
Пример #53
0
def getinfo():

    data = []
    result = request.form

    f = request.files['data_file']
    stream = io.StringIO(f.stream.read().decode("UTF8"), newline=None)
    data = pd.read_csv(stream)
    '''Get user specs from form'''
    output = result['output']
    output = int(output)
    '''Separate input data from output data'''
    outdata = data.iloc[:, output - 1:output]
    indata = data.drop(data.columns[output - 1], axis=1)
    '''Testing purposes to ensure data is placed correctly'''
    '''Further separation of daata file'''
    #inTrain, inTest, outTrain, outTest = train_test_split(indata, outdata, test_size=0.3, random_state=101)

    # print(inTrain)
    # print(inTest)
    # print(outTrain)
    # print(outTest)

    inTest = indata.tail(1)
    outTest = outdata.tail(1)

    inTrain = indata[:-1]
    outTrain = outdata[:-1]
    '''Train data'''
    neural = Network(inTrain.values, outTrain.values)
    Network.train(neural, 1000)
    outputList = pd.DataFrame(Network.run(neural, inTest))

    return render_template("view.html",
                           tables=[
                               inTest.to_html(classes='intext'),
                               outTest.to_html(classes='outTest'),
                               outputList.to_html(classes='outTest')
                           ],
                           titles=['na', 'IN', 'OUT', 'OTIS'])
Пример #54
0
def One_Initialize_Network(Hidden_Neurons: int) -> Network.Neural_Network:
    """ This function initializes a single-hidden-layer neural network with a
    variable number of neurons in the first layer. Every weight and bias in the
    network is initialized to a tensor of ones. This gives the network a
    predictable (though still nonlinear) output, which is very useful for
    testing. In particular, the network we create should evaluate as follows:
        u_NN(x) = n*tanh(x[0] + x[1] + 1) + 1
    where n = Hidden_Neurons. """

    # Initialize the network.
    NN = Network.Neural_Network(Num_Hidden_Layers=1,
                                Neurons_Per_Layer=Hidden_Neurons,
                                Input_Dim=2,
                                Output_Dim=1)

    # Manually set the network Weights and Biases to tensors of ones.
    torch.nn.init.ones_(NN.Layers[0].weight.data)
    torch.nn.init.ones_(NN.Layers[1].weight.data)
    torch.nn.init.ones_(NN.Layers[0].bias.data)
    torch.nn.init.ones_(NN.Layers[1].bias.data)

    return NN
Пример #55
0
 def __init__(self):
     # datasets
     self.train_dataset = Dataset.UCF101VideoDataset(
         '/home/sunhanbo/workspace/C3D_UCF101/Dataset', 'train', 16, False)
     self.train_loader = Data.DataLoader(
         self.train_dataset,
         batch_size=60,
         shuffle=True,
         drop_last=True,
         num_workers=16,
     )
     self.test_dataset = Dataset.UCF101VideoDataset(
         '/home/sunhanbo/workspace/C3D_UCF101/Dataset', 'test', 16, False)
     self.test_loader = Data.DataLoader(
         self.test_dataset,
         batch_size=60,
         shuffle=False,
         drop_last=False,
         num_workers=16,
     )
     # networks
     self.net = Network.C3DNetwork(101)
Пример #56
0
def snowball_network(network, sample_size, n_neighbors, induced=False):
    visited_nodes, visited_edges, nodes_queue, temp_visited = set(), set(
    ), set(), set()
    starting_node = get_random_node(network.nodes)
    nodes_queue.add(starting_node)
    visited_nodes.update(nodes_queue)
    while (len(nodes_queue) > 0) and (len(visited_nodes) <
                                      (sample_size * network.n_nodes)):
        for node in nodes_queue:
            new_neighbors = network.adj[node].difference(
                visited_nodes).difference(temp_visited)
            neighbor_limit = min(len(new_neighbors), n_neighbors)
            visit_neighbors(neighbor_limit, new_neighbors, visited_edges, node,
                            temp_visited)
        update_visited_nodes(visited_nodes, temp_visited, sample_size,
                             network.n_nodes, visited_edges)
        nodes_queue.clear()
        nodes_queue.update(temp_visited)
        temp_visited.clear()
    nodes = visited_nodes
    edges = get_edges(induced, nodes, network.edges, visited_edges)
    return Network(nodes, edges)
Пример #57
0
 def __init__(self,
              speed=None,
              health=None,
              max_health=None,
              dmg=None,
              armor=None,
              size=None,
              brain=None,
              name="Yuval",
              location=None,
              turns=0):
     if speed == None:
         speed = attribute()
     if health == None:
         health = attribute()
     if max_health == None:
         max_health = attribute()
     if dmg == None:
         dmg = attribute()
     if armor == None:
         armor = attribute()
     if size == None:
         size = attribute()
     if location == None:
         location = [400, 400]
     self.location = location
     if brain == None:
         brain = [3, 2, 3]
     brain1 = Network.network(brain)
     self.brain = brain1
     self.speed = speed
     self.health = health
     self.max_health = max_health
     self.dmg = dmg
     self.armor = armor
     self.size = size
     self.name = name
     self.speed.value = 20
     self.turns = turns
Пример #58
0
def RSNN_param_test(X_train, X_test, y_train, y_test, h_nodes, epochs, lr,
                    times, threshold, coefficient, type):
    """
    Trains a regular 3-layer our NN, and returns the accuracy results

    :param X_train: Numpy array/pandas dataframe, data for the keras model.
    :param X_test: Numpy array/pandas dataframe, data for the keras model.
    :param y_train: Numpy array/pandas dataframe, data for the keras model.
    :param y_test: Numpy array/pandas dataframe, data for the keras model.
    :param h_nodes: Int, number of nodes in the hidden layer.
    :param epochs: Int, number of epochs to train the NN.
    :param lr: Float, learning rate for training.
    :param times: Integer, number of times to MC sample.
    :param threshold: Integer, used as threshold for forming residual to sample from.
    :param coefficient: Float, used as the ratio for updating the variance.
    :param type: string, select type of loss function.
    :return: (training_acc, test_acc), training/testing accuracies
    """
    in_dim = X_train.shape[1]
    out_dim = y_train.shape[1]

    #Initialize the network
    np.random.seed(10)  # Ensures each network is initialized the same way.
    net = Network.Network([in_dim, h_nodes, out_dim],
                          type=type,
                          pdw=['gaussian'] * 2,
                          pdb=['gaussian'] * 2)
    net.Learn(X_train,
              y_train,
              epochs=epochs,
              lrate=lr,
              times=times,
              threshold=threshold,
              bootstrap=False,
              coefficient=coefficient)
    acc_train = net.ClassificationAccuracy(X_train, y_train)
    acc_test = net.ClassificationAccuracy(X_test, y_test)

    return (acc_train, acc_test)
Пример #59
0
    def check_alternate_titles(self):
        """
        Checks up to the top MAX_ALTERNATE_TITLE_SEARCHES regular matches to see if we match an alternate title.
        """
        self.results.Sort('score', descending=True)
        top_match_counter = 0
        for result in self.results:
            top_match_counter += 1
            if result.score == 100:
                return
            elif top_match_counter <= MAX_ALTERNATE_TITLE_SEARCHES:
                xml = Network.fetch_xml(tvrage.SHOW_INFO_URL % result.id)

                if xml:
                    for aka_xml in xml.xpath("./akas/aka"):
                        for show_name in self.show_names:
                            aka_show_name = str(aka_xml.text)
                            Log("[%s] [%s]" %
                                (tvrage.sanitize_show_name(show_name), tvrage.sanitize_show_name(aka_show_name)))
                            if tvrage.sanitize_show_name(show_name) == tvrage.sanitize_show_name(aka_show_name):
                                Log("Found exact match in alternate title %s" % aka_show_name)
                                result.score = 100
Пример #60
0
def main():
    root = Tk()
    root.title("Social Network")
    root.configure(bg="#EAF6F6")
    network = Network("social_network.txt")

    def on_closing():
        network.write_messages("messages.txt")
        root.destroy()

    network.parse()
    network.read_messages("messages.txt")
    frame = UserFrame(master=root, network=network)
    frame.style()
    frame.place()
    root.protocol("WM_DELETE_WINDOW", on_closing)
    root.mainloop()