Changeset 7433
 Timestamp:
 04/24/12 11:17:26 (4 years ago)
 Location:
 scolib/trunk/src
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

scolib/trunk/src/libs/TGPO.cpp
r7297 r7433 81 81 82 82 TGPO::TGPO() 83 {} 83 : LHS_sample_size(utilib::Property::Bind<int>(0)) 84 { 85 properties.declare 86 ("LHS_sample_size", 87 "The number of points to use for the initial LHS sample " 88 "(default: 0 [number of variables])", 89 LHS_sample_size); 90 } 84 91 85 92 void TGPO::optimize() … … 100 107 Reval(install("library"), install("tgp")); 101 108 102 // Run LHS and print out the points 109 int num_var = problem>num_real_vars; 110 int partitions = LHS_sample_size; 111 if ( partitions <= 0 ) 112 partitions = num_var; 113 114 // Run LHS to generate initial samples 103 115 SEXP lhs_points; 104 116 PROTECT( lhs_points = 105 Reval( install("improvedLHS"), ScalarInteger(4), 106 ScalarInteger(2), make_pair("dup",ScalarInteger(1)) ) ); 107 for (size_t i = 0; i < 8; ++i) 108 std::cerr << " > " << i << " = " << REAL(lhs_points)[i] << std::endl; 117 Reval( install("improvedLHS"), 118 ScalarInteger(partitions), 119 ScalarInteger(num_var), 120 make_pair("dup",ScalarInteger(1)) ) ); 121 // NB: improvedLHS returns N samples (partitions) of K variables in 122 // an N x K matrix (rowmajor, K rows, N columns) 123 std::vector<std::vector<double> > domain_pts(num_var); 124 std::vector<double> response_pts(partitions); 125 for (size_t i = 0; i < partitions; ++i) 126 { 127 domain_pts[i].resize(num_var); 128 for (size_t j = 0; j < num_var; ++j) 129 domain_pts[i][j] = REAL(lhs_points)[i+j*partitions]; 130 problem>AsyncEvalF(eval_mngr(), domain_pts[i], response_pts[i]); 131 } 109 132 UNPROTECT(1); 110 133 134 // Wait for LHS sample evaluations 135 eval_mngr().synchronize(); 136 111 137 Rf_endEmbeddedR(0); 112 138 } … … 118 144 } // namespace scolib 119 145 120 #else // if ACRO_HAVE_R 146 147 #else // (not) if ACRO_HAVE_R 148 // 149 // Stub in a nonfunctional (and nonregistered) TGPO class. 150 // 121 151 122 152 namespace scolib { … … 133 163 } // namespace scolib 134 164 135 #endif // elseACRO_HAVE_R165 #endif // if ACRO_HAVE_R 
scolib/trunk/src/scolib/TGPO.h
r7296 r7433 33 33 void optimize(); 34 34 35 /// The number of points to use for the initial LHS sample 36 utilib::Property LHS_sample_size; 37 35 38 protected: 36 39 std::string define_solver_type() const
Note: See TracChangeset
for help on using the changeset viewer.