[Depmix-commits] r273 - pkg/R trunk/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 18 13:53:49 CEST 2009


Author: maarten
Date: 2009-06-18 13:53:47 +0200 (Thu, 18 Jun 2009)
New Revision: 273

Modified:
   pkg/R/responseGLMMULTINOM.R
   trunk/R/responseGLMMULTINOM.R
Log:
fixed bug in fit(responseGLMMULTINOMIAL): starting weights were set incorrectly

Modified: pkg/R/responseGLMMULTINOM.R
===================================================================
--- pkg/R/responseGLMMULTINOM.R	2009-05-13 14:57:54 UTC (rev 272)
+++ pkg/R/responseGLMMULTINOM.R	2009-06-18 11:53:47 UTC (rev 273)
@@ -9,11 +9,12 @@
 		y <- object at y
 		x <- object at x
 		#if(is.null(w)) w <- rep(1,nrow(y))
+		# mask is an nx*ny matrix (x are inputs, y are output levels)
 		mask <- matrix(1,nrow=nrow(pars$coefficients),ncol=ncol(pars$coefficients))
 		mask[,base] <- 0 # fix base category coefficients to 0
-		mask <- rbind(0,mask) # fix "bias" nodes to 0
+		mask <- rbind(0,mask) # fix automatic "bias" nodes to 0
 		Wts <- mask
-		Wts[-1,] <- t(pars$coefficients) # set starting weights
+		Wts[-1,] <- pars$coefficients # set starting weights
 		if(!is.null(w)) {
 			if(NCOL(y) < 3) {
 				fit <- nnet.default(x,y,weights=w,size=0,entropy=TRUE,skip=TRUE,mask=mask,Wts=Wts,trace=FALSE)
@@ -27,7 +28,9 @@
 				fit <- nnet.default(x,y,size=0,softmax=TRUE,skip=TRUE,mask=mask,Wts=Wts,trace=FALSE)
 			}
 		}
+		# this is necessary because setpars wants coefficients in column major order
 		pars$coefficients <- t(matrix(fit$wts,ncol=ncol(pars$coefficients),nrow=nrow(pars$coefficients)+1)[-1,])
+		# parameters are set correctly now
 		object <- setpars(object,unlist(pars))
 		object
 	}
Modified: trunk/R/responseGLMMULTINOM.R
===================================================================
--- trunk/R/responseGLMMULTINOM.R	2009-05-13 14:57:54 UTC (rev 272)
+++ trunk/R/responseGLMMULTINOM.R	2009-06-18 11:53:47 UTC (rev 273)
@@ -9,11 +9,12 @@
 		y <- object at y
 		x <- object at x
 		#if(is.null(w)) w <- rep(1,nrow(y))
+		# mask is an nx*ny matrix (x are inputs, y are output levels)
 		mask <- matrix(1,nrow=nrow(pars$coefficients),ncol=ncol(pars$coefficients))
 		mask[,base] <- 0 # fix base category coefficients to 0
-		mask <- rbind(0,mask) # fix "bias" nodes to 0
+		mask <- rbind(0,mask) # fix automatic "bias" nodes to 0
 		Wts <- mask
-		Wts[-1,] <- t(pars$coefficients) # set starting weights
+		Wts[-1,] <- pars$coefficients # set starting weights
 		if(!is.null(w)) {
 			if(NCOL(y) < 3) {
 				fit <- nnet.default(x,y,weights=w,size=0,entropy=TRUE,skip=TRUE,mask=mask,Wts=Wts,trace=FALSE)
@@ -27,7 +28,9 @@
 				fit <- nnet.default(x,y,size=0,softmax=TRUE,skip=TRUE,mask=mask,Wts=Wts,trace=FALSE)
 			}
 		}
+		# this is necessary because setpars wants coefficients in column major order
 		pars$coefficients <- t(matrix(fit$wts,ncol=ncol(pars$coefficients),nrow=nrow(pars$coefficients)+1)[-1,])
+		# parameters are set correctly now
 		object <- setpars(object,unlist(pars))
 		object
 	}


More information about the depmix-commits mailing list