对于S型函数[MATLAB]中的相同值,结果不同

问题描述

我正试图找出S型函数的结果。当我尝试无循环计算时。我没有得到预期的结果。另一方面,使用for循环可获得实际结果。 问题是,为什么我会得到不同的结果?

%This is a hypothesis of AND operation
x1 = randi([0,1],[1,4]);
x2 = randi([0,4]);
features = [x1;x2]';
theta = [-30 20 20];
x = [ones(length(features),1) features]
z = x * theta';
pred = zeros(length(z),1);
pred = 1 / (1 + exp(-z))
y1 = (pred >= 0.5)
fprintf('Using loop\n')
for i= 1:length(z)
    pred(i) = 1 / (1 + exp(-z(i)));
end
pred
y1 = (pred >= 0.5)

输出:

x =

     1     1     1
     1     0     1
     1     0     0
     1     0     1


pred =

   1.0e-13 *

         0         0    0.9358         0


y1 =

   0   0   0   0

Using loop

pred =
    1.0000    0.0000    0.0000    0.0000


y1 =

   1   0   0   0

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...