Encog3Java-User.pdf翻译:第六章 更多监控训练

来源:互联网 发布:沙发颜色选择技巧知乎 编辑:程序博客网 时间:2024/04/28 20:31
Chapter 6
第六章


More Supervised Training
更多监控训练


? Introducing the Lunar Lander Example
? Supervised Training without Training Sets
? Using Genetic Algorithms
? Using Simulated Annealing
? Genetic Algorithms and Simulated Annealing with Training Sets
So far, this book has only explored training a neural network by using the supervised propagation training methods. This chapter will look at some nonpropagation training techniques. The neural network in this chapter will be trained without a training set. It is still supervised in that feedback from the neural network’s output is constantly used to help train the neural network.
到目前为止,本书只使用监督传播训练方法来训练神经网络。本章将看一些非传播的训练技术。本章中的神经网络将在没有训练集的情况下进行训练,但依然在经常被用来帮助训练神经网络的输出反馈的监督下。


We simply will not supply training data ahead of time. Two common techniques for this sort of training are simulated annealing and genetic algorithms. Encog provides built-in support for both. The example in this chapter can be trained with either algorithm, both of which will be discussed later in this chapter.
我们不会提前提供培训数据。这种训练的两种常用技术是模拟退火和遗传算法。encog提供了内置支持。本章中的例子可以用这两种算法进行训练,这两种算法都将在本章后面讨论。


The example in this chapter presents the classic “Lunar Lander” game.This game has been implemented many times and is almost as old as computers themselves. You can read more about the Lunar Lander game on Wikipedia.
本章的例子展示了经典的“月球着陆器”游戏,这款游戏已经多次实现,几乎和电脑一样老。你可以在维基百科上阅读更多关于Lunar Lander的游戏。


http://en.wikipedia.org/wiki/Lunar_Lander_%28computer_game%29
The idea behind most variants of the Lunar Lander game is very similar and the example program works as follows: The lunar lander spacecraft will begin to fall. As it falls, it accelerates. There is a maximum velocity that the lander can reach, which is called the ‘terminal velocity.’ Thrusters can be applied to the lander to slow its descent. However, there is a limited amount of fuel. Once the fuel is exhausted, the lander will simply fall, and nothing can be done.
月球着陆器游戏的大多数变种背后的想法非常相似,示例程序的工作原理如下:月球着陆器宇宙飞船将开始坠落。当它下降时,它加速。着陆器可以达到最大速度,称为“末速”。推进器可以应用于着陆器以减慢其降落速度。然而,燃料的数量是有限的。一旦燃料耗尽,着陆器就会掉下来,什么也做不了。


This chapter will teach a neural network to pilot the lander. This is a very simple text-only simulation. The neural network will have only one option available to it. It can either decide to fire the thrusters or not to fire the thrusters. No training data will be created ahead of time and no assumptions will be made about how the neural network should pilot the craft. If using training sets, input would be provided ahead of time regarding what the neural network should do in certain situations. For this example, the neural network will learn everything on its own.
本章将教一个神经网络来引导着陆器。这是一个非常简单的纯文本模拟。神经网络只有一个选项可供选择。它可以决定启动推进器,也可以关闭推进器。没有预先建立训练数据,也不会对神经网络如何引导飞行器进行假设。如果使用训练集,输入将提前提供关于神经网络在某些情况下应该做什么的信息。对于这个例子,神经网络将自己学习所有的东西。


Even though the neural network will learn everything on its own, this is still supervised training. The neural network will not be totally left to its own devices. It will receive a way to score the neural network. To score the neural network, we must give it some goals and then calculate a numeric value that determines how well the neural network achieved its goals.
尽管神经网络将自己学习所有的东西,但这仍然是有监督的训练。神经网络没有被完全不管。它将获得一种给神经网络评分的方法。对于评分神经网络,我们必须给它一些目标,然后计算一个数值,它决定了神经网络达到目标的程度。


These goals are arbitrary and simply reflect what was picked to score the network. The goals are summarized here:
这些目标是任意的,只是反映了什么被挑选出来评分网络。这里总结了目标:


? Land as softly as possible
尽量轻地着陆
? Cover as much distance as possible
降落所用时间尽可能长
? Conserve fuel
节约燃料


The first goal is not to crash, but to try to hit the lunar surface as softly as possible. Therefore, any velocity at the time of impact is a very big negative score. The second goal for the neural network is to try to cover as much distance as possible while falling. To do this, it needs to stay aloft as long as possible and additional points are awarded for staying aloft longer. Finally, bonus points are given for still having fuel once the craft lands. The score calculation can be seen in Equation 6.1.
第一个目标是不要坠毁,要尽可能轻柔地撞击月球表面。因此,撞击时的任何速度都是一个很大的负分。神经网络的第二个目标是降落所用时间尽可能长。要做到这一点,它需要尽可能长时间地停留在空中,并为在空中停留更长时间加分。最后,还有一点奖励:一旦飞船着陆,仍然有燃料。分数计算可以在等式6.1中看到。

score = (fuel · 10) + (velocity · 1000) + fuel (6.1) 


In the next section we will run the Lunar Lander example and observe as it learns to land a spacecraft.
在下一节,我们将运行月球着陆器的例子和观察它学习着陆航天器。


6.1 Running the Lunar Lander Example
6.1 运行Lunar Lander例子


To run the Lunar Lander game you should execute the LunarLander class. This class is located at the following location.
运行的月球着陆器的游戏你应该执行lunarlander类。该类位于以下位置。


org.encog.examples.neural.lunar.LunarLander
This class requires no arguments. Once the program begins, the neural network immediately begins training. It will cycle through 50 epochs, or training iterations, before it is done. When it first begins, the score is a negative number. These early attempts by the untrained neural network are hitting the moon at high velocity and are not covering much distance.
这个类不需要参数。一旦程序开始,神经网络立即开始训练。在它完成之前,它会周期性地经过50个纪元,或者训练迭代。当它开始时,得分是负数。这些未经训练的神经网络的早期尝试是以高速度撞击月球并且没有覆盖太多距离。


