Commits

stevejb committed 974cb0b

Updates to make DDW SMM really fast

Comments (0)

Files changed (4)

data/iss_calc_moments.R

 
 indiv4 = lapply(cusiplist, subsetByCusip, data.q)
 library(multicore)
-indiv4.mc = mclapply(cusiplist, subsetByCusip, data.q)
-all.equal(indiv4, indiv4.mc)
+## indiv4.mc = mclapply(cusiplist, subsetByCusip, data.q)
+## all.equal(indiv4, indiv4.mc)
 
 i4 = list()
 icount = 1
   influence_stack = do.call("rbind", mmmatlist)
   gmmweights = solve(influence_stack %*% t(influence_stack)/n)
 
+
+  mmmatlist_ddw = list(if.mean_inv, if.var_inv, if.inv_3rd_central, if.mean_lev, if.var_lev, if.mean_opr_income, if.ser_cor, if.var_oper_income_innov, if.mean_tobins_q, if.mean_eq, if.var_eq, if.mean_cash_bal)
+  
+  influence_stack_ddw = do.call("rbind", mmmatlist_ddw)
+  gmmweights_ddw = solve(influence_stack_ddw %*% t(influence_stack_ddw)/n)
+
+
   if(fname != NULL) {
     fname = "DEFAULT___"
   }
 
+  fname_ddw = paste(fname, "_ddw_")
+
   ## write out the rawdata.csv and the GMM weighting matrix
   write.csv(dwl, paste(fname, "rawdata.csv", sep=""))
   writeRawCSV(gmmweights, paste(fname, "gmmweights.csv", sep=""))
-  
+  writeRawCSV(gmmweights_ddw, paste(fname_ddw, "gmmweights.csv", sep=""))
+
   ## write out all of the moments that make this happen
   mf2 = data.frame(mean_inv,
     var_inv,

data/iss_calc_moments_byIndustry.R

   influence_stack = do.call("rbind", mmmatlist)
   gmmweights = solve(influence_stack %*% t(influence_stack)/n)
 
+  mmmatlist_ddw = list(if.mean_inv, if.var_inv, if.inv_3rd_central, if.mean_lev, if.var_lev, if.mean_opr_income, if.ser_cor, if.var_oper_income_innov, if.mean_tobins_q, if.mean_eq, if.var_eq, if.mean_cash_bal)
+  
+  influence_stack_ddw = do.call("rbind", mmmatlist_ddw)
+  gmmweights_ddw = solve(influence_stack_ddw %*% t(influence_stack_ddw)/n)
+
+
+
   if(is.null(fname)) {
     fname = "DEFAULT___"
   }
   ## write out the rawdata.csv and the GMM weighting matrix
   write.csv(dwl, paste(fname, "rawdata.csv", sep=""))
   writeRawCSV(gmmweights, paste(fname, "gmmweights.csv", sep=""))
-  
+  writeRawCSV(gmmweights_ddw, paste(fname, "_ddw_gmmweights.csv", sep=""))
+
   ## write out all of the moments that make this happen
   mf2 = data.frame(mean_inv,
     var_inv,

siman_solve/nm_solve_smmddw.c

 #define SOLVE_COMMAND		"solve_isC-icpc"
 
 /* Solve parameters */
-#define MODEL_VALUE_COUNT	10
+#define MODEL_VALUE_COUNT	8
 
 /*
  * Model value ranges -
   -10.0,	/* s 		*/
   -10.0,	/* lambda_1 	*/
   -10.0,	/* lambda_2 	*/
-  -10.0,	/* delta 	*/
-  -10.0,	/* epsilon_P	*/
+  /* -10.0, */	/* delta 	*/
+  /* -10.0,	/\* epsilon_P	*\/ */
   -10.0		/* theta	*/
 };
 
   10.0,		/* s		*/
   10.0,		/* lambda_1 	*/
   10.0,		/* lambda_2	*/
-  10.0,		/* delta 	*/
-  10.0,		/* epsilon_P	*/
+  /* 10.0,	 */	/* delta 	*/
+  /* 10.0,		/\* epsilon_P	*\/ */
   10.0		/* theta	*/
 };
 
   "s",		
   "lambda_1",	
   "lambda_2",	
