# The question about Turing likelihood

**URL:** https://discourse.julialang.org/t/the-question-about-turing-likelihood/129293
**Category:** New to Julia
**Tags:** question, turing
**Created:** [May 24, 2025, 2:31pm UTC](https://discourse.julialang.org/t/the-question-about-turing-likelihood/129293 "2025-05-24T14:31:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Cyan](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Cyan](https://discourse.julialang.org/u/Cyan)
#### Post date: [May 24, 2025, 2:31pm UTC](https://discourse.julialang.org/t/the-question-about-turing-likelihood/129293/1 "2025-05-24T14:31:27Z")

</div>

Hi, all. I am new to Julia, I am trying to fit an image model, I aim to minimize the model image and observed image:

```julia
minimize(sum(model_intensity - data_obs))

```

both model\_intensity and data\_obs are 2d-array.  
I am not sure the following likelihood meets my requirement:

```julia
for i in eachindex(data_obs)
        data_obs[i] ~ Normal(model_intensity[i], sigma)
end

```

---

<div class="post-metadata">

### Author: ![sethaxen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sethaxen/32/35604_2.png) [@sethaxen](https://discourse.julialang.org/u/sethaxen)
#### Post date: [May 24, 2025, 4:26pm UTC](https://discourse.julialang.org/t/the-question-about-turing-likelihood/129293/2 "2025-05-24T16:26:00Z")

</div>

The problem with minimizing the sum is that it’s numerically the same as

```julia
minimize(sum(model_intensity) - sum(data_obs)) 

```

So you’re effectively collapsing each image down into a single scalar and then comparing those scalars, which is not very informative. You probably want to minimize the mean squared error (corresponds to a Normal likelihood) or mean absolute error (corresponds to a Laplace likelihood).

---

<div class="post-metadata">

### Author: ![Cyan](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Cyan](https://discourse.julialang.org/u/Cyan)
#### Post date: [May 24, 2025, 4:28pm UTC](https://discourse.julialang.org/t/the-question-about-turing-likelihood/129293/3 "2025-05-24T16:28:33Z")

</div>

Thank you for your replay. Yes, I want to minimize the mean square error. Is the above formula correct?

---

<div class="post-metadata">

### Author: ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)
#### Post date: [May 24, 2025, 7:24pm UTC](https://discourse.julialang.org/t/the-question-about-turing-likelihood/129293/4 "2025-05-24T19:24:41Z")

</div>

Looks correct to me. MSE is the negative log-likelihood of a normal distribution with fixed variance. Your code says that each `data_obs[i]` is normally distributed with the expected value given by your model, which is correct.
