Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overloading Base.show #47

Open
torfjelde opened this issue Sep 18, 2019 · 7 comments
Open

Overloading Base.show #47

torfjelde opened this issue Sep 18, 2019 · 7 comments

Comments

@torfjelde
Copy link
Member

torfjelde commented Sep 18, 2019

Currently we've done nothing to improve the "visual inspection" of objects. At the moment it can be very difficult for the user to inspect a Bijector. And with PR #44 we're going to also have dimensionality in the type which makes it even more important to easily be able to inspect a Bijector.

Sooo let's have another poll! Which of the following styles do you prefer:

  1. Distributions.jl-style and Dims=1 for "container" types, e.g. Composed and Stacked
julia> Bijectors.Exp()
Exp{0}()

julia> Bijectors.Logit(0.0, 1.0)
Logit{Float64}(a=0.0, b=1.0)

julia> Bijectors.composel([PlanarLayer(10) for i = 1:3]...)
Composed{..., Dims=1}(ts=(PlanarLayer{Array{Float64,2},Array{Float64,1}}(
w: [-1.10143; 1.33204;  ; -0.725184; -0.279187]
u: [-0.755879; 1.6483;  ; 1.15966; -0.164425]
b: [0.09642]
)
, PlanarLayer{Array{Float64,2},Array{Float64,1}}(
w: [-0.913726; -2.03212;  ; 0.0719403; -0.0622856]
u: [-1.28574; -0.0194101;  ; -0.760258; 0.555373]
b: [-0.951921]
)
, PlanarLayer{Array{Float64,2},Array{Float64,1}}(
w: [1.14896; 0.710024;  ; -2.24741; -0.904142]
u: [0.917471; 1.07336;  ; -1.01782; 0.230862]
b: [0.535096]
)
))
  1. Distributions.jl-style
julia> Bijectors.Exp()
Exp{0}()

julia> Bijectors.Logit(0.0, 1.0)
Logit{Float64}(a=0.0, b=1.0)

julia> Bijectors.composel([PlanarLayer(10) for i = 1:3]...)
Composed(ts=(PlanarLayer{Array{Float64,2},Array{Float64,1}}(
w: [1.67265; -0.888749;  ; -1.3403; -0.0615207]
u: [0.741016; 0.355929;  ; -1.22854; 0.5851]
b: [1.00029]
)
, PlanarLayer{Array{Float64,2},Array{Float64,1}}(
w: [0.401001; -0.586282;  ; 0.359551; 0.736369]
u: [1.26738; -0.194372;  ; 1.13786; -0.0398834]
b: [1.08065]
)
, PlanarLayer{Array{Float64,2},Array{Float64,1}}(
w: [-1.01392; -0.70209;  ; -1.8464; 0.212027]
u: [-0.726696; -2.39618;  ; -0.169901; -0.526239]
b: [1.02857]
)
))
  1. Current one:
julia> Bijectors.Exp()
Exp{0}()

julia> Bijectors.Logit(0.0, 1.0)
Logit{Float64}(0.0, 1.0)

julia> Bijectors.composel([PlanarLayer(10) for i = 1:3]...)
Composed{Tuple{PlanarLayer{Array{Float64,2},Array{Float64,1}},PlanarLayer{Array{Float64,2},Array{Float64,1}},PlanarLayer{Array{Float64,2},Array{Float64,1}}},1}((PlanarLayer{Array{Float64,2},Array{Float64,1}}([0.700402; -0.489015;  ; -1.31095; -1.94269], [-0.199911; 1.38871;  ; -0.464837; 0.853309], [0.0885244]), PlanarLayer{Array{Float64,2},Array{Float64,1}}([-0.238407; -0.00701318;  ; 0.921103; 1.26528], [-0.17988; -0.0505573;  ; -0.886066; 1.18275], [0.467128]), PlanarLayer{Array{Float64,2},Array{Float64,1}}([0.231724; 0.39539;  ; -0.418577; -1.75923], [-0.055946; 1.37152;  ; 1.26864; -1.2355], [-0.636524])))

To vote: 👍 : for (1), 😕 for (2), and 👎 for (3).

Other suggestions welcome!

@trappmartin
Copy link
Member

How does 1 differ from 2?

@torfjelde
Copy link
Member Author

The {..., Dims=1} in Composed. After #44 we'll have dimension information in Bijector, and in the case of these "wrapper" bijectors, e.g. Composed, it could be nice to show the dimensionality of the bijector:)

@torfjelde
Copy link
Member Author

We can also drop the Dims= and just write the dimensionality N, which is similar to what you get by default for all other bijectors, e.g. Exp() is displayed as Exp{0}() because by default we assume Exp to be 0-dimensional (can also instantiate as Exp{N}() where N is an integer)

@trappmartin
Copy link
Member

I see, I think the dims is a good idea.

@torfjelde
Copy link
Member Author

You can see how the README will look with dimensionality from PR #44 combined with the proposed Base.show overload over at https://github.com/torfjelde/Bijectors.jl/tree/tor/show-overload

@trappmartin
Copy link
Member

Would it make sense to use lower-case dim instead of Dim? I think this would be more julia style.

@torfjelde
Copy link
Member Author

I'm not necessarily against that; my reasoning for choosing Dim is because it's a type-parameter rather than an argument. Could also rename to D or dim as you suggested :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants