X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2FoptimParams.R;h=13aec835f3a39e9060b6d080e10913ea3f121403;hb=074c721aa587d45c4f7ef10f8a28fdc09273d31a;hp=b7d901c16fae591f7c320d235cf7be825d76115c;hpb=0f5fbd1371011f25cd1f6caf0e826d2ea9e4e245;p=morpheus.git diff --git a/pkg/R/optimParams.R b/pkg/R/optimParams.R index b7d901c..13aec83 100644 --- a/pkg/R/optimParams.R +++ b/pkg/R/optimParams.R @@ -104,7 +104,7 @@ setRefClass( list( # p: dimension K-1, need to be completed "p" = c(v[1:(K-1)], 1-sum(v[1:(K-1)])), - "β" = matrix(v[K:(K+d*K-1)], ncol=K), + "β" = t(matrix(v[K:(K+d*K-1)], ncol=d)), "b" = v[(K+d*K):(K+(d+1)*K-1)]) }, @@ -112,17 +112,17 @@ setRefClass( { "Linearize vectors+matrices from list L into a vector" - c(L$p[1:(K-1)], as.double(L$β), L$b) + # β linearized row by row, to match derivatives order + c(L$p[1:(K-1)], as.double(t(L$β)), L$b) }, computeW = function(θ) { - #return (diag(c(rep(6,d), rep(3, d^2), rep(1,d^3)))) require(MASS) dd <- d + d^2 + d^3 M <- Moments(θ) Omega <- matrix( .C("Compute_Omega", - X=as.double(X), Y=as.double(Y), M=as.double(M), + X=as.double(X), Y=as.integer(Y), M=as.double(M), pn=as.integer(n), pd=as.integer(d), W=as.double(W), PACKAGE="morpheus")$W, nrow=dd, ncol=dd ) MASS::ginv(Omega) @@ -257,7 +257,7 @@ setRefClass( else if (!is.numeric(θ0$b) || length(θ0$b) != K || any(is.na(θ0$b))) stop("θ0$b: length K, no NA") # TODO: stopping condition? N iterations? Delta <= epsilon ? - for (loop in 1:10) + for (loop in 1:2) { op_res = constrOptim( linArgs(θ0), .self$f, .self$grad_f, ui=cbind(