- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个神经网络,但是当我尝试实现 sigmoid 函数(在这种情况下导入或手动创建它)时,它只是说变量 sigmoid 不存在
这是我的代码
另外,我在 Anaconda 中使用 Visual Studio 代码
from matplotlib import pylab
import pylab as plt
import numpy as np
class NeuralNetwork:
def __init__(self,x,y):
self.input = x
self.weights1 = np.random.rand(self.input.shape[1],4)
self.weights2 = np.random.rand(4,1)
self.y = y
self.output = np.zeros(self.y.shape)
def sigmoid(self,x):
return (1/(1+np.exp(-x)))
def feedforward(self):
self.layer1 = sigmoid(np.dot(self.input, self.weights1))
self.output = sigmoid(np.dot(self.layer1, self.weights2))```
最佳答案
您已定义 sigmoid
作为类方法,因此您需要使用 self
像这样的关键字
self.layer1 = self.sigmoid(np.dot(self.input, self.weights1))
self.output = self.sigmoid(np.dot(self.layer1, self.weights2))
关于python - 开发神经网络时如何在python中使用sigmoid函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62258350/
为什么隐藏层中主要选择 log-sigmoid 激活函数而不是 tanh-sigmoid 激活函数?另外,如果我使用 Z 分数归一化,我可以在隐藏层中使用 sigmoid 激活函数吗? 最佳答案 古代
def sigmoid(z): # complete the code z = np.asarray(z) if z.ndim == 0: return(1/(1+np.exp(-z))) e
我尝试了解 sigmoid 函数导数在神经网络中的作用。 首先,我绘制了 sigmoid 函数,以及使用 python 定义的所有点的导数。这个导数到底有什么作用呢? import numpy as
我在 java 中编写了一个 sigmoid 函数,它在处理单个数字时工作正常,但在第一个数据输入后给定数组失败时。这里有一些数据可以说明我的问题(输出四舍五入到 3 位数)。 Input |
我正在创建一个使用反向传播技术进行学习的神经网络。 我知道我们需要找到所用激活函数的导数。我正在使用标准的 sigmoid 函数 f(x) = 1 / (1 + e^(-x)) 我已经看到它的导数是
你好,我正在尝试创建一个程序来计算感知器算法的权重。我现在一切正常,但最基本的是,它是一个阶跃函数,而且是单层的。在我继续使用多层之前,我试图使其成为最优的和 sigmoid。 这就是我的问题,我对
我正在查看 this工作变分自动编码器。 主类 class VAE(nn.Module): def __init__(self): super(VAE, self).__ini
使用链式法则计算成本函数相对于该层权重的斜率时L ,则公式变为: d C0 / d W(L) = ... . d a(L) / d z(L) . ... 与: z (L) being the indu
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
使用链式法则计算成本函数相对于该层权重的斜率时L ,则公式变为: d C0 / d W(L) = ... . d a(L) / d z(L) . ... 与: z (L) being the indu
我正在使用 keras 开发深度网络。有一个激活“硬 sigmoid”。它的数学定义是什么? 我知道什么是 Sigmoid。有人在Quora上问了类似的问题:https://www.quora.com
我正在研究一些神经网络,因为它看起来很有趣。我将 python 代码翻译成 java,它的工作原理就像我想象的那样。它每次都给我正确的值。虽然我想知道你在代码中哪里实现了Sigmoid函数。我在计算输
有没有一种方法可以在不使用像 JAMA 这样的外部库的情况下找到 2D 数组的 sigmoid ?我尝试了以下代码,但失败了。 public static double[][] sigmoid(dou
我是神经网络/PyTorch 的新手。我正在尝试制作一个接受向量x的网络,第一层是h_j = w_j^T * x + b_j,输出是max_j{h_j }。唯一的事情是,我希望通过 w_j = S(k
我有一个包含 516 个号码的列表。这些数字的范围从 0 到 136661043272.12181,并且在此范围内它们分布不均匀。现在我想将这些数字标准化为[0,1],我想使用sigmoid函数,即原
我在最后一层创建了一个带有 sigmoid 激活函数的神经网络,所以我得到的结果在 0 到 1 之间。我想将事物分为 2 个类,所以我检查“数字是否 > 0.5,然后类1 其他 0 级”。都是基本的。
我创建了一个具有典型激活函数(-1 或 1)的简单感知器,它似乎工作正常。然后我阅读了有关 sigmoid 及其在值之间更平滑过渡的用途,但在使用导数时我总是得到 0.0,这会扰乱计算。 sigmoi
这是代码: import numpy as np # sigmoid function def nonlin(x,deriv=False): if(deriv==True):
我实现了一个二元逻辑回归分类器。只是为了玩,我用 tanh 替换了 sigmoid 函数 (1/1 + exp(-z))。结果完全相同,分类阈值相同,均为 0.5,尽管 tanh 的范围为 {-1,1
我使用的是 Microsoft Visual Studio 2010。 公式是y = 1/(1+exp(-e)) 在值的范围内,其中 bih.biWidth 是要迭代的范围。 然而,当我尝试在代码中实
我是一名优秀的程序员,十分优秀!