CAPITULO III .INCONSTITUCIONALIDAD DE NORMAS.
CONSTITUCIONAL DE LA DECLARATORIA DE ESTADOS DE EXCEPCIÓN
3.3 PETICION O SOLICITUD
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 Neu-
ralPilotclass performs this flight. You can see the NeuralPilot class at the
following location:
Encog . Examples . Lunar . Ne ur alP il o t
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.
public N eu ra l Pi lo t ( BasicNetwork network , bool 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.
private readonly NormalizedField f u e l S t a t s ; private readonly BasicNetwork network ; private readonly bool t r a c k ;
private readonly NormalizedField a l t i t u d e S t a t s ; private readonly NormalizedField v e l o c i t y S t a t s ;
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.
t r a c k = track ; 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.
f u e l S t a t s = new NormalizedField (
NormalizationAction . Normalize , ” f u e l ” , 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. a l t i t u d e S t a t s
= new NormalizedField (
NormalizationAction . Normalize , ” a l t i t u d e ” , 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.
v e l o c i t y S t a t s = new NormalizedField (
NormalizationAction . Normalize , ” v e l o c i t y ” , LanderSimulator . TerminalVelocity , −
LanderSimulator . TerminalVelocity , −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.
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:
public i n t S c o r e P i l o t ( ) {
This method begins by creating a LanderSimulator object to simulate the very simple physics used by this program.
var 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.
while ( sim . Flying ) {
Begin by creating an array to hold the raw data that is obtained directly from the simulator.
IMLData input = new BasicMLData ( 3 ) ;
input [ 0 ] = f u e l S t a t s . Normalize ( sim . Fuel ) ;
input [ 1 ] = a l t i t u d e S t a t s . Normalize ( sim . Altitude ) ; input [ 2 ] = v e l o c i t y S t a t s . Normalize ( sim . V e l o c i t y ) ;
The Normalize method of the NormalizedField object is used to actually normalize the files of fuel, altitude and velocity.
IMLData output = network . Compute ( input ) ;
This single output neuron will determine if the thrusters should be fired. double value = output [ 0 ] ;
bool t h r u s t ;
If the value is greater than zero, then the thrusters will be fired. If the space- craft is tracking, then also display that the thrusters were fired.
i f ( value > 0) {
t h r u s t = true ; i f ( t r a c k )
Console . WriteLine (@”THRUST” ) ; }
e l s e
t h r u s t = f a l s e ;
Process the next “turn” in the simulator and thrust if necessary. Also display telemetry if the spacecraft is tracking.
sim . Turn ( t h r u s t ) ; i f ( t r a c k )
Console . WriteLine ( sim . Telemetry ( ) ) ;
The spacecraft has now landed. Return the score based on the criteria previ- ously discussed.
return ( sim . Score ) ;
We will now look at how to train the neural pilot.