tpapp / TransformVariables.jl

Transformations to contrained variables from ℝⁿ.
Other
66 stars 14 forks source link

Transform (flatten) as Vector{Matrix} #47

Closed ericphanson closed 5 years ago

ericphanson commented 5 years ago

I have a model with observations occurring at a set of discrete time steps, where at each time one observes a matrix, and it would be great to be able to flatten from this case. More specifically, for the case of a single timestep, I can just follow one of the examples:

t = as((γ = as(Array, length(γ)),)) # identity transformation, just to get the dimension

But for multiple timesteps, it would be great to be able to do

t = as((γ = as(Vector{Array}, length(γ), length(γ[1])),)) 

or something like that.

(Maybe this relates to https://github.com/tpapp/TransformVariables.jl/issues/13?)

Would you be able to give me some pointers about how to go about this?

P.S. This is a very nice set of packages!

ericphanson commented 5 years ago

Sorry, I realized it's enough to have Vector{Vector} observations for my use (of course one can just reshape anyway), and somehow just asking it to transform as an array already does this. I think I definitely don't understand how it works but I don't think this feature request is necessary. I'll try to make a docs pull request later to clarify whatever has confused me.

tpapp commented 5 years ago

Reopening because I would like to make sure I got the request correctly. Is this what you want:

julia> using TransformVariables
t = as(Vector, as(Vector, 3), 4)

julia> t = as(Vector, as(Vector, 3), 4)
TransformVariables.ArrayTransform{TransformVariables.ArrayTransform{TransformVariables.Identity,1},1}(TransformVariables.ArrayTransform{TransformVariables.Identity,1}(TransformVariables.Identity(), (3,)), (4,))

julia> dimension(t)
12

julia> t(1:12)
4-element Array{Array{Int64,1},1}:
 [1, 2, 3]   
 [4, 5, 6]   
 [7, 8, 9]   
 [10, 11, 12]

If not, please provide an example of the input and output you would like to see.

ericphanson commented 5 years ago

That's very helpful, thank you. What I originally wanted (i.e. in https://github.com/tpapp/TransformVariables.jl/issues/47#issue-467240085) was

t = as(Vector, as(Matrix, 3,3), 4)

which I now know how to do thanks to that example. Then in the next post, I realized I actually wanted t = as(Vector, as(Vector, 3), 4) as you wrote above (which I still didn't know how to do until your example, but I realized was mixed up so I closed the issue to try to think about it later).

tpapp commented 5 years ago

Great, I am closing then. Feel free to open another issue if you have questions.