From: Benjamin Auder Date: Mon, 9 Dec 2019 14:36:05 +0000 (+0100) Subject: Fix typos and mistakes X-Git-Url: https://git.auder.net/pieces/Cwda/current/%24%7BgetWhatsApp%28link%29%7D?a=commitdiff_plain;h=b389a46aa58d9e7f0bb45b7be72e01ebfba26d8e;p=morpheus.git Fix typos and mistakes --- diff --git a/pkg/R/optimParams.R b/pkg/R/optimParams.R index c061fcf..a5818ed 100644 --- a/pkg/R/optimParams.R +++ b/pkg/R/optimParams.R @@ -31,7 +31,7 @@ #' o$f( o$linArgs(par0) ) #' o$f( o$linArgs(par1) ) #' @export -optimParams = function(X, Y, K, link=c("logit","probit")) +optimParams <- function(X, Y, K, link=c("logit","probit")) { # Check arguments if (!is.matrix(X) || any(is.na(X))) @@ -119,13 +119,13 @@ setRefClass( { dim <- d + d^2 + d^3 W <<- solve( matrix( .C("Compute_Omega", - X=as.double(X), Y=as.double(Y), M=as.double(M(θ)), + X=as.double(X), Y=as.double(Y), M=as.double(Moments(θ)), pn=as.integer(n), pd=as.integer(d), W=as.double(W), PACKAGE="morpheus")$W, nrow=dim, ncol=dim) ) NULL #avoid returning W }, - M <- function(θ) + Moments = function(θ) { "Vector of moments, of size d+d^2+d^3" @@ -148,7 +148,7 @@ setRefClass( { "Product t(Mi - hat_Mi) W (Mi - hat_Mi) with Mi(theta)" - A <- M(θ) - Mhat + A <- Moments(θ) - Mhat t(A) %*% W %*% A }, @@ -156,8 +156,8 @@ setRefClass( { "Gradient of f, dimension (K-1) + d*K + K = (d+2)*K - 1" - -2 * t(grad_M(θ)) %*% getW(θ) %*% (Mhat - M(θ)) - } + -2 * t(grad_M(θ)) %*% W %*% (Mhat - Moments(θ)) + }, grad_M = function(θ) { @@ -256,10 +256,11 @@ setRefClass( ci=c(-1,rep(0,K-1)) ) # debug: - print(computeW(expArgs(op_res$par))) + #computeW(expArgs(op_res$par)) + #print(W) # We get a first non-trivial estimation of W # TODO: loop, this redefine f, so that we can call constrOptim again... - # Stopping condition? N iterations? Delta <= ε ? + # Stopping condition? N iterations? Delta <= epsilon ? expArgs(op_res$par) } diff --git a/pkg/src/functions.c b/pkg/src/functions.c index 8731b9f..c8d51dd 100644 --- a/pkg/src/functions.c +++ b/pkg/src/functions.c @@ -59,14 +59,14 @@ void Moments_M3(double* X, double* Y, int* pn, int* pd, double* M3) void Compute_Omega(double* X, double* Y, double* M, int* pn, int* pd, double* W) { int n=*pn, d=*pd; - //int dim = d+d*d+d*d*d + int dim = d + d*d + d*d*d; //double* W = (double*)calloc(dim*dim,sizeof(double)); double* g = (double*)malloc(dim * sizeof(double)); for (int i=0; i