How to parse output of unknown type in Julia

Viewed 63

I am running a function from an external library here: https://github.com/baggepinnen/SingularSpectrumAnalysis.jl

When running, I get this output printed in the console:


LinearAlgebra.SVD{Float64,Float64,Array{Float64,2}}
U factor:
3465×10 Array{Float64,2}:
 -0.0176092   0.0162669   -0.0286626   …  -0.0123348   -0.00889247    0.0149834
 -0.0176079   0.023189    -0.00313753      0.0234491   -0.000954835   0.0237124
 -0.0175925   0.0216939    0.0187119       0.0418525   -0.0296555     0.0665848
 -0.0175613   0.0146738    0.0288932      -0.0266382    0.0127913     0.00602873
 -0.0175472   0.0072105    0.0349358       0.0225667   -0.0167306    -0.02098
 -0.0175337  -3.25703e-5   0.0304511   …  -0.0229247   -0.00725249   -0.00814757
 -0.0175243  -0.0070557    0.0154106       0.0424862   -0.0206749    -0.0115423
  ⋮                                    ⋱                             
 -0.0124291   0.0454897   -0.0153655      -0.019238     0.00716989    0.00251159
 -0.0122423   0.0435812   -0.0148046   …  -0.0139234   -0.0187464     0.00739847
 -0.0121735   0.0346687    0.00278444     -0.00218233   0.0110443    -0.00929289
 -0.0121211   0.0290382    0.0110726       0.0107806   -0.00106763    0.0317442
 -0.0120607   0.0194982    0.0217969       0.00578442  -0.0117156    -0.00232344
 -0.0120144   0.0126667    0.0164779      -0.0106475    0.00061507   -0.00797532
singular values:
10-element Array{Float64,1}:
 23396.412954604883
    89.77233712912785
    22.739080907231845
     6.7695870707469386
     1.3883392478470917
     2.8068174835480837e-12
     8.400039642654283e-13
     8.317837915706779e-13
     8.065049690243271e-13
     7.945414181455442e-13
Vt factor:
10×10 Array{Float64,2}:
 -0.316135   -0.316298    -0.316323   …  -0.316206   -0.31614    -0.315936
  0.408793    0.414593     0.333553      -0.33494    -0.41203    -0.407189
  0.363599    0.306612     0.0442128      0.0537767   0.309203    0.350534
 -0.314074   -0.183525     0.255186      -0.246725    0.186592    0.323551
 -0.295283   -0.0484189    0.451627       0.462796   -0.0426143  -0.315369
  0.455353   -0.378881    -0.296744   …   0.171696    0.409193   -0.445054
 -0.326408    0.586176    -0.435839       0.420663   -0.0126025  -0.143472
  0.114133    0.0540144   -0.485488      -0.155216   -0.293115    0.27703
 -0.0714588   0.00900755   0.0450054     -0.018732   -0.13437     0.165802
  0.287902   -0.328451     0.0436344      0.528208   -0.571383    0.290639

How do I parse this output to get the "U factor:", "singular values:" and "Vt factor:" output as arrays I can work with in a notebook?

I've tried indexing by position and by name ([1] or ["U factor"]). Both result in errors such as this:

MethodError: no method matching getindex(::LinearAlgebra.SVD{Float64,Float64,Array{Float64,2}}, ::Int64)

1 Answers

It is a part of a standard library, so it can be found in documentation: https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#LinearAlgebra.svd

Output is only visual representation of the data, so it can't be used to access data programmatically. You should use docs or introspection functions like fieldnames to understand how to work with the object. In this case, you should use fields U, S and Vt of an SVD object.

Related