# Multiple dimensional sampling with first element string

**URL:** <https://discourse.julialang.org/t/multiple-dimensional-sampling-with-first-element-string/58863>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, flux\
**Created:** [April 8, 2021, 5:44pm UTC](https://discourse.julialang.org/t/multiple-dimensional-sampling-with-first-element-string/58863 "2021-04-08T17:44:28Z")\
**Posts on this page:** 1\
**Showing post:** 32

<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:** [April 9, 2021, 4:52am UTC](https://discourse.julialang.org/t/multiple-dimensional-sampling-with-first-element-string/58863/32 "2021-04-09T04:52:22Z")

</div>

x-ref: [ArgumentError: invalid index: "s1" of type String](https://discourse.julialang.org/t/argumenterror-invalid-index-s1-of-type-string/58738)

@GraceMabele you need to step back and re-consider what you are trying to do.

```nohighlight
g = d -> @objective m Max begin
    sum((price[s]*d[s,n]) for n in N for s in S)
end

```

is a JuMP objective. it doesn’t make sense to try and fit a surrogate model to this, regardless of which method you chose.

It seems you really want something like

```julia
const S = ["s1","s2","s3","s4"]
const N = 1:10

const price = Dict(
    "s1" => 0,
    "s2" => 0,
    "s3" => 0,
    "s4" => 5
)

function objective(d::Matrix{<:Real})
    return sum(price[s] * d[i, n] for n in N for (i, s) in enumerate(S))
end

objective(rand(4, 10)) # Objective given a random demand

```

and now your take is to approximate `objective` given a 4x10 input matrix.

Here’s something to get you started

```julia
function objective(d::NTuple)
    return objective(reshape(collect(d), length(S), length(N)))
end

lb = fill(0.0, 40)
ub = fill(1.0, 40)
x_train = sample(10, lb, ub, SobolSample())
y_train = objective.(x_train)

```

However, I would again caution you. If you can write down the JuMP objective, why are you trying to fit a surrogate?

---

_[View the full topic](https://discourse.julialang.org/t/multiple-dimensional-sampling-with-first-element-string/58863)._
