コード例 #1
0
ファイル: neural_network.py プロジェクト: OnHoliday/DSLM
    def calculate(self):
        """Calculates semantics of all hidden neurons and output neuron."""
        i = 0
        for layer in self.cnn_layers:
            if i == 0:
                for neuron in layer:
                    neuron.calculate()
            else:
                for neuron in layer:
                    neuron.calculate2()
            i += 1

        last_layer = self.cnn_layers[-1]
        flatten_layer = None
        for neuron in last_layer:
            temp_arr = neuron.semantics
            temp_arr2 = temp_arr.reshape(-1, neuron.semantics.shape[3])

            if flatten_layer is not None:
                flatten_layer = concatenate((flatten_layer, temp_arr2), axis=0)
            else:
                flatten_layer = temp_arr2

        self.flatten_layer = array([Sensor(d) for d in flatten_layer])
        #todo tak zupelnie nie moze byc liczba innput_connections powinna byc dokladnie idealna !!!! cos tu nie gra do naprawy!!!
        self._connect_flat_hidden(self.flatten_layer, self.hidden_layers[0])
        self.load_semantic_after_flat_layer()

        for hidden_layer in self.hidden_layers:
            for neuron in hidden_layer:
                neuron.calculate()

        for neuron in self.output_layer:
            neuron.calculate()
コード例 #2
0
def create_network_from_topology(topology):
    """Creates neural network from topology."""
    # Create bias.
    bias = Sensor(array([1]))
    # Creates neurons from remaining items in string.
    activation_function = choice(list(_NON_LINEAR_ACTIVATION_FUNCTIONS.keys()))
    hidden_layers = [[create_neuron(activation_function, bias) for i in range(j)] for j in topology]
    # Create output neuron.
    output_neuron = create_neuron('identity', bias)
    # Connect nodes in neural network.
    if len(hidden_layers) > 1:
        for i in range(1, len(hidden_layers)): _connect_nodes(hidden_layers[i - 1], hidden_layers[i])
        _connect_nodes(hidden_layers[i], [output_neuron])
    else:
        _connect_nodes(hidden_layers[0], [output_neuron])
    # Create neural network.
    neural_network = NeuralNetwork(None, bias, hidden_layers, output_neuron)
    # Return neural network.
    return neural_network
コード例 #3
0
def create_network_from_topology(topology):
    """Creates neural network from topology."""
    # Create bias.
    bias = Sensor(array([1]))
    # Creates neurons from remaining items in string.
    hidden_layers = [[create_neuron('tanh', bias) for i in range(j)]
                     for j in topology]
    # Create output neuron.
    output_neuron = create_neuron('identity', bias)
    # Connect nodes in neural network.
    if len(hidden_layers) > 1:
        for i in range(1, len(hidden_layers)):
            _connect_nodes(hidden_layers[i - 1], hidden_layers[i])
        _connect_nodes(hidden_layers[i], [output_neuron])
    else:
        _connect_nodes(hidden_layers[0], [output_neuron])
    # Create neural network.
    neural_network = NeuralNetwork(None, bias, hidden_layers, output_neuron)
    # Return neural network.
    return neural_network
コード例 #4
0
ファイル: algorithm.py プロジェクト: OnHoliday/DSLM_NOVA
    def _initialize_bias(self, neural_network):
        """Initializes biases with same length as sensors."""

        return Sensor(
            resize(array([1]), shape(neural_network.sensors[0].semantics)))
コード例 #5
0
ファイル: algorithm.py プロジェクト: OnHoliday/DSLM_NOVA
    def _initialize_flat_sensors(self):
        """Initializes sensors based on input matrix."""

        return [Sensor(input_data) for input_data in self.input_matrix.T]
コード例 #6
0
ファイル: neural_network.py プロジェクト: OnHoliday/DSLM
 def add_sensors(self, X):
     """Adds sensors to neural network and loads input data."""
     self.sensors = [Sensor(np.array([])) for sensor_data in X.T]
     self.load_sensors(X)
     # Connects nodes to first level hidden layer.
     _connect_nodes(self.sensors, self.hidden_layers[0])
コード例 #7
0
ファイル: algorithm_cnn.py プロジェクト: OnHoliday/DSLM
    def _initialize_flat_sensors(self, data):
        """Initializes sensors based on input matrix."""

        return [Sensor(d) for d in data]
コード例 #8
0
    def _initialize_bias(self, neural_network):
        """Initializes biases with same length as sensors."""

        return Sensor(ones(neural_network.sensors[0].semantics.shape))