NelworksNelworks

ML & AI / Season 2 / EP06

Physics-Informed Neural Networks and Objective Function Mismatch

Shez

It learned! It learned the Theory of Everything!

Kurumi

It learned to wiggle.

Shez

It's not wiggling! It's a Deep Neural Network I trained to predict the arm's trajectory.

Shez

The Mean Squared Error is 10^-6! It's basically zero!

Kurumi

The MSE is low. The R-squared is high. The numbers are happy.

Kurumi

Now, show me the energy consumption plot.

Shez

Oh. That part is a little... weird.

Kurumi

'Weird?' Shez, your robot just invented a perpetual motion machine.

Kurumi

According to your model, to perform that elegant little flip, the arm needs to *generate* 50 Watts of power out of thin air.

Kurumi

It violated the First Law of Thermodynamics.

Shez

But the position prediction is perfect! Who cares about the energy?

Kurumi

Anyone who doesn't want their robot to tear a hole in spacetime.

Shez

I wish for a model that perfectly fits my data!

Kurumi

The optimizer is a genie. It will grant your wish *literally*.

Kurumi

You wished for a low MSE. You got a low MSE. You didn't wish for a model that respected reality.

Kurumi

This is the genie's contract.

Kurumi

All it says is 'Make the red line touch the blue dots.' It says *nothing* about Newton, Einstein, or the laws of energy.

Shez

So... the model has no common sense?

Kurumi

A calculator has no common sense. It just calculates.

Kurumi

Your neural network is just a very, very complicated calculator. It will happily divide by zero if you let it.

Kurumi

Let's ask your model to predict the arm's position if it moves 10% faster.

Shez

Whoa! What was that?!

Kurumi

That was **Extrapolation**. Your model is a genius inside the training data, and a complete lunatic outside of it.

Shez

So my beautiful model is just... a high-tech parrot? It can only repeat what it's seen?

Kurumi

Yes. Because you taught it imitation, not comprehension.

Kurumi

To get a smart genie, you need to write a smarter contract.

Shez

How do I write 'Don't Break Physics' in Python?

Kurumi

With more math.

Kurumi

We give the model a **Conscience**.

Kurumi

The sheep wants to eat the grass (Minimize Data Loss).

Kurumi

But we are going to build an electric fence around the field.

Kurumi

This fence is a **Physical Law**. If the sheep tries to cross it, it gets a shock.

Kurumi

The shock is a **Penalty**. We add it to the loss function.

Kurumi

We have two terms now.

Kurumi

**Data Loss:** 'Don't be wrong about what you see.'

Kurumi

**Physics Loss:** 'Don't be stupid about what you don't see.'

Shez

What's the lambda ()?

Kurumi

That's the voltage on the fence. How much we punish stupidity.

Shez

But that has a derivative in it! dEdt!

Shez

My neural network just outputs a position. How do I get the derivative?

Kurumi

We use **Automatic Differentiation**.

Kurumi

Because every operation in this network is differentiable, we can analytically compute the derivative of the output with respect to the input (time).

Kurumi

We backpropagate not just the data error, but the *physics error* too.

Shez

So... the model learns to obey the fence on its own?

Kurumi

Yes. It finds a solution that is both close to the grass and far from the fence. It learns a physically plausible interpolation.

Shez

Retraining...

Shez

Huh. The MSE went up a little. 10^-5. It's... statistically worse.

Kurumi

Of course. We constrained it. It can't wiggle perfectly anymore.

Shez

The energy... it makes sense now.

Kurumi

It generalizes. Because it learned the rule, not just the data points.

Shez

So I should choose a model that first obeys physics before the minimized errors.

Kurumi

A model is a tool. You told the first model to be perfect. It lied to you how reality works.

Kurumi

You told the second model to be a good engineer. It designed a movement that is constrained by physics.

Shez

I don't want to chase fake numbers anymore. I want to model the world.

Kurumi

That's the way of a scientist.