本文整理汇总了Python中neuron.Neuron.bias方法的典型用法代码示例。如果您正苦于以下问题:Python Neuron.bias方法的具体用法?Python Neuron.bias怎么用?Python Neuron.bias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neuron.Neuron
的用法示例。
在下文中一共展示了Neuron.bias方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load
# 需要导入模块: from neuron import Neuron [as 别名]
# 或者: from neuron.Neuron import bias [as 别名]
def load(path):
"""
Loads a neural network from a json file
@param (String) path - The path to load the neural network from
@returns (Network) - The neural network that was loaded
"""
network = Network()
try:
with open(path, "r+") as f:
network_data = "\n".join(f.readlines())
network_json = json.loads(network_data)
layers = network_json["layers"]
# For every layer in the network ...
for layer in layers:
neurons = []
# For every neuron in the layer ...
for neuron in layer["neurons"]:
weights = neuron["weights"]
bias = neuron["bias"]
activation = neuron["activation"]
# Choose the proper activation function and corresponding derivative
activation_func = None
derivative_func = None
if activation == Network.LINEAR:
activation_func = Network.ACTIVATION_LINEAR
derivative_func = Network.DERIVATIVE_LINEAR
elif activation == Network.SIGMOID:
activation_func = Network.ACTIVATION_SIGMOID
derivative_func = Network.DERIVATIVE_SIGMOID
elif activation == Network.TANH:
activation_func = Network.ACTIVATION_TANH
derivative_func = Network.DERIVATIVE_TANH
elif activation == Network.STEP:
activation_func = Network.ACTIVATION_STEP
derivative_func = Network.DERIVATIVE_STEP
# Create a neuron with the desired info
neuron = Neuron(0, activation_func, derivative_func)
neuron.weights = weights
neuron.bias = bias
# Add the processed neuron to the collection
neurons.append(neuron)
# Create a layer with the desired neurons
layer = Layer(0, 0, None, None)
layer.neurons = neurons
# Add the processed layer to the collection
network.layers.append(layer)
except:
raise Exception("Invalid Neural Network File @ {}!".format(path))
return network