Numerical Patterns
Normalize Values
Scale by the Maximum
Normalization can convert raw values to ratios by dividing each value by a reference such as the maximum.
Program
Play the program to choose the maximum value used for scaling.
normalize_values.f90
Replay: real traced execution (multi-file project)
program normalize_values_demo
implicit none
real :: raw(3), scaled(3)
real :: max_value
raw = [2.0, 4.0, 8.0]
max_value = 8.0
scaled = raw / max_value
print '(F0.2, 1X, F0.2, 1X, F0.2)', scaled(1), scaled(2), scaled(3)
end program normalize_values_demo
program normalize_values_demo
implicit none
real :: raw(3), scaled(3)
real :: max_value
raw = [2.0, 4.0, 8.0]
max_value = 4.0
scaled = raw / max_value
print '(F0.2, 1X, F0.2, 1X, F0.2)', scaled(1), scaled(2), scaled(3)
end program normalize_values_demo
program normalize_values_demo
implicit none
real :: raw(3), scaled(3)
real :: max_value
raw = [2.0, 4.0, 8.0]
max_value = 10.0
scaled = raw / max_value
print '(F0.2, 1X, F0.2, 1X, F0.2)', scaled(1), scaled(2), scaled(3)
end program normalize_values_demo
raw ← [2.0, 4.0, 8.0]
6raw = [2.0, 4.0, 8.0]7max_value = 8.0values this step[2.0, 4.0, 8.0]rawmax_value ← 8.0
6raw = [2.0, 4.0, 8.0]7max_value = 8.08scaled = raw / max_valuevalues this step8.0max_valuescaled ← [0.25, 0.50, 1.00]
7max_value = 8.08scaled = raw / max_value9print '(F0.2, 1X, F0.2, 1X, F0.2)', scaled(1), scaled(2), scaled(3)values this step[0.25, 0.50, 1.00]scaled[2.0, 4.0, 8.0]raw8.0max_valueprint '(F0.2, 1X, F0.2, 1X, F0.2)', scaled(1), scaled(2), scaled(3)
8 scaled = raw / max_value9 print '(F0.2, 1X, F0.2, 1X, F0.2)', scaled(1), scaled(2), scaled(3)10end program normalize_values_demooutput0.25 0.50 1.00values this step[0.25, 0.50, 1.00]scaled
raw ← [2.0, 4.0, 8.0]
6raw = [2.0, 4.0, 8.0]7max_value = 4.0values this step[2.0, 4.0, 8.0]rawmax_value ← 4.0
6raw = [2.0, 4.0, 8.0]7max_value = 4.08scaled = raw / max_valuevalues this step4.0max_valuescaled ← [0.50, 1.00, 2.00]
7max_value = 4.08scaled = raw / max_value9print '(F0.2, 1X, F0.2, 1X, F0.2)', scaled(1), scaled(2), scaled(3)values this step[0.50, 1.00, 2.00]scaled[2.0, 4.0, 8.0]raw4.0max_valueprint '(F0.2, 1X, F0.2, 1X, F0.2)', scaled(1), scaled(2), scaled(3)
8 scaled = raw / max_value9 print '(F0.2, 1X, F0.2, 1X, F0.2)', scaled(1), scaled(2), scaled(3)10end program normalize_values_demooutput0.50 1.00 2.00values this step[0.50, 1.00, 2.00]scaled
raw ← [2.0, 4.0, 8.0]
6raw = [2.0, 4.0, 8.0]7max_value = 10.0values this step[2.0, 4.0, 8.0]rawmax_value ← 10.0
6raw = [2.0, 4.0, 8.0]7max_value = 10.08scaled = raw / max_valuevalues this step10.0max_valuescaled ← [0.20, 0.40, 0.80]
7max_value = 10.08scaled = raw / max_value9print '(F0.2, 1X, F0.2, 1X, F0.2)', scaled(1), scaled(2), scaled(3)values this step[0.20, 0.40, 0.80]scaled[2.0, 4.0, 8.0]raw10.0max_valueprint '(F0.2, 1X, F0.2, 1X, F0.2)', scaled(1), scaled(2), scaled(3)
8 scaled = raw / max_value9 print '(F0.2, 1X, F0.2, 1X, F0.2)', scaled(1), scaled(2), scaled(3)10end program normalize_values_demooutput0.20 0.40 0.80values this step[0.20, 0.40, 0.80]scaled
array division
`raw / max_value` divides every element by the scalar.
normalization
Scaling by a reference value makes magnitudes easier to compare.
formatting
`F0.2` prints each ratio with two decimal places.