-  "delta",	
-  "epsilon_P",
+  /* "delta",	 */
+  /* "epsilon_P", */
   "theta"
 };
 
 static char     *Momentlist = "Momentlist";
 static char     *Datamoments = "Datamoments";
 static char     *Gmmweightmatrix = "Gmmweightmatrix";
-static char     *DoSMM = "--do_smm_for_ddw --add_ddw='1'";
+static char     *DoSMM = "--do_smm_for_ddw --add_ddw='1' --delta='0.15' --epsilon_P='-4.0' ";
 int		 Iter;
 
 double	SolveEnergy(const gsl_vector *, void *);
       printf ("converged to minimum at\n");
     }
      
-    printf ("%5d %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e f() = %7.3f size = %.3f\n", 
+    printf ("%5d %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e   %10.3e f() = %7.3f size = %.3f\n", 
 	    Iter,
 	    gsl_vector_get(S->x, 0), 
 	    gsl_vector_get(S->x, 1), 
 	    gsl_vector_get(S->x, 5), 
 	    gsl_vector_get(S->x, 6), 
 	    gsl_vector_get(S->x, 7), 
-	    gsl_vector_get(S->x, 8), 
-	    gsl_vector_get(S->x, 9), 
 	    S->fval, Size);
   }
   while (Status == GSL_CONTINUE && Iter < 1000);
 
 #define EIGEN_USE_MKL_BLAS
 #define EIGEN_USE_MKL_LAPACKE
-#define NDEBUG
+//#define NDEBUG
 
 #ifndef PI
 #define PI 3.141592653589793
   string gmm_weight_matrix_path;
   string datamoments;
   bool do_smm_for_ddw;
+  bool log_gamma;
 };
 
 // THIS PRINTS A STUPID CSV FILE OF PARAMETERS
 	{"datamoments", 1, 0, 'D' },
 	{"do_smm_for_ddw", 0, 0 , 'W'},
 	{"verbose", 0, 0 , 'V'},
+	{"log_gamma", 0, 0 , 'G'},
         {0,0,0,0}
       };
 
 	    cout << "EXITING" << endl;
 	    exit(1);
 	  }
-	  assert(gmm_wmp_exists && rtp.gmm_weight_matrix_path + " DOES NOT EXIST");
+	  assert(gmm_wmp_exists);
 
 	  break;
 
 	  rtp.do_smm_for_ddw = true;
 	  break;
 
+        case 'G':
+	  rtp.log_gamma = true;
+	  break;
+
+
         case 'V':
 	  VERBOSE_MODE = true;
 	  break;
   rtp.smm_using_gmm_weights = false;
   rtp.gmm_weight_matrix_path = "";
   rtp.do_smm_for_ddw = false;
+  rtp.log_gamma = false;
 
   string fname  = "DEFAULT_FILENAME";
   bool OUTPUT   = false;
   // LET EPSILON_P actually be the log of epsilon_P. 
   // THUS, WE EXPONENTIATE IT 
   par.epsilon_P = exp(par.epsilon_P);
+  par.lambda_1 = exp(par.lambda_1);
+  par.lambda_2 = exp(par.lambda_2);
+
+  if(rtp.log_gamma) {
+    par.gamma = exp(par.gamma);
+  }
 
   // set some internal paramters
   const int z_support_pts = 9;
     // AT THIS POINT, WE HAVE A WEIGHT MATRIX
     MatrixXd ddw_smm_obj_mat = ddw_smm_g.transpose() * ddw_smm_weight_matrix * ddw_smm_g;
     cout << "Hey Dad:Energy=" << ddw_smm_obj_mat(0,0) << endl;
+    cout << "ddw_smm_g" << ddw_smm_g.rows() << "x" << ddw_smm_g.cols()  << endl;
+    cout << "ddw_smm_obj_mat" << ddw_smm_obj_mat.rows() << "x" << ddw_smm_obj_mat.cols()  << endl;
 
   } // end if rtp.do_smm