lennart2810 / InvertedPendulumSDS

Projektausarbeitung zum Wahlmodul - Sondergebiete der Simulation - WS21/22
5 stars 1 forks source link

RE: your question on my harmonic oscillator PINN blog post #1

Open benmoseley opened 2 years ago

benmoseley commented 2 years ago

Hi Lennart, super cool application of PINNs to the inverted pendulum. Replying to your question on my blog post (https://benmoseley.blog/my-research/so-what-is-a-physics-informed-neural-network/) here for ease. Here is the question:

Hi Ben, first of all thank you for this very nice mechanical project.

I tried to use your example to solve the ode of the inverse pendulum.
The NN with two outputs works fine, but adding the physics loss does not help to extrapolate the equations (after more than 200.000 episodes).

You can find my code here: https://github.com/lennart2810/InvertedPendulumSDS/blob/master/PINN/InvertedPendulum/Inverse%20Pendulum%20PINN.ipynb

I had a quick look at your code, it all looks reasonable, the two lines I would check are:

    physics = torch.cat((physics_x, physics_theta), 1)

    loss_physics = (1e-4)*torch.mean(physics**2)

when training the PINN. I am assuming these are your (coupled) equations of motion (from the repo readme.md?)

If so I think you would need two physics loss terms in the loss function (one for each equation of motion), i.e.

loss_physics = lambda_x * torch.mean(physics_x**2) + lambda_theta * torch.mean(physics_theta**2)

rather than what you have at the moment. Also I would trial a few different scalar values of lambda_x and lambda_theta above; the physics loss needs to be balanced well with the data loss for it to converge well.

lennart2810 commented 2 years ago

Hi Ben, thank you for your advise.

I tried your suggestion and the network seems to perform much better. It's still not perfect but I will continue trying to solve the problem.