Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding example on Physics-Informed Neural Networks for solving Eikonal equation #1345

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

sgrubas
Copy link

@sgrubas sgrubas commented Apr 29, 2023

Hello,

According to my question, you might be interested in a new example of physics-informed neural networks (PINNs).

I created a new folder pinn in the repo since it did not have any related to physics-informed neural networks (pinn)
This .py file contains the example with the neural eikonal solver.

Serafim

@google-cla
Copy link

google-cla bot commented Apr 29, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

two-point modification of the [eikonal
equation](https://en.wikipedia.org/wiki/Eikonal_equation):

$$\Vert \nabla_r \tau(\textbf{x}_s, \textbf{x}_r) \Vert = \frac{1}{v(\textbf{x}_r)}$$
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use latex syntax. Either explain equations via python code snippets or pseudocode snippets, or include rendered images of equations. The former is better since it is more accessible to our audience.

@@ -0,0 +1,459 @@
"""
Title: Neural Eikonal Solver
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not create a new category specifically for this example. Is there an existing category that could be a good fit?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best fit would be "quick keras recipes" perhaps; though PINNs probably don't fit in there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comments and reply!
I was also thinking about "quick keras recipes" but alternatively since eikonal is widely used in computer vision if I adapt the example to a computer vision context (e.g. to Shape-from-Shading problem), do you think that "computer vision" could be a good fit?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I say we put it in quick keras recipes and focus on the concept of PINNs!
I think we should emphasize that in PINNs you simply add an L2 loss to enforce the implicit physics constraints of the system.


def build_model(input_scale, vmin, vmax, dim=2):
# Hyperparameters
n_layers = 5 # number of hidden layers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming nit: use num_ as number prefix.

inputs_list = xs_list + xr_list

# Scaling of inputs, to avoid unit dependence
XsXr = Concatenate(name="x", axis=-1)([xs, xr])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming nit: use snake case for all instances. Lowercase.

xr = Concatenate(name="xr", axis=-1)(xr_list)

# Input 3: velocity model at Receiver coordinates
vr = Input(shape=(1,), name="vr")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming tips: strictly avoid non-obvious one-letter or two-letter names. Use fully-spelled out variable names everywhere.


import tensorflow as tf
from tensorflow.keras.layers.experimental.preprocessing import Rescaling
from tensorflow.keras.layers import Input, Concatenate, Dense
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just from tensorflow.keras import layers, then access elements of the module, e.g. layers.Dense

from tensorflow.keras.layers.experimental.preprocessing import Rescaling
from tensorflow.keras.layers import Input, Concatenate, Dense
from tensorflow.keras.layers import Multiply, Subtract, Lambda
from tensorflow.keras.models import Model
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access it from keras

## Imports
"""

import tensorflow as tf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also import keras

@sgrubas sgrubas requested review from fchollet and LukeWood May 23, 2023 01:42
@sgrubas
Copy link
Author

sgrubas commented Jun 23, 2023

Hello,
I revised the pull request in accordance with your comments, please review
Serafim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants