1 of 68

PINN: �Multiple Loss Terms and Weighting

Prof. Seungchul Lee

2 of 68

Overfitting: Start with Linear Regression

2

3 of 68

Recap: Nonlinear Regression

  • Polynomial (here, quad is used as an example)

3

4 of 68

Nonlinear Regression

4

10 input points with degree 9 (or 10)

5 of 68

Polynomial Fitting with Different Degrees

5

Low error on input data points,

but high error nearby

  • Underfit
  • Good fit
  • Overfit

​

Important to find the right balance between model complexity and generalization

6 of 68

Loss

  • Loss: Residual Sum of Squares (RSS)
    • decreases as the polynomial degree increases
    • a lower error does not necessarily indicate a better model

6

Minimizing loss in training data is

often not the best

Low error on input data points,

but high error nearby

7 of 68

Issue with Rich Representation

  • Low error on input data points, but high error nearby
  • Low error on training data, but high error on testing data

7

8 of 68

Overfitting

  • One of the most common problem data science professionals face

​

  • Overfitting occurs when a machine learning model performs well on the training data but poorly on unseen or test data.

​

  • The model essentially "memorizes" the noise and details in the training set rather than learning the general patterns that can be applied to new data.

8

9 of 68

Signs of Overfitting

  • Large gap between training and test loss:

​

  • Training loss continues to decrease, but test loss increases.

9

10 of 68

Causes of Overfitting

  • Model Complexity
    • A model with too many parameters (e.g., deep neural networks) can overfit the training data.

​

  • Insufficient Training Data
    • If the training dataset is small, the model may fit every point precisely, capturing noise rather than general patterns.

​

  • Noisy Data
    • If the data has a lot of noise or irrelevant features, the model may try to learn this noise.

​

  • Too Many Training Iterations
    • Training for too long can lead to overfitting, where the model starts fitting noise instead of actual patterns.

​

10

11 of 68

Generalization Error

  • Difference between a machine learning model's performance on the training data and its performance on unseen data (test or validation data)

11

12 of 68

Regularization to Reduce Overfitting

12

13 of 68

Generalization Error

  •  

13

14 of 68

Representational Difficulties

  •  

14

15 of 68

With Less Basis Functions: Fewer RBF Centers

15

16 of 68

With Less Basis Functions: Fewer RBF Centers

  • Least-squares fits for different numbers of RBFs

​

16

17 of 68

Representational Difficulties

  •  

17

18 of 68

Regularization (Shrinkage Methods)

  • Often, overfitting associated with very large estimated parameters
  • We want to balance
    • how well function fits data
    • magnitude of coefficients 

​

​

​

​

​

​

​

    • multi-objective optimization
    • 𝜆 is a tuning parameter

18

19 of 68

Regularization (Shrinkage Methods)

  •  

19

20 of 68

RBF: Start from Rich Representation

20

21 of 68

RBF with Regularization

  •  

21

22 of 68

RBF with Regularization

  •  

22

23 of 68

 

  •  

23

24 of 68

How L2 Regularization Works

​

​

​

​

  • Effect on Weights:
    • L2 regularization forces the model to keep weights small.
  • Interpretation:
    • L2 regularization distributes the penalty uniformly across all weights, shrinking their magnitude.
  • Overfitting Reduction:
    • By limiting the model's ability to learn large weights, the model becomes less likely to overfit the noise in the training data.

​

​

24

25 of 68

Probabilistic Linear Regression

25

26 of 68

Probabilistic Linear Regression

​

​

​

​

​

​

​

  • Inference idea

​

​

​

  • Change your viewpoint of data
    • Generative model

26

data = underlying pattern + independent noise

27 of 68

Generative Model: Regression

  •  

27

28 of 68

Likelihood and Log-Likelihood

  • The likelihood of the parameters given the dataset is:

​

​

​

​

  • Taking the logarithm (log-likelihood):

28

29 of 68

Maximum Likelihood Estimation (MLE)

  •  

29

30 of 68

Maximum Likelihood Estimation (MLE)

  • In a matrix form

​

​

​

​

​

​

  • Taking gradients of the log-likelihood and setting them to zero:

30

31 of 68

Maximum Likelihood Estimation (MLE)

  •  

31

32 of 68

Linear Regression: A Probabilistic View

32

33 of 68

Linear Regression: A Probabilistic View

  • Demonstrate

33

34 of 68

Linear Regression: A Probabilistic View

  • Demonstrate
    • samples are independent

​

​

​

​

​

​

​

​

​

​

​

  • If a linear model is correctly specified and well estimated, then the residual errors should approximately follow a Gaussian distribution:

34

35 of 68

Bayesian View of Linear Regression

