神经网络的Scilab

认识我试着运行这个例子,它采用神经网络工具箱的Scilab https://burubaxair.wordpress.com/2014/03/12/artificial-neural-networks-in-scilab/神经网络的Scilab

这是代码:

T = [ 

1 1 1 1 1

0 0 1 0 0

0 0 1 0 0

0 0 1 0 0

0 0 1 0 0

0 0 1 0 0

0 0 1 0 0

]';

U = [

1 0 0 0 1

1 0 0 0 1

1 0 0 0 1

1 0 0 0 1

1 0 0 0 1

1 0 0 0 1

0 1 1 1 0

]';

N = [35 10 2];

W = ann_FF_init(N);

x = [1, 0, 0, 0, 1;

1, 0, 0, 0, 1;

1, 0, 0, 0, 1;

1, 0, 0, 0, 1;

1, 0, 0, 0, 1;

1, 0, 0, 0, 1;

0, 1, 1, 1, 0]';

t_t = [1 0]';

t_u = [0 1]';

t = [t_t, t_u];

lp = [0.01, 1e-4];

epochs = 3000;

W = ann_FF_Std_batch(x,t,N,W,lp,epochs);

y = ann_FF_run(x,N,W)

disp(y)

但是我收到一个错误:

-->exec('D:\Учёба\Задачи\Recognition.sce', -1) 

!--error 15

Подматрица задана некорректно (Submatrix is incorrect).

at line 37 of function ann_FF_grad_BP called by :

at line 25 of function ann_FF_Std_batch called by :

W = ann_FF_Std_batch(x,t,N,W,lp,epochs);

at line 33 of exec file called by :

exec('D:\Учёба\Задачи\Recognition.sce', -1)

一个错误可能在T和U矩阵中,但我不明白为什么。你能告诉我做错了什么吗?谢谢!

回答:

你让你的代码2级的错误:

  1. 你不应该混合测试和训练集。
  2. 测试输入必须是单列。

您的第一个错误是x = [ 1.... ],因为它包含一个图像,而您在N中指定您有两个输出神经元。 正如例子说,你应该有x = [T,U];

你的第二个错误是给X作为测试ann_FF_run。该功能将测试输入作为单个列。但是因为你在x是5x7矩阵之前用x训练了你的NN。只需将其更改为列向量。

这里校正和注释的代码:

T = [... 

1 1 1 1 1 ...

0 0 1 0 0 ...

0 0 1 0 0 ...

0 0 1 0 0 ...

0 0 1 0 0 ...

0 0 1 0 0 ...

0 0 1 0 0 ...

]';

U = [...

1 0 0 0 1 ...

1 0 0 0 1 ...

1 0 0 0 1 ...

1 0 0 0 1 ...

1 0 0 0 1 ...

1 0 0 0 1 ...

0 1 1 1 0 ...

]';

// setting the traing set of two image

xtrain = [T,U];

// so each image as 35 pixels so N(1) is 35

// and we have two images so N($) is 2

N = [35 10 2];

// training the NN

W = ann_FF_init(N);

// The expected response for T : 1 for T, 0 for U

t_t = [1 0]';

// The expected response for T : 1 for T, 0 for U

t_u = [0 1]';

// the overall response

t = [t_t, t_u];

// some parameters

lp = [0.01, 1e-4];

epochs = 3000;

// getting the weight of the trained NN

W = ann_FF_Std_batch(xtrain,t,N,W,lp,epochs);

// testing the traing set.

y = ann_FF_run(xtrain,N,W)

disp('Testing the traing set')

disp(y) //should get something close to t ~ [1 0 ; 0 1]

// testing a distord U

xtest1 = matrix([1, 0, 0, 0, 1;

1, 1, 0, 0, 1;

1, 0, 0, 0, 1;

1, 0, 0, 0, 1;

1, 0, 0, 0, 1;

1, 0, 0, 0, 1;

0, 1, 1, 1, 1]',-1,1);

y = ann_FF_run(xtest1,N,W)

disp('Testing a distored U')

disp(y) //should get something close to t_u ~ [0 1]

//testing something different from T and U. should get nothing

xtest2 = matrix([1, 0, 0, 0, 1;

1, 1, 0, 0, 1;

1, 0, 1, 0, 1;

1, 0, 1, 0, 1;

0, 0, 1, 1, 1;

0, 0, 1, 0, 1;

0, 1, 1, 1, 1]',-1,1);

y = ann_FF_run(xtest2,N,W)

disp('Testing something neither T nor U')

disp(y)

和SCILAB的控制台输出

Testing the traing set 

0.8538757 0.1075397

0.1393287 0.8957439

Testing a distored U

0.1078667

0.9007755

Testing something neither T nor U

0.3433933

0.6306797

以上是 神经网络的Scilab 的全部内容, 来源链接: utcz.com/qa/265301.html

回到顶部