Epoch #1 Score :-299.0
Epoch #2 Score :-299.0
Epoch #3 Score :-299.0
Epoch #4 Score :-299.0
Epoch #5 Score :-299.0
Epoch #6 Score :-299.0
Epoch #7 Score :-299.0
After the seventh epoch, the score begins to increase.
Epoch #8 Score :-96.0
Epoch #9 Score : 5 7 6 0.0
Epoch #10 Score : 5 7 6 0.0
Epoch #11 Score : 5 7 6 0.0
Epoch #12 Score : 5 7 6 0.0
Epoch #13 Score : 5 7 6 0.0
Epoch #14 Score : 5 7 6 0.0
Epoch #15 Score : 5 7 6 0.0
Epoch #16 Score : 5 7 6 0.0
Epoch #17 Score : 6 1 9 6.0
Epoch #18 Score : 6 1 9 6.0
Epoch #19 Score : 6 1 9 6.0
The score will hover at 6,196 for awhile, but will improve at a later epoch.
Epoch #45 Score : 6 2 7 5.0
Epoch #46 Score : 6 2 7 5.0
Epoch #47 Score : 7 3 4 7.0
Epoch #48 Score : 7 3 4 7.0
Epoch #49 Score : 7 4 6 0.0
Epoch #50 Score : 7 4 6 0.0
By the 50th epoch, a score of 7,460 has been achieved. The training techniques used in this chapter make extensive use of random numbers. As a result, running this example multiple times may result in entirely different scores.
到了第五十迭代,已经达到了7460分。本章所使用的训练技术对随机数进行了广泛的应用。因此,多次运行这个示例可能会导致完全不同的分数。


More epochs may have produced a better-trained neural network; however, the program limits it to 50. This number usually produces a fairly skilled neural pilot. Once the network is trained, run the simulation with the winning pilot. The telemetry is displayed at each second.
更多的迭代可能产生了更好的训练神经网络;然而,程序将它限制在50。这个数字通常会产生相当熟练的神经飞行员。一旦网络得到训练,就与获胜的飞行员进行仿真。遥测每秒显示。


The neural pilot kept the craft aloft for 911 seconds. So, we will not show every telemetry report. However, some of the interesting actions that this neural pilot learned are highlighted. The neural network learned it was best to just let the craft free-fall for a while. How the winning network landed :
神经驾驶员把飞船保持在高空911秒。因此,我们不会显示每一个遥测报告。然而,这种神经飞行员所学的一些有趣的动作被高亮显示。神经网络学会最好是让飞船自由下落一段时间。获胜网络是如何着陆的:


Elapsed : 1 s , Fuel : 200 l , Velocity :-1.6200 m/s , 9998 m
Elapsed : 2 s , Fuel : 200 l , Velocity :-3.2400 m/s , 9995 m
Elapsed : 3 s , Fuel : 200 l , Velocity :-4.8600 m/s , 9990 m
Elapsed : 4 s , Fuel : 200 l , Velocity :-6.4800 m/s , 9983 m
Elapsed : 5 s , Fuel : 200 l , Velocity :-8.1000 m/s , 9975 m
Elapsed : 6 s , Fuel : 200 l , Velocity :-9.7200 m/s , 9965 m
Elapsed : 7 s , Fuel : 200 l , Velocity :-11.3400 m/s , 9954 m
Elapsed : 8 s , Fuel : 200 l , Velocity :-12.9600 m/s , 9941 m
Elapsed : 9 s , Fuel : 200 l , Velocity :-14.5800 m/s , 9927 m
Elapsed : 10 s , Fuel : 200 l , Velocity :-16.2000 m/s , 9910 m
Elapsed : 11 s , Fuel : 200 l , Velocity :-17.8200 m/s , 9893 m
Elapsed : 12 s , Fuel : 200 l , Velocity :-19.4400 m/s , 9873 m
Elapsed : 13 s , Fuel : 200 l , Velocity :-21.0600 m/s , 9852 m
Elapsed : 14 s , Fuel : 200 l , Velocity :-22.6800 m/s , 9829 m
Elapsed : 15 s , Fuel : 200 l , Velocity :-24.3000 m/s , 9805 m
Elapsed : 16 s , Fuel : 200 l , Velocity :-25.9200 m/s , 9779 m
Elapsed : 17 s , Fuel : 200 l , Velocity :-27.5400 m/s , 9752 m
Elapsed : 18 s , Fuel : 200 l , Velocity :-29.1600 m/s , 9722 m
Elapsed : 19 s , Fuel : 200 l , Velocity :-30.7800 m/s , 9692 m
Elapsed : 20 s , Fuel : 200 l , Velocity :-32.4000 m/s , 9659 m
Elapsed : 21 s , Fuel : 200 l , Velocity :-34.0200 m/s , 9625 m
Elapsed : 22 s , Fuel : 200 l , Velocity :-35.6400 m/s , 9590 m
Elapsed : 23 s , Fuel : 200 l , Velocity :-37.2600 m/s , 9552 m
Elapsed : 24 s , Fuel : 200 l , Velocity :-38.8800 m/s , 9514 m
Elapsed : 25 s , Fuel : 200 l , Velocity :-40.0000 m/s , 9473 m
Elapsed : 26 s , Fuel : 200 l , Velocity :-40.0000 m/s , 9431 m
Elapsed : 27 s , Fuel : 200 l , Velocity :-40.0000 m/s , 9390 m
You can see that 27 seconds in and 9,390 meters above the ground, the terminal velocity of -40 m/s has been reached. There is no real science behind -40 m/s being the terminal velocity; it was just chosen as an arbitrary number. Having a terminal velocity is interesting because the neural networks learn that once this is reached, the craft will not speed up. They use the terminal velocity to save fuel and “break their fall” when they get close to the surface. The freefall at terminal velocity continues for some time. Finally, at 6,102 meters above the ground, the thrusters are fired for the first time.
你可以看到,在27秒和离地面9390米处,已经到达了40米/秒的终端速度。没有什么科学依据- 40米/秒是终端速度,它只是作为一个任意数选择。终端速度是很有趣的,因为神经网络知道一旦达到这个目标,飞行器就不会加速。他们使用终端速度来节省燃料,当接近地面时“中断它们的下落”。自由落体的终端速度持续一段时间。最后,在地面6102米处,推进器第一次开火。