35

36 of 68

Generative Model: Regression

36

37 of 68

 

  •  

37

38 of 68

 

  •  

38

Images from Prof. Philipp Hennig at University of Tubingen

39 of 68

 

  •  

39

Images from Prof. Philipp Hennig at University of Tubingen

40 of 68

Maximum-a-Posteriori (MAP)

  •  

40

Images from David S. Rosenberg at Bloomberg ML EDU

41 of 68

Posterior

  • Posterior probability
    • Bayes rule

​

​

​

​

  • Log posterior probability

​

​

​

​

​

​

  • Maximize log posterior probability�

41

42 of 68

Maximum-a-Posteriori (MAP)

  •  

42

43 of 68

Summary: MLE vs MAP

  •  

43

44 of 68

From Statistical Priors to Physical Priors

44

45 of 68

From Statistical Priors to Physical Priors

  • Consider a governing equation written with all terms on one side,

​

​

  • The residual

​

​

  • Measures how badly the physics is violated over collocation points

​

​

​

  • A MAP estimate whose prior is a physical law rather than a statement about parameter magnitudes

45

46 of 68

Strategies for Choosing the Weights

46

47 of 68

PINN Architecture

47

48 of 68

PINN Architecture

  • PINNs train multiple physical conditions in one objective
  • The optimizer sees only the combined scalar loss

48

49 of 68

Poisson Equation

  • Poisson equation

​

​

  • with homogeneous Dirichlet boundary conditions

​

​

​

  • Exact solution

49

50 of 68

Naive PINN

  • Poisson equation

​

​

​

​

​

​

​

​

​

  • Most natural thing to do is to add them

50

51 of 68

Loss Imbalance

  • Equal weights do not imply equal gradient contributions
    • Parameters are updated by the sum of gradients from each loss term

51

 

 

 

52 of 68

Loss Imbalance

  • Equal weights do not imply equal gradient contributions
    • Parameters are updated by the sum of gradients from each loss term

52

 

 

 

 

 

 

53 of 68

Loss Imbalance

  • Equal weights do not imply equal gradient contributions
    • Parameters are updated by the sum of gradients from each loss term

53

“A single loss can dominate the parameter update”

 

 

 

 

 

 

54 of 68

Mitigating Loss Imbalance

  • Apply weights to individual loss terms

54

 

 

 

 

 

 

55 of 68

Mitigating Loss Imbalance

  • Apply weights to individual loss terms
    1. Fixed weighting
    2. Adaptive weighting

55

 

 

 

 

 

 

56 of 68

Fixed Weighting

  • A Well-Chosen Weight
  • A Badly Chosen Weight

​

56

57 of 68

Two Limitations of a Fixed Weight

  1. The right value is not known in advance

​

  • Even a right value does not stay right

57

58 of 68

Fixed Weighting

  • Weights are set before training and kept constant
  • Simple, but suitable weights are problem dependent

58

 

 

 

 

 

 

59 of 68

Fixed Weighting

  • Cannot adapt when gradient scales change during training

59

 

 

 

 

 

 

60 of 68

Adaptive Weighting

  • Automatically adjusts weights from training signals

60

Method

Core idea

Gradient-based

Balance gradient norms

Loss-based

Upweight large or slowly decaying losses

Trainable Weight

Optimize weights directly

NTK-based

Upweight slower-learning terms

61 of 68

The Optimizer Sees Gradients, Not Losses

  • The parameters are updated by gradient descent on the total loss

​

​

​

  • Because the objective is a sum, so is its gradient

​

​

​

  • What decides the direction of the step is the gradient contribution of each term,
    • the length and direction of its vector, and
    • not the scalar value of the loss

61

62 of 68

Gradient-Based Adaptive Weighting

  •  

62

63 of 68

Gradient-Based Adaptive Weighting

​

​

​

​

​

​

​

​

​

​

  • The weights are recomputed at every iteration from the current gradients

63

64 of 68

Moving-Average Adaptive Weighting

  • Instantaneous weights are too noisy to use directly
  • Move the weight part of the way toward the measurement, not all the way

​

​

​

  • An exponential moving average of the instantaneous weights

64

65 of 68

Moving-Average Adaptive Weighting

65

66 of 68

Hard Constraint

  • Embed mandatory conditions directly into the network output
    • Remove selected constraints from loss-gradient competition

66

 

 

 

 

Neural network

Hard Constraint

67 of 68

Hard Constraint by a Masking Function

  • Build the boundary condition into the output instead of penalizing it

​

​

​

​

​

​

​

​

​

​

​

  • One term left in the objective, and no weight to choose

67

68 of 68

Hard Constraint by a Masking Function

68