创建多个隐藏层神经网络

时间:2018-05-18 06:37:30

标签: python machine-learning neural-network

我正在从头开始创建一个神经网络(无法使用任何现有的框架),我想知道如何使构造函数保持可变数量的隐藏层?到目前为止我已经创建了一个,但我有点坚持如何将它扩展到多个隐藏层。 (在Python上完成)

编辑:

class NeuralNetwork:
    # Constructor
    def __init__(self, input_len, hidden_units, output_len,
                 act_func = None, loss_func=None,
                 init_weights=np.zeros, output_func=None,
                 random_seed=None):

        if random_seed:
            np.random_seed(random_seed)

        self.loss_func = loss_func
        self.output_func = output_func
        self.L = len(hidden_units) + 2  # change this later
        self.layers = []

        input_layer = Layer(np.identity(input_len),
                            np.zeros(input_len), id_f)
        self.layers.append(input_layer)

        for neurons, func in zip(hidden_units, act_func):
            prev_neurons = self.layers[-1].num_neurons
            weight_mat = init_weights((neurons,prev_neurons))
            biases = init_weights((neurons, ))
            current_layer = Layer(weight_mat, biases, func)
            self.layers.append(current_layer)

0 个答案:

没有答案