Elapsed : 105 s , Fuel : 200 l , Velocity :-40.0000 m/s , 6143 m
Elapsed : 106 s , Fuel : 200 l , Velocity :-40.0000 m/s , 6102 m
THRUST
Elapsed : 107 s , Fuel : 199 l , Velocity :-31.6200 m/s , 6060 m
Elapsed : 108 s , Fuel : 199 l , Velocity :-33.2400 m/s , 6027 m
Elapsed : 109 s , Fuel : 199 l , Velocity :-34.8600 m/s , 5992 m
Elapsed : 110 s , Fuel : 199 l , Velocity :-36.4800 m/s , 5956 m
Elapsed : 111 s , Fuel : 199 l , Velocity :-38.1000 m/s , 5917 m
Elapsed : 112 s , Fuel : 199 l , Velocity :-39.7200 m/s , 5878 m
THRUST
Elapsed : 113 s , Fuel : 198 l , Velocity :-31.3400 m/s , 5836 m
Elapsed : 114 s , Fuel : 198 l , Velocity :-32.9600 m/s , 5803 m
Elapsed : 115 s , Fuel : 198 l , Velocity :-34.5800 m/s , 5769 m
Elapsed : 116 s , Fuel : 198 l , Velocity :-36.2000 m/s , 5733 m
Elapsed : 117 s , Fuel : 198 l , Velocity :-37.8200 m/s , 5695 m
The velocity is gradually slowed, as the neural network decides to fire the thrusters every six seconds. This keeps the velocity around -35 m/s.
速度被逐渐减慢,神经网络决定每6秒点一次火。保持速度在-35 m/s左右。


THRUST
Elapsed : 118 s , Fuel : 197 l , Velocity :-29.4400 m/s , 5655 m
Elapsed : 119 s , Fuel : 197 l , Velocity :-31.0600 m/s , 5624 m
Elapsed : 120 s , Fuel : 197 l , Velocity :-32.6800 m/s , 5592 m
Elapsed : 121 s , Fuel : 197 l , Velocity :-34.3000 m/s , 5557 m
Elapsed : 122 s , Fuel : 197 l , Velocity :-35.9200 m/s , 5521 m
THRUST
Elapsed : 123 s , Fuel : 196 l , Velocity :-27.5400 m/s , 5484 m
Elapsed : 124 s , Fuel : 196 l , Velocity :-29.1600 m/s , 5455 m
Elapsed : 125 s , Fuel : 196 l , Velocity :-30.7800 m/s , 5424 m
Elapsed : 126 s , Fuel : 196 l , Velocity :-32.4000 m/s , 5392 m
Elapsed : 127 s , Fuel : 196 l , Velocity :-34.0200 m/s , 5358 m
Elapsed : 128 s , Fuel : 196 l , Velocity :-35.6400 m/s , 5322 m
THRUST
As the craft gets closer to the lunar surface, this maximum allowed velocity begins to decrease. The pilot is slowing the craft, as it gets closer to the lunar surface. At around 4,274 meters above the surface, the neural network decides it should now thrust every five seconds. This slows the descent to around -28 m/s.
当飞行器接近月球表面时,最大速度开始下降。当飞行器接近月球表面时,飞行员正减慢速度。大约离地面4,274米时,神经网络决定应该每5秒反推一次。速度减缓到-28 m/s。


THRUST
Elapsed : 163 s , Fuel : 189 l , Velocity :-22.3400 m/s , 4274 m
Elapsed : 164 s , Fuel : 189 l , Velocity :-23.9600 m/s , 4250 m
Elapsed : 165 s , Fuel : 189 l , Velocity :-25.5800 m/s , 4224 m
Elapsed : 166 s , Fuel : 189 l , Velocity :-27.2000 m/s , 4197 m
Elapsed : 167 s , Fuel : 189 l , Velocity :-28.8200 m/s , 4168 m
THRUST
Elapsed : 168 s , Fuel : 188 l , Velocity :-20.4400 m/s , 4138 m
Elapsed : 169 s , Fuel : 188 l , Velocity :-22.0600 m/s , 4116 m
Elapsed : 170 s , Fuel : 188 l , Velocity :-23.6800 m/s , 4092 m
Elapsed : 171 s , Fuel : 188 l , Velocity :-25.3000 m/s , 4067 m
Elapsed : 172 s , Fuel : 188 l , Velocity :-26.9200 m/s , 4040 m
Elapsed : 173 s , Fuel : 188 l , Velocity :-28.5400 m/s , 4011 m
THRUST
By occasionally using shorter cycles, the neural pilot slows it even further by the time it reaches only 906 meters above the surface. The craft has been slowed to -14 meters per second.
通过偶尔使用更短的周期,神经飞行员减慢它达到离地面906米的地方使用了更多时间。飞船已经减慢到每秒14米。


THRUST
Elapsed : 320 s , Fuel : 162 l , Velocity :-6.6800 m/s , 964 m
Elapsed : 321 s , Fuel : 162 l , Velocity :-8.3000 m/s , 955 m
Elapsed : 322 s , Fuel : 162 l , Velocity :-9.9200 m/s , 945 m
Elapsed : 323 s , Fuel : 162 l , Velocity :-11.5400 m/s , 934 m
Elapsed : 324 s , Fuel : 162 l , Velocity :-13.1600 m/s , 921 m
Elapsed : 325 s , Fuel : 162 l , Velocity :-14.7800 m/s , 906 m
THRUST
Elapsed : 326 s , Fuel : 161 l , Velocity :-6.4000 m/s , 890 m
Elapsed : 327 s , Fuel : 161 l , Velocity :-8.0200 m/s , 882 m
Elapsed : 328 s , Fuel : 161 l , Velocity :-9.6400 m/s , 872 m
Elapsed : 329 s , Fuel : 161 l , Velocity :-11.2600 m/s , 861 m
Elapsed : 330 s , Fuel : 161 l , Velocity :-12.8800 m/s , 848 m
Elapsed : 331 s , Fuel : 161 l , Velocity :-14.5000 m/s , 833 m
THRUST
This short cycling continues until the craft has slowed its velocity considerably. It even thrusts to the point of increasing its altitude towards the final seconds of the flight.
这种短程循环一直持续到飞船减慢速度为止。它甚至达到了在飞行的最后几秒增加了高度。


Elapsed : 899 s , Fuel : 67 l , Velocity : 5.3400 m/s , 2 m
Elapsed : 900 s , Fuel : 67 l , Velocity : 3.7200 m/s , 5 m
Elapsed : 901 s , Fuel : 67 l , Velocity : 2.1000 m/s , 8 m
Elapsed : 902 s , Fuel : 67 l , Velocity : 0.4800 m/s , 8 m
Elapsed : 903 s , Fuel : 67 l , Velocity :-1.1400 m/s , 7 m
Elapsed : 904 s , Fuel : 67 l , Velocity :-2.7600 m/s , 4 m
THRUST
Elapsed : 905 s , Fuel : 66 l , Velocity : 5.6200 m/s , 0 m
Elapsed : 906 s , Fuel : 66 l , Velocity : 4.0000 m/s , 4 m
Elapsed : 907 s , Fuel : 66 l , Velocity : 2.3800 m/s , 6 m
Elapsed : 908 s , Fuel : 66 l , Velocity : 0.7600 m/s , 7 m
Elapsed : 909 s , Fuel : 66 l , Velocity :-0.8600 m/s , 6 m
Elapsed : 910 s , Fuel : 66 l , Velocity :-2.4800 m/s , 4 m
THRUST
Elapsed : 911 s , Fuel : 65 l , Velocity : 5.9000 m/s , 0 m
Finally, the craft lands, with a very soft velocity of positive 5.9. You wonder why the lander lands with a velocity of 5.9. This is due to a slight glitch in the program. This “glitch” is left in because it illustrates an important point: when neural networks are allowed to learn, they are totally on their own and will take advantage of everything they can find.
最后,飞船降落,以非常软的速度为正5.9。你想知道为什么着陆器以5.9的速度着陆。这是由于程序中有一点小毛病。这个“小故障”之所以存在,是因为它说明了一个重要的问题:当神经网络被允许学习时,它们完全是自己的,并且将利用他们所能找到的一切。


The final positive velocity is because the program decides if it wants to thrust as the last part of a simulation cycle. The program has already decided the craft’s altitude is below zero, and it has landed. But the neural network “sneaks in” that one final thrust, even though the craft is already landed and this thrust does no good. However, the final thrust does increase the score of the neural network.
最后的正速度是因为程序决定它是否要作为模拟周期的最后一部分进行推力。这个程序已经决定了飞船的高度在零以下,并且着陆了。而神经网络最后一个“乱入的”推力,虽然飞行器已登陆这个推力没用。然而,最后的推力确实增加了神经网络的得分。


Recall equation 6.1. For every negative meter per second of velocity at landing, the program score is decreased by 1,000. The program figured out that the opposite is also true. For every positive meter per second of velocity, it also gains 1,000 points. By learning about this little quirk in the program, the neural pilot can obtain even higher scores.
回看方程式6.1。在着陆时每秒钟的负速度每秒,程序得分减少1000。这个程序发现相反的情况也是这样。对于每米每秒的正速度,它也得到1000点。通过学习程序中的这个小魔鬼,神经飞行员可以获得更高的分数。


The neural pilot learned some very interesting things without being fed a pre-devised strategy. The network learned what it wanted to do. Specifically, this pilot decided the following:
神经飞行员学习了一些非常有趣的东西,尽管没有预先设计策略。网络学习到了它想做什么。具体来说,这个飞行员决定如下:


? Free-fall for some time to take advantage of terminal velocity.
自由落体一段时间,利用终端速度优势。
? At a certain point, break the freefall and slow the craft.
在某一点上,打破自由落体,减缓飞行器下降速度。
? Slowly lose speed as you approach the surface.
接近地面时慢慢减小速度。
? Give one final thrust, after landing, to maximize score.
着陆后给最后一个推力,最大限度地得分。
The neural pilot in this example was trained using a genetic algorithm. Genetic algorithms and simulated annealing will be discussed later in this chapter. First, we will see how the Lander was simulated and how its score is actually calculated.
本例中的神经飞行员使用遗传算法进行训练。遗传算法和模拟退火将在本章后面讨论。首先,我们将了解着陆器是如何模拟的,以及它的得分是如何计算出来的。


6.2 Examining the Lunar Lander Simulator
6.2 检查月球着陆模拟器


We will now examine how the Lunar Lander example was created by physical simulation and how the neural network actually pilots the spacecraft. Finally, we will see how the neural network learns to be a better pilot.
我们现在将研究如何通过物理模拟创建月球着陆器的例子,以及神经网络实际上如何引导航天器。最后,我们将看到神经网络如何学习成为一个更好的飞行员。


6.2.1 Simulating the Lander
6.2.1 模拟着陆器


First, we need a class that will simulate the “physics” of lunar landing. The term “physics” is used very loosely. The purpose of this example is more on how a neural network adapts to an artificial environment than any sort of realistic physical simulation. All of the physical simulation code is contained in the LanderSimulator class. This class can be found at the following location. 
首先,我们需要一个模拟物理着陆月球的类。“物理学”这个词使用得很随意。这个例子的目的更多地是关于一个神经网络如何适应一个人工环境而不是任何一种真实的物理模拟。所有的物理仿真代码都包含在landersimulator类。可以在以下位置找到此类。


org.encog.examples.neural.lunar.LanderSimulator
This class begins by defining some constants that will be important to the simulation.
这个类首先定义一些对模拟非常重要的常量。


public static final double GRAVITY = 1.6 2 ;
public static final double THRUST = 1 0 ;
public static final double TERMINAL VELOCITY = 4 0 ;
The GRAVITY constant defines the acceleration on the moon that is due to gravity. It is set to 1.62 and is measured in meters per second. The THRUST constant specifies how the number of meters per second by which the gravity acceleration will be countered. The TERMINAL VELOCITY is the fastest speed that the spacecraft can travel either upward or downward. In addition to these constants, the simulator program will need several instance variables to maintain state. These variables are listed below as follows:
重力常数定义了月球重力加速度。设置为1.62,以米每秒计算。推力常数规定了每秒抵消重力加速度的量。终端速度是航天器可以向上或向下移动的最快速度。除了这些常量之外,模拟器程序还需要几个实例变量来维护状态。这些变量如下所示:


private int fuel;
private int seconds ;
private double altitude;
private double velocity;
The fuel variable holds the amount of fuel remaining. The seconds variable holds the number of seconds aloft. The altitude variable holds the current altitude in meters. The velocity variable holds the current velocity. Positive numbers indicate that the craft is moving upwards. Negative numbers indicate that the craft is moving downwards. The simulator sets the values to reasonable starting values in the following constructor:
燃料变量保存燃料剩余量。秒变量保存停留空中的秒数。海拔高度保存当前高度。速度变量保存当前速度。正数表明飞船在向上移动。负数表明飞船在向下移动。模拟器在下面的构造函数中将值设置为合理的起始值:


