简体   繁体   English

八度错误:返回列表中的元素未定义

[英]Octave error: element undefined in return list

I am writing the following octave code: 我正在编写以下八度代码:

function p = predict(Theta1, Theta2, X)
m = size(X, 1);
num_labels = size(Theta2, 1);
global a=zeros(size(Theta2, 2), m);
global delta=zeros(m, 1);

p = zeros(size(X, 1), 1);

X=[ones(size(X,1),1) X];
a=sigmoid(Theta1*X');
a=[ones(1,size(X,1));a];
[delta p]=max(sigmoid(Theta2*a))';

It gives me the error: "element number 2 undefined in return list". 它给我一个错误:“元素编号2在返回列表中未定义”。 The error occurs when I use delta in the last line to store max values. 当我在最后一行中使用增量来存储最大值时,会发生错误。 I have searched a lot but couldn't find any relevant answer. 我已经搜索了很多,但是找不到任何相关的答案。

The line 线

[delta p] = max( sigmoid( Theta2*a ) )'; # transpose operator over the result

is equivalent to 相当于

[delta p] = transpose( max( sigmoid( Theta2*a ) ); # transpose function over the result

which means you are trying to get a "two-output" result out of this transpose operation, which fails, since the transpose function only returns one output, therefore octave is informing you that it cannot find a second output in the 'results' list. 这意味着您试图从此转置操作中获取“双输出”结果,该操作失败,因为转置功能仅返回一个输出,因此,八度表示您无法在“结果”列表中找到第二个输出。

Presumably you either meant to do something along the lines of: 大概您打算按照以下方式做某事:

[delta p] = max( sigmoid( Theta2*a )' );

and misplaced the transpose operator, or you actually did want to obtain the maxima and their indices as a column vector, in which case you need to do this in two steps, ie 并放错了转置运算符的位置,或者您实际上确实想获取最大值及其索引作为列向量,在这种情况下,您需要分两个步骤进行操作,即

[delta p] = max( sigmoid( Theta2*a ) );
ColVector = [delta p]';

PS. PS。 Incidentally, you should use .' 顺便说一句,您应该使用.' instead of ' as the transpose operator. 代替'作为转置运算符。 ' is not the transpose operator, it's the "conjugate transpose" one. '不是转置运算符,它是“共轭转置”之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM