dart backy - 无法运行基本示例

时间:2014-12-21 16:36:41

标签: dart neural-network

我尝试运行Backy的例子

https://pub.dartlang.org/packages/backy

 import "package:backy/backy.dart";

 // 1.
 var neuron  = new TanHNeuron(); // returnes floatingpoint values between -1 and 1
 var student = new Backy([2, 2, 1], neuron);
 var trainer = new Trainer(backy: student, maximumReapeatingCycle: 200, precision: .1);

 // 2. Add the pattern whcih the network should learn
 trainer.addTrainingCase([-1,-1], [-1]);
 trainer.addTrainingCase([-1, 1], [-1]);
 trainer.addTrainingCase([ 1,-1], [-1]);
 trainer.addTrainingCase([ 1, 1], [ 1]);

 // 3. train all the traininCases up to 300 times and be satisfied with a precision of           .1
 print(trainer.trainOnlineSets()); // prints number loops it took to learn all      trainingcases

 // 4. After that you can use the neural network
 print(student.use([-1,-1]));
 print(student.use([-1, 1]));
 print(student.use([ 1,-1]));
 print(student.use([ 1, 1]));

trainer.addTrainingCase([-1,-1], [-1]);给我错误:

 Multiple markers at this line
 - Expected a method, getter, setter or operator declaration
 - Unexpected token '('
 - Undefined class 'trainer.addTrainingCase' 

我真的不知道为什么会出现这个错误。

1 个答案:

答案 0 :(得分:0)

您无法在函数或方法之外运行代码。我不知道为什么这个例子是以这种方式发布的,但是当你用main()方法将它括起来时,你可以摆脱错误并运行示例

import "package:backy/backy.dart";

 // 1.
 var neuron  = new TanHNeuron(); // returnes floatingpoint values between -1 and 1
 var student = new Backy([2, 2, 1], neuron);
 var trainer = new Trainer(backy: student, maximumReapeatingCycle: 200, precision: .1);

void main() {
 // 2. Add the pattern whcih the network should learn
 trainer.addTrainingCase([-1, -1], [-1]);
 trainer.addTrainingCase([-1, 1], [-1]);
 trainer.addTrainingCase([ 1, -1], [-1]);
 trainer.addTrainingCase([ 1, 1], [ 1]);

 // 3. train all the traininCases up to 300 times and be satisfied with a precision of           .1
 print(trainer.trainOnlineSets()); // prints number loops it took to learn all      trainingcases

 // 4. After that you can use the neural network
 print(student.use([-1, -1]));
 print(student.use([-1, 1]));
 print(student.use([ 1, -1]));
 print(student.use([ 1, 1]));
}