当前位置: 首页>>代码示例>>Python>>正文


Python Neuron.weights方法代码示例

本文整理汇总了Python中neuron.Neuron.weights方法的典型用法代码示例。如果您正苦于以下问题:Python Neuron.weights方法的具体用法?Python Neuron.weights怎么用?Python Neuron.weights使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在neuron.Neuron的用法示例。


在下文中一共展示了Neuron.weights方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load

# 需要导入模块: from neuron import Neuron [as 别名]
# 或者: from neuron.Neuron import weights [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
开发者ID:XxZ350xX,项目名称:Neural-Network,代码行数:60,代码来源:network.py


注:本文中的neuron.Neuron.weights方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。