当前位置: 首页>>代码示例>>Python>>正文


Python Network.update方法代码示例

本文整理汇总了Python中network.Network.update方法的典型用法代码示例。如果您正苦于以下问题:Python Network.update方法的具体用法?Python Network.update怎么用?Python Network.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在network.Network的用法示例。


在下文中一共展示了Network.update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Simulation

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import update [as 别名]
class Simulation(object):
    def __init__(self, config, phases, network = None, processes=1):
        self.phases = phases
        if network is None:
            if 'type' in config['network'] and config['network']['type'] == 'som':
                logger.info('initializing regular SOM.')
                dim = config['network']['dim']
                datalength = sum([m['dim'][0] * m['dim'][1] for m in config['modalities']])
                self.network = SOM(dimensions = dim, datalength = datalength)
            else:
                logger.info('initializing som variant.')
                self.network = Network(config)
        else:
            self.network = network
        self.processes = processes
    

    def run(self):
        for phase in self.phases:
            logger.info('Starting phase: %s', phase.name)
            phase.start()
            if phase.train:
                for step,stimulus in enumerate(phase.stimulusGenerator()):
                    sigma = phase.interactionWidth(step)
                    s = phase.updateStrength(step)

                    logger.debug('Phase: %s, Step: %d. Sigma: %f, Strength: %f', phase.name, step, sigma, s)
                    if not logger.isEnabledFor(logging.DEBUG) and step % 100 == 0:
                        logger.info('Phase: %s, Step: %d. Sigma: %f, Strength: %f', phase.name, step, sigma, s)

                    activity = self.network.update(stimulus['stimulus'], sigma, s)
                self.network.net_training_id = time.time()
                phase.evaluate(self.network, stimulus['truth'], stimulus['stimulus'], activity)

            else:
                pid = (threading.current_thread().ident,time.time())
                if self.processes is not None:
                    logger.info("Using %d processes.", self.processes)
                else:
                    logger.info("Using as many processes as deemed appropriate by Python.")

                pools[pid] = Pool(self.processes)
                p = pools[pid]

                def repeater():
                    for _step, stimulus in enumerate(phase.stimulusGenerator()):
                        yield pid, self.network, _step, stimulus

                for step, stimulus, activity in p.imap(_doStep, repeater(), chunksize=100):
                    if step % 100 == 0:
                        logger.info('Phase: %s, Step: %d', phase.name, step)
                    phase.evaluate(self.network, stimulus['truth'], stimulus['stimulus'], activity)

                pools[pid] = None

            phase.finish()
开发者ID:tatome,项目名称:bauer_et_al_2015,代码行数:58,代码来源:simulation.py

示例2: Game

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import update [as 别名]
class Game():
    def __init__(self):
        pygame.init()
        # network
        self.network = Network()
        self.network.connect()
        self.network.login(username)
        netThread = threading.Thread(target=self.update_network)
        netThread.start()
        
        self.screen = pygame.display.set_mode((1024, 768), 0, 32)
        self.load()
        
    def load(self):
        self.background = pygame.image.load(background_image_filename).convert()
        self.image = pygame.image.load(sprite_image_filename).convert_alpha()
        self.update()
        
    def update(self):
        global pos
        while True:
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    exit()
                if event.type == MOUSEBUTTONDOWN:
                    pos[0] += 5
            self.draw()
                    
    def draw(self):
        self.screen.blit(self.background, (0,0))
        
        # network data draw
        if network_received is not None:
            for player in network_received:
                sp = Sprite(self, sprite_image_filename)
                sp.image = self.image
                sp.position = Vector2(player['pos'][0], player['pos'][1])
                sp.draw()
        
        pygame.display.update()
        
    def update_network(self):
        global network_received
        while True:
            data = {'action': 'update', 'id': username, 'pos': pos}
            network_received = json.loads(self.network.update(json.dumps(data)))
            time.sleep(0.05)
开发者ID:leotada,项目名称:pygame-async,代码行数:50,代码来源:main.py

示例3: int

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import update [as 别名]
    if s == 0:
        return v
    else:
        return v/s

dt = 0.0001
totalTime = 0.3
numIterations = int(totalTime/dt)
m = 32
n = 256
network = Network(m, n)
voltage = np.zeros((n, numIterations))
for t in range(numIterations):
    for i in range(n):
        voltage[i, t] = network.S[i].voltage
    network.update(dt)


#plt.plot(voltage[0], 'red')
#plt.plot(voltage[1], 'green')
#plt.plot(voltage[2], 'blue')
#plt.show()

plt.plot(normalize(network.X))
S = np.zeros(n)
for i in range(n):
    S[i] = network.S[i].spikeRate

print("Neuron firing rates:")
print(S)
X2 = np.dot(network.A, S)
开发者ID:nspotrepka,项目名称:neuron-inference,代码行数:33,代码来源:inference.py


注:本文中的network.Network.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。