Hi,
I am using Julia to solve the equation below, where
XS is a large matrix and XT is a transpose version of XS.
LamI is a diagonal matrix and RHS is a vector.
using DelimitedFiles
using LinearAlgebra
XS = readdlm(“XS.txt”)
RHS = readdlm(“rhs.txt”)
LamI = readdlm(“LamI.txt”)
XT=XS’
MME= XTXS + LamI
b = MME\RHS
GEBV=XSb
Error I got
ERROR: LoadError: MethodError: no method matching zero(::Type{Array{Float64,2}})
how can I fix it? thank you in advance.
If you could post a bit more of the error message or a MWE that would be helpful.
To me the concerning thing is the Type
part of the error. That seems to imply you are passing in an Array Datatype instead of an actual Array.
1 Like
yes, my datasets were Arrays from Julia, then I want to import data as an array to do the calculation,
here is the complete error.
ERROR: LoadError: MethodError: no method matching zero(::Type{Array{Float64,2}})
Closest candidates are:
zero(!Matched::Type{Missing}) at missing.jl:103
zero(!Matched::Type{Dates.Time}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Dates/src/types.jl:406
zero(!Matched::Type{LibGit2.GitHash}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/LibGit2/src/oid.jl:220
…
Stacktrace:
[1] pinv(::Array{Array{Float64,2},1}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/generic.jl:1054
[2] (::Array{Array{Float64,2},1}, ::Array{Float64,2}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/generic.jl:1121
[3] top-level scope at /net/fs-1/home01/wubu/.julia/environments/v1.5/jcode.jl:16
[4] include(::Function, ::Module, ::String) at ./Base.jl:380
[5] include(::Module, ::String) at ./Base.jl:368
[6] exec_options(::Base.JLOptions) at ./client.jl:296
[7] _start() at ./client.jl:506
in expression starting at /net/fs-1/home01/wubu/.julia/environments/v1.5/jcode.jl:16
the code b = RHS/MME
is (jcode.jl:16)
,
seems I have problem with the vector and arrays type.
This looks like RHS
is a vector of matrices, not a matrix.
Aside from that, please use triple backticks (```) for code blocks, not quotations. Otherwise, some characters are swallowed (in your original code block, there are some *
missing because they are used to toggle italics).
1 Like
yes, how can I fix the issue about RHS
?
That depends on what you want to do. I assume you want a vector of numbers instead of a vector of matrices? I don’t understand how you get a vector of matrices in the first place, I think readdlm
always returns a matrix. How is the rhs.txt file formatted?
Also, the stacktrace implies that you call \
, not /
, which is it?
yes, I want a vector of numbers, when I open the RHS
, it is a one-column vector with numbers.
I do not understand why matrix format and vector format matters for RHS
in this case.
and I thought b = RHS\MME
and b = MEE/RHS
are same.
It would not matter whether RHS
is a vector or a matrix if its elements were numbers. However, in this case, RHS
is a vector that contains matrices.
Not necessarily, although they are the same for numbers. Similar to how A*B
and B*A
are different if A
and B
are matrices, A/B
is equal to (B'\A')'
ok, altough I do not how to solve the problem, I am pretty sure that RHS
is a vector with numbers. and for calculating b
, I should use b = MEE/RHS
.
Can you check the types of the objects? For example, put
@show typeof(XS)
@show typeof(RHS)
@show typeof(LamI)
in your code.
1 Like
those are the data types and then I saved those file saved as txt
file using DelimitedFiles
typeof(XS) = Array{Float16,2}
@show typeof(LamI)
typeof(LamI) = Array{Float64,2}
@show typeof(RHS)
typeof(RHS) = Array{Float64,1}
Unfortunately it is kind of difficult to help with so little information. Could you paste a way to reproduce your arrays? Maybe uploading a smaller version of them and/or how to create them. It will be easier to debug then.
For example, in your code you don’t show the definition of XTXS
, which you are using then when you do
MME= XTXS + LamI
b = RHS/MME
You can take a look at this thread with advice on what kind of info would make it easier.
PSA: make it easier to help you
here is my small part of data,
and it is working, and I do not understand why I got MethodError
, when I use b = MME/RHS
I got error ERROR: DimensionMismatch("Both inputs should have the same number of columns")
RHS[1:5,:]
5×1 Array{Float64,2}:
-463.784842149869
613.3235123884596
344.87395521407393
-474.745592135491
-84.87248412192399
LamI[1:5,1:5]
5×5 Array{Float64,2}:
60928.0 0.0 0.0 0.0 0.0
0.0 60928.0 0.0 0.0 0.0
0.0 0.0 60928.0 0.0 0.0
0.0 0.0 0.0 60928.0 0.0
0.0 0.0 0.0 0.0 60928.0
XS[1:5,1:5]
5×5 Array{Float16,2}:
-1.036 1.006 0.2256 0.38 -1.691
-0.03613 0.006348 0.2256 0.38 -0.6914
-0.03613 0.006348 -0.7744 0.38 0.3086
-0.03613 0.006348 0.2256 -0.62 0.3086
0.964 -0.9937 0.2256 -0.62 0.3086
MME = XS’ * XS + LamI
5×5 Array{Float64,2}:
60930.0 -2.0 -0.00476074 -0.996094 2.05469
-2.0 60930.0 0.000854492 0.999023 -2.00781
-0.00476074 0.000854492 60928.8 -0.402588 -0.636719
-0.996094 0.999023 -0.402588 60929.2 -1.1709
2.05469 -2.00781 -0.636719 -1.1709 60931.6
b = MME\RHS
5×1 Array{Float64,2}:
-0.007611513860004633
0.0100658671109758
0.0056602111208895285
-0.0077920367386778286
-0.0013924157031305455
GEBV = XS*b
5×1 Array{Float64,2}:
0.018683329887863184
-0.00038155181207251366
-0.007434178636092588
0.006018069223474769
-0.011659311747505664
So it is working now? Great.
The error about the column number is probably related to
When you transpose the vector RHS you get only one column and many rows, or viceversa, then the operation is not possible. If MME is a square matrix, its number of rows and columns do not change when transposing.