From 3823a5d997e90864728c55bbf195611709eeac01 Mon Sep 17 00:00:00 2001 From: Alexey Stukalov Date: Sun, 10 Mar 2024 22:22:51 -0700 Subject: [PATCH 1/5] cov_and_mean(): fix rows splatting --- src/additional_functions/helper.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/additional_functions/helper.jl b/src/additional_functions/helper.jl index 26d079b00..dca309389 100644 --- a/src/additional_functions/helper.jl +++ b/src/additional_functions/helper.jl @@ -114,11 +114,11 @@ function sparse_outer_mul!(C, A, B::Vector, ind) #computes A*S*B -> C, where ind end function cov_and_mean(rows; corrected = false) - data = permutedims(hcat(rows...)) + data = reduce(vcat, rows) size(rows, 1) > 1 ? obs_cov = Statistics.cov(data; corrected = corrected) : obs_cov = reshape([0.0],1,1) - obs_mean = vcat(Statistics.mean(data, dims = 1)...) + obs_mean = vec(Statistics.mean(data, dims = 1)) return obs_cov, obs_mean end From 92b8eace703beaad2f47b028acac647b96759338 Mon Sep 17 00:00:00 2001 From: Alexey Stukalov Date: Sun, 10 Mar 2024 22:23:25 -0700 Subject: [PATCH 2/5] get_matrix_derivative(): fix splatting --- src/additional_functions/parameters.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/additional_functions/parameters.jl b/src/additional_functions/parameters.jl index b381e1c32..13aa1cd41 100644 --- a/src/additional_functions/parameters.jl +++ b/src/additional_functions/parameters.jl @@ -103,7 +103,7 @@ function get_matrix_derivative(M_indices, parameters, n_long) ones(length(M_indices[i])), n_long) for i in 1:length(parameters)] - ∇M = hcat(∇M...) + ∇M = reduce(hcat, ∇M) return ∇M From ae7cf6b68af0c3298e6c8d4cdbc8864fa07c692c Mon Sep 17 00:00:00 2001 From: Alexey Stukalov Date: Sun, 10 Mar 2024 22:28:50 -0700 Subject: [PATCH 3/5] test: cleanup params assignment --- test/examples/multigroup/multigroup.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/examples/multigroup/multigroup.jl b/test/examples/multigroup/multigroup.jl index a86371caa..5ef6bd8c6 100644 --- a/test/examples/multigroup/multigroup.jl +++ b/test/examples/multigroup/multigroup.jl @@ -21,25 +21,24 @@ dat_miss_g2 = dat_missing[dat_missing.school .== "Grant-White", :] ############################################################################################ x = Symbol.(:x, 1:36) -#x = [x...] F = zeros(9, 12) F[diagind(F)] .= 1.0 A = Matrix{Any}(zeros(12, 12)) A[1, 10] = 1.0; A[4, 11] = 1.0; A[7, 12] = 1.0 -A[2:3, 10] .= [x...][16:17]; A[5:6, 11] .= [x...][18:19]; A[8:9, 12] .= [x...][20:21]; +A[2:3, 10] .= x[16:17]; A[5:6, 11] .= x[18:19]; A[8:9, 12] .= x[20:21]; # group 1 S1 = Matrix{Any}(zeros(12, 12)) -S1[diagind(S1)] .= [x...][1:12] +S1[diagind(S1)] .= x[1:12] S1[10, 11] = x[13]; S1[11, 10] = x[13] S1[10, 12] = x[14]; S1[12, 10] = x[14] S1[12, 11] = x[15]; S1[11, 12] = x[15] # group 2 S2 = Matrix{Any}(zeros(12, 12)) -S2[diagind(S2)] .= [x...][22:33] +S2[diagind(S2)] .= x[22:33] S2[10, 11] = x[34]; S2[11, 10] = x[34] S2[10, 12] = x[35]; S2[12, 10] = x[35] S2[12, 11] = x[36]; S2[11, 12] = x[36] From 6d9c00004d158e061c1a341ff20460dc463da058 Mon Sep 17 00:00:00 2001 From: Alexey Stukalov Date: Sun, 10 Mar 2024 22:55:45 -0700 Subject: [PATCH 4/5] fixup cov_and_mean() --- src/additional_functions/helper.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/additional_functions/helper.jl b/src/additional_functions/helper.jl index dca309389..ffb02684e 100644 --- a/src/additional_functions/helper.jl +++ b/src/additional_functions/helper.jl @@ -114,7 +114,7 @@ function sparse_outer_mul!(C, A, B::Vector, ind) #computes A*S*B -> C, where ind end function cov_and_mean(rows; corrected = false) - data = reduce(vcat, rows) + data = mapreduce(transpose, vcat, rows) size(rows, 1) > 1 ? obs_cov = Statistics.cov(data; corrected = corrected) : obs_cov = reshape([0.0],1,1) From d0b2feedc5965746f837d3a783c482ea10e21e48 Mon Sep 17 00:00:00 2001 From: Maximilian-Stefan-Ernst <34346372+Maximilian-Stefan-Ernst@users.noreply.github.com> Date: Tue, 12 Mar 2024 16:43:36 +0100 Subject: [PATCH 5/5] Update src/additional_functions/helper.jl --- src/additional_functions/helper.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/additional_functions/helper.jl b/src/additional_functions/helper.jl index ffb02684e..91095e071 100644 --- a/src/additional_functions/helper.jl +++ b/src/additional_functions/helper.jl @@ -114,7 +114,7 @@ function sparse_outer_mul!(C, A, B::Vector, ind) #computes A*S*B -> C, where ind end function cov_and_mean(rows; corrected = false) - data = mapreduce(transpose, vcat, rows) + data = transpose(reduce(hcat, rows)) size(rows, 1) > 1 ? obs_cov = Statistics.cov(data; corrected = corrected) : obs_cov = reshape([0.0],1,1)