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


Python Network.process方法代码示例

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


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

示例1: range

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import process [as 别名]
three = [1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1]

# Set some quick properties for the upcoming training session
ITERATIONS = 1000  # Number of iterations per training session
LEARN_RATE = 0.03  # The rate the network learns on each iteration
THRESHOLD = 0.001  # If this precision is reached, the training session is instantly complete

# Perform a quick training session
for i in range(0, ITERATIONS, 1):
    error = 0

    # Example Data         Inputs   Outputs Learn Rate
    error += network.train(zero, [0, 0], LEARN_RATE)
    error += network.train(one, [0, 1], LEARN_RATE)
    error += network.train(two, [1, 0], LEARN_RATE)
    error += network.train(three, [1, 1], LEARN_RATE)

    # Check the error
    if error < THRESHOLD:
        break

# Process the outputs
outputs = network.process([0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1])

# Save the neural network to a file
Network.save("test_binary.json", network)

# Print the decimal equivalent of the network's output (Expected: ~2)
print(sum([(2 ** i) * outputs[-i - 1] for i in range(0, len(outputs), 1)]))
开发者ID:XxZ350xX,项目名称:Neural-Network,代码行数:31,代码来源:test_binary.py

示例2: vectorized_result

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import process [as 别名]
def vectorized_result(j):
    e = np.zeros((1, 10))
    e[0][j] = 1.0
    return e


def mse(output, target):
    error = 0.0
    target = vectorized_result(target)
    for i in range(len(output[0])):
        error += pow(abs(output[0][i] - target[0][i]), 2)
    return error/2

training_inputs, training_results, validation_inputs, validation_results, test_inputs, test_results = load_data_wrapper()
n = Network([784, 300, 10])
n.SGD(training_inputs, training_results, 0.3, 5000)

totalerror = 0

for i in range(10000):
    k = np.random.randint(len(validation_inputs))
    result = n.process(validation_inputs[k])
    erro = mse(result, validation_results[k])
    totalerror += erro
    print("Erro = {}".format(erro))
    print("CASE #{}:\n input[{}] = {} \nExpected = {}\n\n".format(i, k, result, validation_results[k]))

avgerror = totalerror/10000
right = 100 - avgerror*100
print("Taxa de acerto: {}\nErro Médio: {}".format(right, avgerror))
开发者ID:edusig,项目名称:RedesNeuraisT1,代码行数:32,代码来源:main.py

示例3: main

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import process [as 别名]
def main():
  # Make pygame window
  screen = pygame.display.set_mode((640,640))

  timer = 0
  numClients = 50

  # Create network of clients
  clients = []
  for i in xrange(0, numClients):
    clients.append(client.Client(i))

  # Set up random connections amongst the clients
  for i in xrange(0, numClients):
    for j in xrange(0, 5):
      clients[i].addConnection(clients[random.randrange(0, numClients)])

  # Instantiate network layer
  networkLayer = Network(clients)

  for c in clients:
    c.networkLayer = networkLayer;

  # Get user input
  keyInput = None
  while keyInput != 'q':
    message = None
    sourceID = -1
    destinationID = -1
    keyInput = raw_input("Select Option:\n's' - start\n'q' - end the program\n")
    
    # Start forming a message
    if keyInput == 's':
      # Choose a valid client index
      while sourceID < 0 or sourceID >= numClients:
        sourceID = int(raw_input("Enter the Client ID: "))
      source = clients[sourceID]

      # Choose an option
      keyInput = raw_input("\nSelect Option:\n'm' - submit message\n'd' - display client\n")

      # Send a direct message
      if keyInput == 'm':
        while destinationID < 0 or destinationID >= numClients:
          destinationID = int(raw_input("Enter the Reciever ID: "))
        destination = clients[destinationID]
        message = raw_input("Enter the message to send:\n")
        clients[sourceID].sendMessage(clients[sourceID].user, clients[destinationID].user, message, timer)

        if (len(source.networkLayer.BFS(source.ip, destination.ip)) == 0):
          print "No path between clients"
          continue;

        # Process TCP packets on sender and receiver
        while networkLayer.routing(timer) or len(source.transportLayer.tcpPackets) > 0 or len(destination.transportLayer.tcpPackets) > 0:
          drawClient(screen, source, 20, 20, destination)
          drawClient(screen, destination, 300, 20)

          # Checks if the source has packet to send
          if source.transportLayer.sendPacket():
            srcPacket = source.transportLayer.tcpPackets.pop(0)
            srcPacket.addHeader("send_time", timer)
            networkLayer.process(srcPacket)
            
            # Send the packet to a buffer for resubmission
            if not srcPacket.getHeader("syn") and not srcPacket.getHeader("fin"):
              newPacket = Packet(srcPacket)
              message = newPacket.getBody("message")
              newPacket.addBody("message", message+"(r)")
              newPacket.addHeader("fail", False)
              source.transportLayer.sentPackets.append(newPacket)

          # Checks for a retransmission packet
          retansmitPacket = source.transportLayer.checkRetransmission(timer)
          if retansmitPacket != None:
            nextPacket = Packet(retansmitPacket)
            message = nextPacket.getBody("message")
            networkLayer.process(retansmitPacket)
            nextPacket.addBody("message", message+"(r)")
            nextPacket.addHeader("fail", False)
            source.transportLayer.sentPackets.append(nextPacket)

          if destination.transportLayer.sendPacket():
            networkLayer.process(destination.transportLayer.tcpPackets.pop(0))

          timer += 1
          time.sleep(5)

        # Reset the transport layers
        source.transportLayer.reset()
        destination.transportLayer.reset()

        # Clients update their inbox
        drawClient(screen, source, 20, 20, destination)
        drawClient(screen, destination, 300, 20)

      # Display all IP addresses a client can talk to
      if keyInput == 'd':
        print clients[sourceID].connections
        drawClient(screen, source, 20, 20)
开发者ID:nburfield,项目名称:CPE-400-Networking-Project,代码行数:102,代码来源:main.py


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