# Specify loss function directly for NeuralPDE?

**URL:** <https://discourse.julialang.org/t/specify-loss-function-directly-for-neuralpde/77757>\
**Category:** General Usage\
**Created:** [March 11, 2022, 3:47pm UTC](https://discourse.julialang.org/t/specify-loss-function-directly-for-neuralpde/77757 "2022-03-11T15:47:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)\
**Post date:** [March 11, 2022, 3:47pm UTC](https://discourse.julialang.org/t/specify-loss-function-directly-for-neuralpde/77757/1 "2022-03-11T15:47:39Z")

</div>

Hello,

In NeuralPDE you normally define the PDE (lhs-rhs=0) symbolically and the loss function is built internally, loosely \int dvars ||lhs(vars) - rhs(vars)||^2 .

Is there a way to specify the objective function symbolically directly? Let’s say you are crazy enough and just want to optimize \int dvars \, [cos(lhs(vars)) + sin(rhs (vars))] . What would be the easiest way to do that?

Cheers!

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 11, 2022, 5:38pm UTC](https://discourse.julialang.org/t/specify-loss-function-directly-for-neuralpde/77757/2 "2022-03-11T17:38:53Z")

</div>

You crazy bastard. There’s no way to do that right now without hacking the code, but that would be cool. Open an issue and we can see how to support that. Right now you can simply add new loss terms with `additional_loss`, but not change the PINN loss.

---

<div class="post-metadata">

**Author:** ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)\
**Post date:** [March 11, 2022, 5:41pm UTC](https://discourse.julialang.org/t/specify-loss-function-directly-for-neuralpde/77757/3 "2022-03-11T17:41:16Z")

</div>

> [@ChrisRackauckas](#):
>
> You crazy bastard.

😆 🤷‍♂️

opened [issue](https://github.com/SciML/NeuralPDE.jl/issues/496)

---

<div class="post-metadata">

**Author:** ![nico](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nico/32/211667_2.png) [@nico](https://discourse.julialang.org/u/nico)\
**Post date:** [August 29, 2024, 11:36am UTC](https://discourse.julialang.org/t/specify-loss-function-directly-for-neuralpde/77757/4 "2024-08-29T11:36:36Z")

</div>

Any update?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 29, 2024, 12:17pm UTC](https://discourse.julialang.org/t/specify-loss-function-directly-for-neuralpde/77757/5 "2024-08-29T12:17:08Z")

</div>

We are trying to finish a new parser that would allow for this. It has not merged yet though

---

<div class="post-metadata">

**Author:** ![nico](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nico/32/211667_2.png) [@nico](https://discourse.julialang.org/u/nico)\
**Post date:** [August 29, 2024, 1:29pm UTC](https://discourse.julialang.org/t/specify-loss-function-directly-for-neuralpde/77757/6 "2024-08-29T13:29:47Z")

</div>

Thank you Chris for your reply.

---

<div class="post-metadata">

**Author:** ![nico](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nico/32/211667_2.png) [@nico](https://discourse.julialang.org/u/nico)\
**Post date:** [November 21, 2024, 1:23pm UTC](https://discourse.julialang.org/t/specify-loss-function-directly-for-neuralpde/77757/7 "2024-11-21T13:23:42Z")

</div>

Is it possible to change the loss weights then? In this way one can add a new loss term, and turn off others…

---

<div class="post-metadata">

**Author:** ![nico](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nico/32/211667_2.png) [@nico](https://discourse.julialang.org/u/nico)\
**Post date:** [November 21, 2024, 1:50pm UTC](https://discourse.julialang.org/t/specify-loss-function-directly-for-neuralpde/77757/8 "2024-11-21T13:50:39Z")

</div>

I guess the answer is here: [Adaptive Loss Functions · NeuralPDE.jl](https://docs.sciml.ai/NeuralPDE/stable/manual/adaptive_losses/)
