lululxvi / deepxde

A library for scientific machine learning and physics-informed learning
https://deepxde.readthedocs.io
GNU Lesser General Public License v2.1
2.77k stars 760 forks source link

There is one more column of train loss in the running result #630

Closed doubao2 closed 2 years ago

doubao2 commented 2 years ago

Dear Dr Lu Lu, I try to solve a two-dimensional partial differential equation that solves the option value over time,but there's something wrong with the training process, i get one more column of train loss in the running result,This is the PDE equation I defined

def pde(x, u): 
    u_t = dde.grad.jacobian(u, x, i=0, j=2) 
    u_x = dde.grad.jacobian(u, x, i=0, j=0)        
    u_y = dde.grad.jacobian(u, x, i=0, j=1)
    u_xx = dde.grad.hessian(u, x, i=0, j=0)
    return (
        u_t  
        + tf.maximum(18-x[: ,0:1],0)* u_y  #max(18-x[: ,0:1],0)
        + (B + C * omega * tf.cos(omega * x[: ,2:3] + phi)+ alpha * (A + B*x[: ,2:3]+C * tf.sin(omega*x[: ,2:3]+phi)-x[: ,0:1])-lamda*sigma)* u_x 
        + 0.5 * sigma ** 2 * u_xx
        - r * u
         ) 

This is the boundary and initial condition I defined

def boundary_l(x, on_boundary):
    return on_boundary and np.isclose(x[0], -50)
def boundary_r(x, on_boundary):
    return on_boundary and np.isclose(x[1], 30)
def boundary_b(x, on_boundary):
    return on_boundary and np.isclose(x[2], 0)
def func(x):
    return tf.maximum(k-tf.maximum(18-x[: ,0:1],0),0)
def boundary_d(x, _):
    return np.isclose(x[0], 50)
bc_d = dde.OperatorBC(
    spatio_temporal_domain,
    lambda x, u,_: dde.grad.jacobian(u, x, i=0, j=0),#或者为0?
    boundary_d,
)
bc_l = dde.DirichletBC(spatio_temporal_domain, lambda x: 0, boundary_l)
bc_r = dde.DirichletBC(spatio_temporal_domain, lambda x: 0, boundary_r)#float("inf")无穷
ic = dde.IC(
        spatio_temporal_domain,func,lambda _,boundary_b: boundary_b)

My mode

data = dde.data.TimePDE(
    spatio_temporal_domain,
    pde,[bc_l, bc_r,ic, bc_d],
    num_domain=1000,
    num_boundary=100,
    num_initial=99,
    num_test=250,
    #anchors=X
)
model.compile("adam", lr = 0.001,loss_weights=[1e-6, 1e-4,1e-3,1e-5,1e-2,1e-2])

This is the result of my training image

PDE, boundary and initial conditions are five items in total, but when setting weights, I must set six weights, and training losses are also six items. I don't know What is the more one. And my training loss is getting bigger and bigger, which puzzles me Thank you very much in advance!

praksharma commented 2 years ago

That is the total loss.

And don't worry if your training loss is increasing. DeepXDE stores the model with the least training loss.

Also, go here. And check Q: I failed to train the network or get the right solution, e.g., large training loss, unbalanced losses.

doubao2 commented 2 years ago

That is the total loss.

And don't worry if your training loss is increasing. DeepXDE stores the model with the least training loss.

Also, go here. And check Q: I failed to train the network or get the right solution, e.g., large training loss, unbalanced losses.

Thank you very much for your selfless help,there is something wrong with my results. I will carefully read the questions in the FAQ to solve my problems

lululxvi commented 2 years ago

Does your network have regularization? If so, the extra loss is the regularization loss.

doubao2 commented 2 years ago
doubao2 commented 2 years ago

您的网络是否具有正则化?如果是这样,额外的损失是正则化损失。

I checked that it is, I added regularization to the network.

Also, I checked the examples in the FAQ, but I'm sorry I still have some confusion:

  1. My solution is very jumping,these are some strange data I intercepted in test.dat

image

2.The range of my solution V(x,y,t) is very different from that in other papers. I suspect that there is a problem in the setting of my boundary conditions This is my solution,the value of the y-axis parameter is here.,the X axis is the value of the X parameter. image

This is the solution obtained by my tutor's numerical scheme. There are slight differences in the values of parameters, but the results are very different(Only the value of X parameter is shown in the figure)

image

This is my boundary condition

image

I define it this way:

image

My Python is really poor, so I have a lot of problems, I'm sorry to trouble you.

lululxvi commented 2 years ago

Didn't fully get your question. Maybe you can check FAQ first https://deepxde.readthedocs.io/en/latest/user/faq.html

doubao2 commented 2 years ago

Didn't fully get your question. Maybe you can check FAQ first https://deepxde.readthedocs.io/en/latest/user/faq.html

OK, thank you so much for your reply