示例#1
0
def perceptron(size, weights):
    """Creates a perceptron network
    """
    inputLayer = Layer(LayerType.INPUT, size[0], activation=None)
    outputLayer = Layer(LayerType.OUTPUT, size[1], activation=Neuron.HEAVISIDE)
    pp.pprint(weights)
    inputLayer.connect(outputLayer, weights)
    return Ann({'input': inputLayer, 'hidden': [], 'output': outputLayer})
def connect(layer: Layer, instruction: Instruction):
    if len(instruction.details) > 2:
        print("\nWRONG CONNECT INSTRUCTION FORMAT.")
        raise Exception
    port1 = str.split(instruction.details[0], '_')
    port2 = str.split(instruction.details[1], '_')
    layer.connect(instruction.time, port1[0],
                  int(port1[1]) - 1, port2[0],
                  int(port2[1]) - 1)
    write(
        instruction.time,
        "connect, device_x={}, port_x={}, device_y={}, port_y={}\n".format(
            port1[0], port1[1], port2[0], port2[1]))
示例#3
0
def multi_layer_network(size, weights):
    """Creates a 3 layer network (1 hidden)
    """
    inputLayer = Layer(LayerType.INPUT, size[0], activation=None)
    hiddenLayer = Layer(LayerType.HIDDEN, size[1], activation=Neuron.LOGISTIC)
    outputLayer = Layer(LayerType.OUTPUT, size[2], activation=Neuron.LOGISTIC)
    inputLayer.connect(hiddenLayer, weights[1])
    hiddenLayer.connect(outputLayer, weights[0])
    return Ann({
        'input': inputLayer,
        'hidden': [hiddenLayer],
        'output': outputLayer
    })
示例#4
0
def deep_network(size, weights):
    """Creates a 5 layer network (3 hidden)
    """
    inputLayer = Layer(LayerType.INPUT, size[0], activation=None)
    hiddenLayer1 = Layer(LayerType.HIDDEN, size[1], activation=Neuron.LOGISTIC)
    hiddenLayer2 = Layer(LayerType.HIDDEN, size[2], activation=Neuron.LOGISTIC)
    hiddenLayer3 = Layer(LayerType.HIDDEN, size[3], activation=Neuron.LOGISTIC)
    outputLayer = Layer(LayerType.OUTPUT, size[4], activation=Neuron.LOGISTIC)
    inputLayer.connect(hiddenLayer1, weights[3])
    hiddenLayer1.connect(hiddenLayer2, weights[2])
    hiddenLayer2.connect(hiddenLayer3, weights[1])
    hiddenLayer3.connect(outputLayer, weights[0])
    return Ann({
        'input': inputLayer,
        'hidden': [hiddenLayer1, hiddenLayer2, hiddenLayer3],
        'output': outputLayer
    })