示例#1
0
    def activate(self, input_list):

        if (len(input_list) != len(self.hpneat_config.input_neuron_position)):
            raise ValueError("argument ouf of range")

        pre_activate_val = copy.deepcopy(self.activate_val)

        for n in range(len(input_list)):
            self.activate_val[self.hpneat_config.input_neuron_position[n][0]][
                self.hpneat_config.input_neuron_position[n][1]] = input_list[n]

        activate_vec = tools.matrix_to_vector(self.activate_val)
        activate_vec = np.dot(activate_vec, self.weight)
        self.activate_val = tools.sigmoid_for_np_ndarray(
            tools.vector_to_matrix(activate_vec) + self.bias)

        #update weight
        self.weight = update_weight_for_abc(self.hpneat_config.num_x, \
                                            self.hpneat_config.num_y, \
                                            self.weight, \
                                            pre_activate_val, \
                                            self.activate_val,\
                                            self.A, self.B, self.C, self.ita)

        output_vec = []
        for n in range(len(self.hpneat_config.output_neuron_position)):
            output_vec.append(self.activate_val[
                self.hpneat_config.output_neuron_position[n][0]][
                    self.hpneat_config.output_neuron_position[n][1]])
        return output_vec
示例#2
0
def test_matrix_to_vector():
    hpneat_config.num_x = 2
    hpneat_config.num_y = 3
    m1 = 20 * np.random.random((hpneat_config.num_x, hpneat_config.num_y)) - 10
    print(m1)
    vec = tools.matrix_to_vector(m1)
    print(vec)
    print(vec.shape)
    m2 = tools.vector_to_matrix(vec)
    print(m2)

    assert m1.shape == (2, 3)
    assert vec.shape == (1, 6)
    assert m1[1][0] == m2[1][0]
    assert m1.shape == m2.shape
示例#3
0
def testWolfBQ():
    r = 0.1327
    T = np.linspace(0, 1, 100)
    BQ1 = []
    BQ2 = []
    for i, t in enumerate(T):
        print(f'{i+1}/{len(T)}')
        B = functional(t, r)
        bq1, _, _, _, _, _, _ = CHSH.chsh2(T.vector_to_matrix(B), 0.0001)
        bq2 = QValue(t, r)

        BQ1.append(bq1)
        BQ2.append(bq2)
    plt.plot(BQ1)
    plt.plot(BQ2)
    plt.show()
示例#4
0
    def activate(self, input_list):
        if (len(input_list) != len(self.hpneat_config.input_neuron_position)):
            raise ValueError("argument ouf of range")

        for n in range(len(input_list)):
            self.activate_val[self.hpneat_config.input_neuron_position[n][0]][
                self.hpneat_config.input_neuron_position[n][1]] = input_list[n]

        activate_vec = tools.matrix_to_vector(self.activate_val)
        activate_vec = np.dot(activate_vec, self.weight)
        self.activate_val = tools.sigmoid_for_np_ndarray(
            tools.vector_to_matrix(activate_vec) + self.bias)

        output_vec = []
        for n in range(len(self.hpneat_config.output_neuron_position)):
            output_vec.append(self.activate_val[
                self.hpneat_config.output_neuron_position[n][0]][
                    self.hpneat_config.output_neuron_position[n][1]])
        return output_vec