# Custom loss in DiffEqParamEstim

**URL:** <https://discourse.julialang.org/t/custom-loss-in-diffeqparamestim/115580>\
**Category:** Modelling & Simulations\
**Created:** [June 13, 2024, 4:54am UTC](https://discourse.julialang.org/t/custom-loss-in-diffeqparamestim/115580 "2024-06-13T04:54:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piyush](https://avatars.discourse-cdn.com/v4/letter/p/ecb155/32.png) [@Piyush](https://discourse.julialang.org/u/Piyush)\
**Post date:** [June 13, 2024, 4:54am UTC](https://discourse.julialang.org/t/custom-loss-in-diffeqparamestim/115580/1 "2024-06-13T04:54:32Z")

</div>

How to add first differencing term in custom loss function as included in the inbuilt L2Loss function?

Is there a way I can access the documentation for the same?

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [June 13, 2024, 5:02am UTC](https://discourse.julialang.org/t/custom-loss-in-diffeqparamestim/115580/2 "2024-06-13T05:02:51Z")

</div>

You need to specify which packages you are talking about, `L2Loss` is not a Julia built in function.

---

<div class="post-metadata">

**Author:** ![Piyush](https://avatars.discourse-cdn.com/v4/letter/p/ecb155/32.png) [@Piyush](https://discourse.julialang.org/u/Piyush)\
**Post date:** [June 13, 2024, 5:11am UTC](https://discourse.julialang.org/t/custom-loss-in-diffeqparamestim/115580/3 "2024-06-13T05:11:29Z")

</div>

@baggepinnen Hi, Thank you for your response. I am using `DiffEqParamEstim.jl` for parameter estimation. I would like to introduce `L2Loss first differencing functionality` to my custom loss function.

---

<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:** [June 13, 2024, 11:20am UTC](https://discourse.julialang.org/t/custom-loss-in-diffeqparamestim/115580/4 "2024-06-13T11:20:50Z")

</div>

> **[Optimization-Based Methods · DiffEqParamEstim.jl](https://docs.sciml.ai/DiffEqParamEstim/stable/methods/optimization_based_methods/#The-Loss-Function)**
>
> Documentation for DiffEqParamEstim.jl.

You just need to supply a non-zero differ\_weight.

`L2Loss(t, data; differ_weight = 1.0)`

And then it’ll add first differencing terms to the loss function with a weight of 1.0 (default for the L2 is 1.0 so that would be balance).
