Closed timholy closed 4 years ago
This may be an issue with GLM (or LinearAlgebra). I narrowed it down to this minimal example. Failed when X has more columns than rows:
julia> using GLM: DensePredQR
julia> using LinearAlgebra
julia> X = [ones(5) rand(5,16)]
5×17 Array{Float64,2}:
1.0 0.580274 0.132501 0.37971 0.833601 0.475992 … 0.920004 0.497813 0.478095 0.511493
1.0 0.315058 0.544557 0.180399 0.411512 0.059083 0.254424 0.102081 0.0286219 0.647392
1.0 0.391001 0.504542 0.442633 0.969872 0.407162 0.435692 0.642055 0.424189 0.0115529
1.0 0.564244 0.794587 0.878073 0.626503 0.980334 0.940471 0.326352 0.567887 0.138451
1.0 0.645479 0.0293748 0.633139 0.116494 0.801077 0.432296 0.132267 0.0319513 0.552074
julia> pp = DensePredQR(X, [1.0; zeros(16)])
DensePredQR{Float64}([1.0 0.580274009583994 … 0.47809477805270717 0.5114929068474399; 1.0 0.3150583269104097 … 0.028621904555609978 0.6473922612151892; … ; 1.0 0.5642437355787289 … 0.5678874314808784 0.13845091449127933; 1.0 0.6454792441633972 … 0.031951265718494826 0.5520738462543564], [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], LinearAlgebra.QRCompactWY{Float64,Array{Float64,2}}([-2.23606797749979 -1.116270170750235 … -0.6845695901066935 -0.832247875015137; 0.3090169943749474 0.2789561805801902 … 0.10463228340229419 0.038530583627515824; … ; 0.3090169943749474 -0.08190521016680165 … -0.11848808249638054 -0.26013205225776165; 0.3090169943749474 -0.2483172515160915 … -0.38510326696972386 0.3625685822485454], [1.4472135954999579 -0.737806952509757 … 0.6614848324933887 0.0; 6.9236266118005e-310 1.749948096097638 … 0.6485165557577766 0.0; … ; 6.9236266118068e-310 6.92362661182263e-310 … 1.538444946831569 0.0; 6.92362661181e-310 6.9236266118258e-310 … 6.9236266118574e-310 0.0]))
julia> cholesky!(pp)
Cholesky{Float64,Array{Float64,2}}
U factor:
Error showing value of type Cholesky{Float64,Array{Float64,2}}:
ERROR: DimensionMismatch("matrix is not square: dimensions are (5, 17)")
Stacktrace:
[1] show(::IOContext{REPL.Terminals.TTYTerminal}, ::MIME{Symbol("text/plain")}, ::Cholesky{Float64,Array{Float64,2}}) at /home/amanela/julialang/julia-1.2.0/share/julia/stdlib/v1.2/LinearAlgebra/src/cholesky.jl:214
[2] display(::REPL.REPLDisplay, ::MIME{Symbol("text/plain")}, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:132
[3] display(::REPL.REPLDisplay, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:136
[4] display(::Any) at ./multimedia.jl:323
[5] #invokelatest#1 at ./essentials.jl:790 [inlined]
[6] invokelatest at ./essentials.jl:789 [inlined]
[7] print_response(::IO, ::Any, ::Bool, ::Bool, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:156
[8] print_response(::REPL.AbstractREPL, ::Any, ::Bool, ::Bool) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:141
[9] (::getfield(REPL, Symbol("#do_respond#38")){Bool,getfield(REPL, Symbol("##48#57")){REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:718
[10] #invokelatest#1 at ./essentials.jl:790 [inlined]
[11] invokelatest at ./essentials.jl:789 [inlined]
[12] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.2/REPL/src/LineEdit.jl:2306
[13] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:1038
[14] run_repl(::REPL.AbstractREPL, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:201
[15] (::getfield(Base, Symbol("##737#739")){Bool,Bool,Bool,Bool})(::Module) at ./client.jl:390
[16] #invokelatest#1 at ./essentials.jl:790 [inlined]
[17] invokelatest at ./essentials.jl:789 [inlined]
[18] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at ./client.jl:374
[19] exec_options(::Base.JLOptions) at ./client.jl:312
[20] _start() at ./client.jl:464
Works when X has less columns than rows:
julia> X = [ones(5) rand(5,3)]
5×4 Array{Float64,2}:
1.0 0.306428 0.31801 0.184585
1.0 0.232915 0.764172 0.0942903
1.0 0.76324 0.417055 0.75017
1.0 0.0693803 0.0189854 0.606391
1.0 0.115757 0.928158 0.407045
julia> pp = DensePredQR(X, [1.0; zeros(3)])
DensePredQR{Float64}([1.0 0.3064275898269031 0.31800993546137724 0.18458464212986359; 1.0 0.232914966109671 0.7641719493937462 0.09429026058084755; … ; 1.0 0.06938027136383895 0.018985389499792893 0.6063908045626791; 1.0 0.11575738677580527 0.9281580476591449 0.4070448096847634], [1.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], LinearAlgebra.QRCompactWY{Float64,Array{Float64,2}}([-2.23606797749979 -0.665328504116652 -1.094054353537571 -0.9134248915931886; 0.3090169943749474 0.5533834420112992 -0.045900417539708194 0.23951738896324892; … ; 0.3090169943749474 0.3719791225729259 -0.566711539751736 -0.44845316472968644; 0.3090169943749474 0.29726861774802116 0.38777842756814573 0.34418746977329984], [1.4472135954999579 -0.4632669079734904 -1.0287834052206186 -1.4790393596226374; NaN 1.1217495432487656 1.2826653568087332 0.04231760876926971; 1.5e-323 6.9236282580383e-310 1.35912584673567 1.0529285021131154; 6.92352103362253e-310 2.0e-323 0.0 1.788165006809973]))
julia> cholesky!(pp)
Cholesky{Float64,Array{Float64,2}}
U factor:
4×4 UpperTriangular{Float64,Array{Float64,2}}:
-2.23607 -0.665329 -1.09405 -0.913425
⋅ 0.553383 -0.0459004 0.239517
⋅ ⋅ -0.722357 0.215147
⋅ ⋅ ⋅ -0.448453
Thanks for fixing this!
I'm attempting to use this in a multidimensional context in which the number of observations is smaller than the number of variables. I'm getting some errors I don't understand. Here's a demo:
Note that the first error is triggered upon display, the computation of
m
succeeds.Contrast this with
but for which it's not possible to compute the error: