# Controlling a Train

## Calibration

The easy part

#### Using a Calibration

The other easy part

#### Building a Calibration Table

The hard part.

Two things are hard.

1. Dealing with measurement error
• Two categories of error
1. Systematic = controllable
2. Random = uncontrollable
2. Two strategies for dealing with error
1. Promotion
• Segregate data to promote random error into systematic error
2. Be conservative
• The further you get in your project the more you will want to relax conservative assumptions
3. Determining what state is relevant

## Dealing with Data

#### Offline

Large collection of data records

 Train Speed Section Previous Speed Time since speed change (seconds) Time since maintenance (hours) Cleanliness of track Previous speed (coded) Section type (coded) Velocity (cm/sec) 25 8 31 10 23 76 higher curved 8.9

How to manipulate the data

1. Code data with lots of values

What to do with the data

1. Remove the mean
• mean_velocity = (1/N) sum velocity
2. Calculate the remaining variance
• variance = sum (velocity - mean_velocity)^2
3. Form a linear model
• velocity = a(train) + b(speed) + c(section type) + ...
4. Calculate the optimal values for each factor
• subdivide by factor value
• calculate the mean for each subdivision
5. Find out which factors matter
• What fraction of the variance to they remove?
• Is the difference between velocities for different factor values worth worrying about?

The result is a collection of factors and values for each factor

• which are the ones that are worth considering

In reality a lot of intuition about the trains goes into the above judgment.

#### Online

• Calibrate the day before

AND/OR

• Calibrate at the beginning of the demo

AND/OR

• Calibrate as the demo runs

Whatever you do you can't do ANOVA online

Consider this:

1. You already know the factors and their values
2. Allocate a value for each
3. Initialize the value with a pre-estimate
4. Each time you measure a velocity
• find the appropriate value
• update the value using something like new_value = a * new_measurement + (1-a) * current_value
• experiment to find a good value for a.

### Practical Issues

You might want to consider

1. You are already doing a whole lot of measurements
2. Average in a circular buffer to get variance estimate
3. Turn on optimization, but be careful
• There are places where you have done register allocation by hand
4. Size & align calibration tables by size & alignment of cache lines