Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Diff of /gmm_estimate.m [6da49b] .. [0e3aae] Maximize Restore

  Switch to side-by-side view

--- a/gmm_estimate.m
+++ b/gmm_estimate.m
@@ -1,4 +1,4 @@
-# Copyright (C) 2003,2004  Michael Creel michael.creel@uab.es
+# Copyright (C) 2003,2004,2005 Michael Creel michael.creel@uab.es
 # 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -14,12 +14,59 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-# performs the minimization
-function [theta, obj_value, convergence, iters] = gmm_estimate(theta, data, weight, moments, momentargs, control)
-	gmmargs = {theta, data, weight, moments, momentargs};
-	if nargin < 6
-		[theta, obj_value, convergence, iters] = bfgsmin("gmm_obj", gmmargs);
-	else
-		[theta, obj_value, convergence, iters] = bfgsmin("gmm_obj", gmmargs, control);
+# usage: [theta, obj_value, convergence, iters] = 
+#           gmm_estimate(theta, data, weight, moments, momentargs, control, nslaves)
+#
+# inputs:
+# theta: column vector initial parameters
+# data: data matrix
+# weight: the GMM weight matrix
+# moments: name of function computes the moments (should return nXg matrix of contributions)
+# momentargs: (cell) additional inputs needed to compute moments. May be empty ("")
+# names: vector of parameter names, e.g., use names = str2mat("param1", "param2");
+# title: string, describes model estimated
+# unscale: (optional) cell that holds means and std. dev. of data (see scale_data) 
+# control: (optional) BFGS or SA controls (see bfgsmin and samin). May be empty (""). 
+# nslaves: (optional) number of slaves if executed in parallel (requires MPITB)
+#
+# outputs:
+# theta: GMM estimate of parameters
+# obj_value: the value of the gmm obj. function
+# convergence: return code from bfgsmin (1 means success, see bfgsmin for details)
+# iters: number of BFGS iteration used 
+
+# call the minimizing routine
+function [theta, obj_value, convergence, iters] = gmm_estimate(theta, data, weight, moments, momentargs, control, nslaves)
+
+	if nargin < 5 error("gmm_estimate: 5 arguments required"); endif
+
+	if nargin < 6 control = {Inf,0,1,1}; endif # default controls
+	if !iscell(control) control = {Inf,0,1,1}; endif # default controls if receive placeholder
+	if nargin < 7 nslaves = 0; endif
+
+ 	if nslaves > 0
+		global NSLAVES PARALLEL NEWORLD NSLAVES TAG;
+		LAM_Init(nslaves);
+		# Send the data to all nodes
+		NumCmds_Send({"data", "weight", "moments", "momentargs"}, {data, weight, moments, momentargs});
 	endif
+
+	# bfgs or sa?
+	if (size(control,1)*size(control,2) == 0) # use default bfgs if no control
+		control = {Inf,0,1,1};	
+	  method = "bfgs";
+	elseif (size(control,1)*size(control,2) < 11)
+		method = "bfgs";
+	else method = "sa";	
+	endif
+	
+
+	if strcmp(method, "bfgs")
+	  [theta, obj_value, convergence, iters] = bfgsmin("gmm_obj", {theta, data, weight, moments, momentargs}, control);
+	elseif strcmp(method, "sa") 	
+	  [theta, obj_value, convergence] = samin("gmm_obj", {theta, data, weight, moments, momentargs}, control);
+	endif	
+
+	if nslaves > 0 LAM_Finalize; endif # clean up		
+
 endfunction