1

In MATLAB, feedforwardnet(8) creates a feedforward network with one hidden layer containing 8 hidden neurons. MATLAB stores numeric data as double-precision floating point (double) by default. Therefore feedforwardnet(8) is equivalent to feedforwardnet(double(8)).

However, feedforwardnet(int32(8)) will raise the following error:

Undefined function or variable 'ind'.

Error in network/subsasgn>setLayerSize (line 1170)
  err = sprintf('"layers{%g}.size" must be a positive integer.',ind);

Error in network/subsasgn>network_subsasgn (line 180)
        if isempty(err), [net,err] = setLayerSize(net,i,newSize); end

Error in network/subsasgn (line 13)
net = network_subsasgn(net,subscripts,v,netname);

Error in feedforwardnet>create_network (line 116)
      net.layers{i}.size = param.hiddenSizes(i);

Error in feedforwardnet (line 69)
    net = create_network(param);

Why won't feedforwardnet() takes an int32 as argument? Equivalently, why doesn't isposint() (in *network/subsasgn.m, line 1169)) returns true when given int32(8) as argument?

The code was tested with MATLAB 2011a, 2012a and 2012b.

4

2 回答 2

4

不确定您拥有哪个版本的工具箱,但 1.7 版isposint(v)测试了这样的论点:

[...]
if ~isa(v,'double') | any(size(v) ~= [1 1]) | ...
  ~isreal(v) | v<0 | round(v) ~= v
[...]

这意味着它将返回所有false不是double.double

至于“未定义的函数或变量'ind'”。消息,我的猜测是因为代码中的错误(变量ind没有在函数的任何地方创建/分配/作为参数传递)。

于 2013-04-11T21:57:55.333 回答
1

在第 9 行编辑(风险自负,未经彻底测试)isposint.m

% if ~isa(v,'double') | any(size(v) ~= [1 1]) | ...
if ~isnumeric(v) | any(size(v) ~= [1 1]) | ...

两者都经过:

a = feedforwardnet(8);
b = feedforwardnet(int32(8));

大小变化不大:

>> whos
  Name      Size            Bytes  Class      Attributes

  a         1x1             31224  network              
  b         1x1             30968  network
于 2013-04-11T22:32:49.083 回答