我正试图用C语言制作一个神经网络,我用我不久前制作的一个python代码作为设计的基础。但不知何故,最终的结果是不一样的。在
我是C的新手,我在Unity中使用它,所以我对库的使用有限制。在
在python中,numpy可以使用纽比.dot()方法。我在C中没有发现类似的东西,特别是在Unity中。所以我不得不用手来做。在
Python代码:import numpy as np
class NN:
def __init__(self, n_input, n_hidden_layers, n_hidden_nodes, n_output):
self.weights_hidden = []
for n in range(n_hidden_layers + 1):
if n == 0:
size = n_input, n_hidden_nodes
elif n == n_hidden_layers:
size = n_hidden_nodes, n_output
else:
size = n_hidden_nodes, n_hidden_nodes
self.weights_hidden.append(
np.random.random(size)
)
@staticmethod
def activation(x):
return np.tanh(x)
def feed_forward(self, ip):
input_values = (ip - np.mean(ip, axis=0)) / np.std(ip, axis=0)
for w, weights in enumerate(self.weights_hidden):
if w == 0:
result = input_values
result = np.array(
map(self.activation, result.dot(weights))
)
return result
ANN = NN(n_input=5, n_hidden_layers=2, n_hidden_nodes=3, n_output=1)
print ANN.feed_forward([1, 2, 3, 4, 5])
我试图把它转换成C。在
^{pr2}$
我使用init方法从其他脚本运行网络,然后使用start_net()方法。在
我做了一个没有随机权重和固定输入数据的测试,但是结果与python代码不一样。在
C代码怎么了?在