To build the Digital Twin, we needed to answer one key question: how much each donor city should
contribute. If Lagos is twice as similar to Port Harcourt as Kano, then Lagos should have more
influence. These influence values are called weights. We used a mathematical optimizer to find
the best weights for each city. Here is how it worked:
1. The Loss Function (Mean Squared Error)
We gave the model a target called a Loss Function. In our project, we used Mean Squared Error
(MSE).
The job of the loss function is to calculate the "penalty" for being wrong.
- It takes the difference between the Twin and the Real city for every single day.
- It squares that difference so that even small errors are punished.
- The optimizer's only goal is to change the weights until this "penalty" score is as close to
zero as possible.
2. The Scaling Secret (Mean-Normalization)
This is the most important part of our technical approach. Without scaling, the optimizer is
"blinded" by the size of Lagos. We used a method called Mean-Normalization.
The Math:
We calculate the average (Mean) of each city for the entire 700-day period. Then, we divide
every
daily order count by that average.
What the Scaling Does (An Example):
Imagine we have two donor cities: Lagos (Huge) and Kano (Small). On a specific day, both cities
grow
by 10%.
| City |
Average |
Orders |
Calculation |
Scaled |
| Lagos |
1,200 |
1,320 |
1,320 ÷ 1,200 |
1.10 |
| Kano |
10 |
11 |
11 ÷ 10 |
1.10 |
Why this matters:
Before scaling, a 10% error in Lagos was 120 orders, while a 10% error in Kano was only 1 order.
The
optimizer would ignore Kano's trend entirely because its numbers were too small to affect the
total
"penalty" score. By scaling, both cities now look like they have a value of 1.10. This gives
Kano an
equal "voice" in the model. It forces the optimizer to look at the Trend (the wiggles in the
line)
rather than the Volume (the size of the city).
3. The Constraints
We set strict rules so the model stayed realistic:
- Sum to 1.0: The total donor weights must equal 100%. We cannot create a
twin
that is "larger" than a full city.
- No Negatives: A city cannot have a negative weight. We only want to add
trends
together, not subtract them.
Following these rules, the optimizer gave us our final weights: Lagos: 0.1754,
Abuja: 0.1479, Ibadan: 0.3658, and Kano:
0.3109.
These perfectly equal 1.0.