public LanderSimulator ( ) {
this.fuel= 200;
this.seconds = 0 ;
this.altitude= 10000;
this.velocity= 0 ;
}
The craft starts with 200 liters and the altitude is set to 10,000 meters above ground. The turn method processes each “turn.” A turn is one second in the simulator. The thrust parameter indicates whether the spacecraft wishes to thrust during this turn.
飞船以200升燃料开始,高度设置在10000米以上。turn方法处理每个“转换”。在模拟器中一次转换是一秒。推力参数表明飞船在这次转换过程中是否希望启动推力。


public void turn ( boolean thrust ) {
First, increase the number of seconds elapsed by one. Decrease the velocity by the GRAVITY constant to simulate the fall.
首先,秒数加1,表示逝去1秒。用重力常数来降低速度以模拟下降。
this.seconds++;
this.velocity-=GRAVITY;
The current velocity increases the altitude. Of course, if the velocity is negative, the altitude will decrease.
当前速度增大了海拔高度。当然,如果速度是负的,高度就会降低。
this.altitude+=this.velocity;
If thrust is applied during this turn, then decrease the fuel by one and increase the velocity by the THRUST constant.
如果在这个转换处施加了推力,则将燃油减少一,并通过推力常数增加速度。
i f ( thrust && this.fuel >0 ) {
this.fuel--;
this.velocity+=THRUST;
}
Terminal velocity must be imposed as it cannot fall or ascend faster than the terminal velocity. The following line makes sure that the lander is not ascending faster than the terminal velocity.
飞行器的下降或上升速度不能大于终端速度。下面的代码确保着陆器的上升速度不超过终端速度。
this.velocity= Math.max(
?TERMINAL VELOCITY,
this.velocity) ;
The following line makes sure that we are not descending faster than the terminal velocity.
下面代码确保我们下降速度不大于终端速度。
this.velocity= Math.min (
TERMINAL VELOCITY,
this.velocity) ;
The following line makes sure that the altitude does not drop below zero. It is important to prevent the simulation of the craft hitting so hard that it goes underground.
下面代码确保高度不会降到零以下。这是很重要的,以防止飞行器模拟着陆太硬以至于闯到地下去。
i f ( this.altitude <0)
this.altitude= 0;
}
In addition to the simulation code, the LanderSimulator also provides two utility functions. The first calculates the score and should only be called after the spacecraft lands. This method is shown here.
除了模拟代码,landersimulator还提供了两个实用功能。第一个计算的分数,应该只在航天器着陆后调用。此处显示此方法。
public int score () {
return ( int ) (( this.f u e l-10)
+ this.seconds
+ ( this.velocity-1000) ) ;
}
The score method implements Equation 6.1. As you can see, it uses fuel, seconds and velocity to calculate the score according to the earlier equation. Additionally, a method is provided to determine if the spacecraft is still flying. If the altitude is greater than zero, it is still flying.
记分方法实现等式6.1。正如你所看到的,它使用燃料、秒和速度来计算分数。此外,还提供了一种确定飞船是否仍在飞行的方法。如果高度大于零,它仍在飞行。
public boolean f l y i n g () {
return ( this.altitude >0) ;
}
In the next section, we will see how the neural network actually flies the spacecraft and is given a score.
在下一节中,我们将看到神经网络是如何实际飞行并获得一个分数的。
6.2.2 Calculating the Score
6.2.2 计算分数
The PilotScore class implements the code necessary for the neural network to fly the spacecraft. This class also calculates the final score after the craft has landed. This class is shown in Listing 6.1.
pilotscore类实现飞行航天器的神经网络所需的代码。这个类还计算在登陆后的最终得分。这个类如清单6.1所示。
Listing 6.1: Calculating the Lander Score
package org.encog.examples.neural.lunar ;
import org.encog.neural.networks.BasicNetwork ;
import org.encog.neural.networks.training.CalculateScore;
public class PilotScore implements CalculateScore{
public double CalculateScore( BasicNetwork network ) {
NeuralPilot pilot= new NeuralPilot( network , false ) ;
return pilot.scorePilot( ) ;
}
public boolean shouldMinimize ( ) {
return false ;
}
}
As you can see from the following line, the PilotScore class implements the CalculateScore interface.
正如你可以看到下面代码,这pilotscore类实现calculatescore接口。
public class Pilotscoreimplements CalculateScore{
The CalculateScore interface is used by both Encog simulated annealing and genetic algorithms to determine how effective a neural network is at solving the given problem. A low score could be either bad or good depending on the problem.
encog的模拟退火和遗传算法都使用了calculatescore接口,来确定神经网络在解决被给的问题时效率如何。根据不同的问题,低分可以是坏的也可以是好的。


The CalculateScore interface requires two methods. This first method is named calculateNetworkScore. This method accepts a neural network and returns a double that represents the score of the network.
calculatescore接口要求两个方法。方法一被称为calculatenetworkscore。此方法接受一个神经网络,返回一个表示网络分数的double。


public double calculateNetworkScore (
BasicNetwork network ) {
NeuralPilot pilot= new NeuralPilot( network , false ) ;
return pilot.scorePilot( ) ;
}
The second method returns a value to indicate if the score should be minimized.
public boolean shouldMinimize ( ) {
return false ;
}
For this example we would like to maximize the score. As a result the shouldMinimize method returns false.
对于这个例子,我们想最大化得分。作为结果,shouldminimize方法返回false。
6.2.3 Flying the Spacecraft
6.2.3 驾驶天空飞船
This section shows how the neural network actually flies the spacecraft. The neural network will be fed environmental information such as fuel remaining, altitude and current velocity. The neural network will then output a single value that will indicate if the neural network wishes to thrust. The NeuralPilot class performs this flight. You can see the NeuralPilot class at the following location:
本节展示了神经网络是如何实际飞行的。神经网络将提供环境信息,如燃料剩余、高度和当前速度。然后神经网络输出一个值,表示神经网络是否希望启动推力。neuralpilot类执行此飞行。可以在以下位置看到neuralpilot类:


org.encog.examples.neural.lunar.Neuralpilot
The NeuralPilot constructor sets up the pilot to fly the spacecraft. The constructor is passed a network to fly the spacecraft, as well as a Boolean that indicates if telemetry should be tracked to the screen.
neuralpilot构造函数设置飞行的航天器。该构造函数通过一个网络来飞行飞船,以及一个布尔值,指示是否应该跟踪到屏幕上的遥测。


public NeuralPilot(
BasicNetwork network , boolean track ) {
The lunar lander must feed the fuel level, altitude and current velocity to the neural network. These values must be normalized as was covered in Chapter 2. To perform this normalization, the constructor begins by setting several normalization fields.
月球着陆器必须将燃料水平、高度和当前速度反馈给神经网络。这些值必须规范化,如第2章所述。为了实现这种规范化,构造函数首先设置几个规范化字段。


private NormalizedField fuelStats;
private NormalizedField altitudeStats;
private NormalizedField velocityStats;
In addition to the normalized fields, we will also save the operating parameters. The track variable is saved to the instance level so that the program will later know if it should display telemetry.
除了规范化字段之外,我们还将保存操作参数。跟踪变量保存到实例级别,以便程序稍后知道它是否应该显示遥测。


this.track = track ;
this.network = network ;
The neural pilot will have three input neurons and one output neuron. These three input neurons will communicate the following three fields to the neural network.
神经飞行员将有三个输入神经元和一个输出神经元。这三个输入神经元将向神经网络传达以下三个字段。
? Current fuel level
? Current altitude
? Current velocity
These three input fields will produce one output field that indicates if the neural pilot would like to fire the thrusters. To normalize these three fields, define them as three NormalizedField objects. First, set up the fuel.
这三个输入字段将产生一个输出字段,指示神经飞行员是否愿意启动推进器。规范这三个领域,它们定义为三个NormalizedField对象。首先,设置燃料。
fuelStats=
new NormalizedField (
NormalizationAction.Normalize ,
” fuel” ,
200 ,
0 ,
?0.9 ,
0.9) ;
We know that the range is between 0 and 200 for the fuel. We will normalize this to the range of -0.9 to 10.9. This is very similar to the range -1 to 1, except it does not take the values all the way to the extreme. This will sometimes help the neural network to learn better. Especially when the full range is known. Next velocity and altitude are set up.
我们知道燃料在0到200之间。我们将把这个标准化到0.9到10.9的范围。这与范围- 1至1是非常相似的,除非它不采取价值的方式到极端。这有时会帮助神经网络更好地学习。尤其是当全范围已知时。接下来设置速度和高度。


altitudeStats=
new NormalizedField (
NormalizationAction.Normalize ,
” altitude” ,
10000 ,
0 ,
?0.9 ,
0.9) ;
Velocity and altitude both have known ranges just like fuel. As a result, velocity is set up similarly to fuel and altitude.
速度和高度都知道范围,像燃料一样。其结果是,速度建立起来类似于燃料和高度。
velocityStats=
new NormalizedField ( NormalizationAction.Normalize ,
” velocity” ,
LanderSimulator .TERMINAL VELOCITY,
?LanderSimulator .TERMINAL VELOCITY,-0.9 , 0.9) ;
Because we do not have training data, it is very important that we know the ranges. This is unlike the examples in Chapter 2 that provided sample data to determine minimum and maximum values.
因为我们没有训练数据,所以知道范围是非常重要的。这与第2章中提供的确定最小值和最大值的示例数据不同。


For this example, the primary purpose of flying the spacecraft is to receive a score. The scorePilot method calculates this score. It will simulate a flight from the point that the spacecraft is dropped from the orbiter to the point that it lands. The scorePilot method calculates this score:
在这个例子中,飞行宇宙飞船的主要目的是获得一个分数。scorepilot方法计算这个分数。它将模拟一个飞船从轨道一点降落到着陆点的飞行。scorepilot方法计算这个分数:


public int scorePilot () {
This method begins by creating a LanderSimulator object to simulate the very simple physics used by this program.
该方法首先创建一个landersimulator对象来模拟被该程序采用的非常简单的物理。
LanderSimulator sim = new LanderSimulator () ;
We now enter the main loop of the scorePilot method. It will continue looping as long as the spacecraft is still flying. The spacecraft is still flying as long as its altitude is greater than zero.
我们现在进入的scorepilot法主循环。只要飞船还在飞行,它就会继续循环。只要它的高度大于零,宇宙飞船仍在飞行。


while(sim.flying () ) {
Begin by creating an array to hold the raw data that is obtained directly from the simulator.
首先创建一个数组来保存从模拟器直接获得的原始数据。
MLData input = new BasicMLData(3) ;
input.setData (0 , this.fuelStats.normalize (sim.getFuel () ) ) ;
input.setData (1 , this.altitudeStats.normalize (sim.getAltitude () ) ) ;
input.setData (2 , this.velocityStats.normalize (sim.getVelocity () ) ) ;
The normalize method of the NormalizedField object is used to actually normalize the files of fuel, altitude and velocity.
规范化方法的normalizedfield对象用于实际规范燃料文件,高度和速度。
MLData output = this.network.compute( input ) ;
This single output neuron will determine if the thrusters should be fired.
这个单输出神经元将决定推进器是否应该被启动。
double value = output.getData (0) ;
boolean thrust ;
If the value is greater than zero, then the thrusters will be fired. If the spacecraft is tracking, then also display that the thrusters were fired.
如果值大于零,则推进器将被启动。如果飞船正在跟踪,那么也会显示推进器被启动了。
i f ( value > 0 ) {
thrust = true ;
i f ( track )
System.out.println (”THRUST”) ;
}
else
thrust = false ;
Process the next “turn” in the simulator and thrust if necessary. Also display telemetry if the spacecraft is tracking.
在模拟器中处理下一个“转换”,必要时进行推力。如果飞船跟踪,也显示遥测。
sim.turn ( thrust ) ;
i f ( track )
System.out.println (sim.telemetry () ) ;
}
The spacecraft has now landed. Return the score based on the criteria previously discussed.
宇宙飞船现在着陆了。根据前面讨论的标准返回分数。
return(sim.cost () ) ;
We will now look at how to train the neural pilot.
现在我们来看看如何训练神经飞行员。
6.3 Training the Neural Pilot
6.3 训练神经飞行员


This example can train the neural pilot using either a genetic algorithm or simulated annealing. Encog treats both genetic algorithms and simulated annealing very similarly. On one hand, you can simply provide a training set and use simulated annealing or you can use a genetic algorithm just as in a propagation network. We will see an example of this later in the chapter as we apply these two techniques to the XOR problem. This will show how similar they can be to propagation training.
这个例子可以使用遗传算法或模拟退火训练神经飞行员。encog将遗传算法和模拟退火算法非常类似地对待。一方面,您可以简单地提供一个训练集和使用模拟退火,或者您可以使用一个遗传算法,就像在一个传播网络中一样。我们将在本章后面看到一个例子,我们将这两种技术应用于XOR问题。这将表明它们与传播训练有多么相似。


On the other hand, genetic algorithms and simulated annealing can do something that propagation training cannot. They can allow you to train without a training set. It is still supervised training since a scoring class is used, as developed earlier in this chapter. However, it still does not need to training data input. Rather, the neural network needs input on how good of a job it is doing. If you can provide this scoring function, simulated annealing or a genetic algorithm can train the neural network. Both methods will be discussed in the coming sections, beginning with a genetic algorithm.
另一方面,遗传算法和模拟退火可以做一些传播训练不能做的事情。他们可以让你在没有训练集的情况下进行训练。由于本章前面开发了一个评分类,它仍然是有监督的培训。但是,它不需要训练数据输入。相反,神经网络需要输入它所做的工作有多好的标准。如果能提供这种评分函数,模拟退火算法或遗传算法可以训练神经网络。这两种方法将在接下来的章节中讨论,遗传算法开始。


6.3.1 What is a Genetic Algorithm
6.3.1 遗传算法是什么


Genetic algorithms attempt to simulate Darwinian evolution to create a better neural network. The neural network is reduced to an array of double variables. This array becomes the genetic sequence. The genetic algorithm begins by creating a population of random neural networks. All neural networks in this population have the same structure, meaning they have the same number of neurons and layers. However, they all have different random weights.
遗传算法试图模拟达尔文的进化来创造一个更好的神经网络。神经网络被简化为一个double变量数组。这个数组变成了基因序列。遗传算法首先是建立一个随机神经网络种群。这个群体中的所有神经网络都具有相同的结构,这意味着它们具有相同数量的神经元和层。然而,它们都有不同的随机权重。


These neural networks are sorted according their “scores.” Their scores are provided by the scoring method as discussed in the last section. In the case of the neural pilot, this score indicates how softly the ship landed.
这些神经网络按“分数”排序,其得分由评分方法提供,如上一节所讨论的。在神经飞行员的例子中,这个分数表明飞船降落的多软。


The top neural networks are selected to “breed”. The bottom neural networks “die”. When two networks breed, nature is simulated by splicing their DNA. In this case, splices are taken from the double array from each network and spliced together to create a new offspring neural network. The offspring neural networks take up the places vacated by the dying neural networks.
顶部的神经网络被选中来“繁殖”。底层神经网络“死亡”。当两个网络繁殖时,通过拼接DNA来模拟大自然。在这种情况下,接头是来自每个网络的双数组拼接在一起,创建一个新的子代神经网络。子代神经网络占据了垂死的神经网络空出的位置。


Some of the offspring will be “mutated”. That is, some of the genetic material will be random and not from either parent. This introduces needed variety into the gene pool and simulates the natural process of mutation.
有些后代会“突变”。也就是说,一些遗传物质是随机的,而不是来自双亲。这就引入了基因库中需要的多样性,并模拟了突变的自然过程。


The population is sorted and the process begins again. Each iteration provides one cycle. As you can see, there is no need for a training set. All that is needed is an object to score each neural network. Of course you can use training sets by simply providing a scoring object that uses a training set to score each network.
种群被排序,这个过程又开始了。每次迭代提供一个循环。正如你所看到的,不需要训练集。所有需要的是一个对象来评分每个神经网络。当然,您可以提供一个得分对象使用的训练集,该对象使用训练集来对每个网络进行评分。


6.3.2 Using a Genetic Algorithm
6.3.2 使用遗传算法


Using the genetic algorithm is very easy and uses the NeuralGeneticAlgorithm class to do this. The NeuralGeneticAlgorithm class implements the MLTrain interface. Therefore, once constructed, it is used in the same way as any other Encog training class. The following code creates a new NeuralGeneticAlgorithm to train the neural pilot.
利用遗传算法非常简单,使用NeuralGeneticAlgorithm类(我下载的3.4版本的Encog代码,没有发现NeuralGeneticAlgorithm类,月球着陆器的例子使用的是MLMethodGeneticAlgorithm类)。NeuralGeneticAlgorithm类实现mltrain接口。因此,一旦建成,它用的方法与其他encog训练类一样。下面的代码创建训练神经新对象NeuralGeneticAlgorithm。


train = new NeuralGeneticAlgorithm (network , new NguyenWidrowRandomizer () ,new PilotScore () ,500 , 0.1 , 0.25) ;
The base network is provided to communicate the structure of the neural network to the genetic algorithm. The genetic algorithm will disregard weights currently set by the neural network. The randomizer is provided so that the neural network can create a new random population. The NguyenWidrowRandomizer attempts to produce starting weights that are less extreme and more trainable than the regular RangeRandomizer that is usually used. However, either randomizer could be used.
提供基本网络以将神经网络的结构与遗传算法通信。遗传算法将忽略当前由神经网络设置的权重。随机数发生器的设置使神经网络可以创建一个新的随机种群。与通常用的普通rangerandomizer相比,NguyenWidrowRandomizer试图产生不极端、更可训练的起始权重。然而,两个随机数发生器都可用。


The value of 500 specifies the population size. Larger populations will train better, but will take more memory and processing time. The 0.1 is used to mutate 10% of the offspring. The 0.25 value is used to choose the mating population from the top 25% of the population.
500的值指定了种群大小。较大的种群会训练得更好,但会占用更多的内存和处理时间。0.1个用于变异10%个后代。0.25值用于从居前25%的种群中选择交配群体。


int epoch = 1;
Now that the trainer is set up, the neural network is trained just like any Encog training object. Here we only iterate 50 times. This is usually enough to produce a skilled neural pilot.
现在的训练器建好了,训练神经网络,就像任何encog训练对象那样。这里我们只重复50次。这通常足以制造出熟练的神经飞行员。


for ( int i =0;i <50; i++) {
train.iteration () ;
System.out.println (
”Epoch #” + epoch + ” Score : ” + train.getError () ) ;
epoch++;
}
This neural network could have also trained using the EncogUtility class, as in the previous chapter. Just for simple training, the EncogUtility is usually the preferred method. However, if your program needs to do something after each iteration, the more manual approach shown above may be preferable.
该神经网络也可以使用encogutility类训练,如在前一章。只是简单的训练,encogutility通常是首选的方法。然而,如果你的程序在每次迭代之后需要做些事,上面显示的更手动的方法可能是最好的。


6.3.3 What is Simulated Annealing
6.3.3 模拟退火是什么


Simulated annealing can also be used to train the neural pilot. Simulated annealing is similar to a genetic algorithm in that it needs a scoring object. However, it works quite differently internally. Simulated annealing simulates the metallurgical process of annealing.
模拟退火也可以用来训练神经飞行员。模拟退火算法类似于遗传算法,它也需要一个评分对象。然而,它在内部起着截然不同的作用。模拟退火模拟冶金退火过程。


Annealing is the process by which a very hot molten metal is slowly cooled. This slow cooling process causes the metal to produce a strong, consistent molecular structure. Annealing is a process that produces metals less likely to fracture or shatter.
退火是一种非常热的熔融金属慢慢冷却的过程。这种缓慢的冷却过程使金属产生了强烈的、一致的分子结构。退火是一种使金属不易断裂或破碎的过程。


A similar process can be performed on neural networks. To implement simulated annealing, the neural network is converted to an array of double values. This is exactly the same process as was done for the genetic algorithm. 
可以在神经网络上执行类似的过程。为了实现模拟退火,将神经网络转换为一个double数组。这与遗传算法所做的过程完全相同。


Randomness is used to simulate the heat and cooling effect. While the neural network is still really “hot”, the neural network’s existing weights increase in speed. As the network cools, this randomness slows down. Only changes that produce a positive effect on the network’s score are kept.
随机性是用来模拟散热和冷却效果的。当神经网络仍然是真正的“热”,神经网络的现有权值在速度上增加。当网络冷却时,这种随机性会减慢。只有对网络得分产生积极影响的改变才被保留下来。


6.3.4 Using Simulated Annealing
6.3.4 使用模拟退火


To use simulated annealing to train the neural pilot, pass the argument anneal on the command line when running this example. It is very simple for the example to use annealing rather than a genetic algorithm. They both use the same scoring function and are interchangeable. The following lines of code make use of the simulated annealing algorithm for this example.
使用模拟退火训练神经飞行员,在运行这个示例时,在命令行上传递退火参数。这是非常简单的使用退火的例子,而不是遗传算法。它们都使用相同的得分函数,并且是可互换的。下面的代码行使用了模拟退火算法。


i f ( args.length >0 && args [ 0 ].equalsIgnoreCase (”anneal”) )
{
train = new NeuralSimulatedAnnealing (
network , new PilotScore () , 10 , 2 , 100) ;
}
The simulated annealing object NeuralSimulatedAnnealing is used to train the neural pilot. The neural network is passed along with the same scoring object that was used to train using a genetic algorithm.
模拟退火neuralsimulatedannealing对象是用来训练神经飞行员。神经网络通过与使用遗传算法训练的相同得分对象一起传递。


The values of 10 and 2 are the starting and stopping temperatures, respectively. They are not true temperatures, in terms of Fahrenheit or Celsius. A higher number will produce more randomness; a lower number produces less randomness. The following code shows how this temperature or factor is applied.
10和2的值分别为起始温度和停止温度。就华氏度或摄氏度而言,它们不是真正的温度。较高的数字会产生更多的随机性;较低的数字会产生较少的随机性。下面的代码显示了如何应用这个温度或因素。


public final void randomize () {
final double [ ] array = NetworkCODEC
. networkToArray( NeuralSimulatedAnnealing.this.network) ;
for ( int i = 0; i < array.length ; i++) {
double add = NeuralSimulatedAnnealing .CUT- Math. random() ;
add /= this.anneal.getStartTemperature () ;
add-= this.anneal.getTemperature () ;
array [ i ] = array [ i ] + add ;
}
NetworkCODEC. arrayToNetwork( array ,
NeuralSimulatedAnnealing.this.network) ;
}
The number 100 specifies how many cycles, per iteration, that it should take to go from the higher temperature to the lower temperature. Generally, the more cycles, the more accurate the results will be. However, the higher the number, the longer it takes to train. There are no simple rules for how to set these values. Generally, it is best to experiment with different values to see which trains your particular neural network the best.
数字100指定从高温到低温每一次迭代需要多少个循环,。一般来说,周期越长,结果就越准确。然而,数字越高,训练的时间就越长。对于如何设置这些值,没有简单的规则。一般来说,最好用不同的值进行实验,看看哪一种训练你的神经网络最好。


6.4 Using the Training Set Score Class
6.4 使用训练集评分类


Training sets can also be used with genetic algorithms and simulated annealing. Used this way, simulated annealing and genetic algorithms are a little different than propagation training based on usage. There is no scoring function when used this way. You simply use the TrainingSetScore object, which takes the training set and uses it to score the neural network.
训练集也可用于遗传算法和模拟退火。使用这种方法,模拟退火和遗传算法与基于使用的传播训练有点不同。使用这种方法时没有计分功能。你只是用trainingsetscore对象,以训练集,用它来评分神经网络。


Generally resilient propagation will outperform genetic algorithms or simulated annealing when used in this way. Genetic algorithms or simulated annealing really excel when using a scoring method instead of a training set. Furthermore, simulated annealing can sometimes to push backpropagation out of a local minimum.
一般来说,使用这种方式时弹性传播优于遗传算法或模拟退火。遗传算法或模拟退火算法在使用评分方法而不是训练集时非常出色。此外,模拟退火有时可以将反向传播从局部极小值中推出来。


The Hello World application, found at the following location, could easily be modified to use a genetic algorithm or simulated annealing:
在下面的代码找到的hello应用程序可以很容易地修改为使用遗传算法或模拟退火算法:


org.encog.examples.neural.xor.HelloWorld
To change the above example to use a genetic algorithm, a few lines must be added. The following lines create a training set-based genetic algorithm. First, create a TrainingSetScore object.
要改变上面的例子来使用遗传算法,必须添加几行。以下几行创建了一个基于训练集的遗传算法。首先,创建一个trainingsetscore对象。


CalculateScorescore = new TrainingSetScore (trainingSet) ;
This object can then be used with either a genetic algorithm or simulated annealing. The following code shows it being used with a genetic algorithm:
然后可以使用该对象与遗传算法或模拟退火算法一起使用。下面的代码显示它与一个遗传算法一起使用:


final MLTrain train = new NeuralGeneticAlgorithm (network , new NguyenWidrowRandomizer ( ) , score , 5000 , 0.1 , 0.25 ) ;
To use the TrainingSetScore object with simulated annealing, simply pass it to the simulated annealing constructor, as was done above.
使用trainingsetscore对象与模拟退火,只是通过模拟退火的构造函数传递,如以上所做。