30 #define LINFO(x) std::cerr << "INFO:: " << x << std::endl; 33 #define LDEBUG(x) std::cerr << "DEBUG:: " << x << std::endl; 37 #define LERROR(x) std::cerr << "ERROR:: " << x << std::endl; 40 #define LWARN(x) std::cerr << "WARNING:: " << x << std::endl; 53 std::vector<T> result;
54 std::stringstream strm ( std::stringstream::in | std::stringstream::out );
55 if ( pos ) strm << stringparams.substr ( pos ) << std::noskipws;
56 else strm << stringparams << std::noskipws;
58 while ( strm.good() ) {
59 if ( result.size() > 0 ) {
64 result.push_back ( w );
66 if ( strm.fail() || strm.bad() || strm.fail() ) {
67 LERROR(
"Unable to parse params : " << stringparams.substr ( pos ) );
68 for (
unsigned k = 0; k < result.size(); ++k )
69 std::cerr << result[k] << std::endl;
70 exit ( EXIT_FAILURE );
78 , std::vector<T>& params
82 stringstream strm ( stringstream::in | stringstream::out );
85 strm << stringparams.substr ( pos , span) << noskipws;
86 LDEBUG(
"Passing in: [" << strm.str() <<
"]");
87 }
else strm << stringparams.substr ( pos ) << noskipws;
88 else strm << stringparams << noskipws;
90 span = strm.str().size();
92 while ( strm.good() ) {
93 if ( params.size() > 0 ) {
98 params.push_back ( w );
100 if ( strm.fail() || strm.bad() ) {
101 LERROR(
"Unable to parse params : " << stringparams.substr ( pos , span) );
102 for (
unsigned k = 0; k < params.size(); ++k )
103 cerr << params[k] << endl;
104 exit ( EXIT_FAILURE );
111 inline void WriteParamFile(
const std::string& filename, std::vector<float> params_) {
112 std::ofstream ofs ( filename.c_str() );
114 LERROR(
"Can't write to " << filename);
115 exit ( EXIT_FAILURE );
117 LINFO(
"Writing final Lambda to " << filename );
118 float ev = params_.back();
120 for (
size_t i=0; i<params_.size(); i++) {
121 ofs << params_[i] <<
",";
123 ofs << ev << std::endl;
135 std::string stringparams;
136 char *paramsfile = getenv (
"TUPLEARC_WEIGHT_VECTOR_FILE" );
138 std::ifstream ifs ( paramsfile );
140 LERROR(
"Unable to open file " << paramsfile );
141 exit ( EXIT_FAILURE);
145 char * pParams = getenv (
"TUPLEARC_WEIGHT_VECTOR" );
147 LWARN(
"Cannot find parameter vector. Defaulting to flat parameters");
150 stringparams = pParams;
152 params = ParseParamString<T> ( stringparams );
154 std::stringstream ss;
155 for (
typename std::vector<T>::const_iterator it = params.begin();
156 it != params.end(); ++it ) {
159 std::cerr <<
"Setting params to: " << ss.str() << endl;
Initializes a set of parameters from environment variables PARAMS_FILE or PARAMS. ...
std::vector< T > ParseParamString(const std::string &stringparams, size_t pos=0)
Function to parse string of parameters, e.g. separated by commas.
void WriteParamFile(const std::string &filename, std::vector< float > params_)
Write parameter vector to a file, with comma separators.
iszfstream & getline(iszfstream &izs, std::string &line)