# User-defined objective function with scalar and vector inputs

**URL:** <https://discourse.julialang.org/t/user-defined-objective-function-with-scalar-and-vector-inputs/64218>\
**Category:** Optimization (Mathematical)\
**Created:** [July 7, 2021, 2:50pm UTC](https://discourse.julialang.org/t/user-defined-objective-function-with-scalar-and-vector-inputs/64218 "2021-07-07T14:50:12Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [July 7, 2021, 10:18pm UTC](https://discourse.julialang.org/t/user-defined-objective-function-with-scalar-and-vector-inputs/64218/4 "2021-07-07T22:18:45Z")

</div>

I think your function has to return a `Float64` instead of an `Int`. Try this:

```julia
# These shouldn't be inside the function or you have to read the 
# data frame _every_ time it gets called!!!
const df = CSV.read("data_estimation.csv", DataFrame; header=true)
const n = nrow(df)

function likelihood(ρ::T, α::T, fB::T, fS::T, fO::T, δ::T...) where {T}
    sum = zero(T)
    for i in 1:n
        # ...
    end
    return -sum
end 

```

Also: please read [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757). It’s easier to help if you post a minimal working example demonstrating the error.

---

_[View the full topic](https://discourse.julialang.org/t/user-defined-objective-function-with-scalar-and-vector-inputs/64218)._
