Turing.jl icon indicating copy to clipboard operation
Turing.jl copied to clipboard

Feature Request: Better Indexing for ModeResult object

Open BlackWingedKing opened this issue 5 years ago • 5 comments

Based on the discussion here I was using Turing's MLE, MAP estimation. The object returned by optimize(model, MLE()) is a ModeResult object Here is a sample example.

mle_estimate = optimize(model, MLE())
ModeResult with maximized lp of -141.20
36-element Named Array{Float64,1}
A                 │ 
──────────────────┼────────
:scale            │     1.4
Symbol("lsd[1]")  │ 7.23206
Symbol("lsd[2]")  │ 14.6571
Symbol("lsd[3]")  │ 9.90191
Symbol("lsd[4]")  │ 7.91973
Symbol("lsd[5]")  │ 5.67751
Symbol("lsd[6]")  │ 6.80444
Symbol("lsd[7]")  │ 5.82526
Symbol("lsd[8]")  │ 6.97793
Symbol("lsd[9]")  │  14.528
Symbol("lsd[10]") │  9.5812
Symbol("lsd[11]") │ 13.3083
⋮                         ⋮
Symbol("u[7]")    │ 73.7783
Symbol("u[8]")    │ 25.0389
Symbol("u[9]")    │ 30.4734
Symbol("u[10]")   │ 61.6176
Symbol("u[11]")   │  17.547
Symbol("u[12]")   │ 29.3112
Symbol("u[13]")   │ 56.5756
Symbol("u[14]")   │ 93.1553
Symbol("u[15]")   │ 29.0809
Symbol("u[16]")   │ 57.9938
Symbol("u[17]")   │ 27.6348
:σ                │ 2.27592

mle_estimate.values is a NamedArray and to get all the values corresponding to u[i] in the array I need to do getindex(mle_estimate.values, [Symbol("u[$(i)]") for i in 1:17]). For dynamic u array size we might have to follow the roundabout suggested in the slack thread.

It would be great to have a function get similar to the one for chains object So that get(mle_estimate, :u) returns all the values corresponding to u[i] in an array

BlackWingedKing avatar Sep 28 '20 03:09 BlackWingedKing

@cpfiffer

BlackWingedKing avatar Sep 28 '20 03:09 BlackWingedKing

Maybe it would make sense to not flatten the values? E.g. as a ComponentArray (or ComponentMatrix, to be precise)?

devmotion avatar Sep 28 '20 06:09 devmotion

Ah never mind, I don't think it supports components of different shapes. So the alternative would be a NamedTuple, I guess.

devmotion avatar Sep 28 '20 06:09 devmotion

Hey is the issue open ? Also can i take it up ?

codeboy5 avatar Oct 07 '20 17:10 codeboy5

Sure, if you like.

cpfiffer avatar Oct 08 '20 02:10 cpfiffer