void Feature:: createLam(int which, ECString tmp, ECString path) { ECString npath("/ltmp/discrim/FOLDS/"); int b,f; int tot = Feature::total[which]; for(int i = 0 ; i < 20 ; i++) { ECString ftstr(npath); ftstr += intToString(i) + "/"; ftstr += tmp; ftstr += ".lambdas"; ifstream fts(ftstr.c_str()); assert(fts); for(b = 1; b < 15 ; b++) { int bb; if(!fts) { cerr << "Trouble reading lambs for " << which << " in " << ftstr << endl; assert(fts); } fts >> bb ; //cerr << bb << endl; if(bb != b) { cerr << tmp << " " << b << " " << bb << endl; assert(bb == b); } for(f = 2; f <= tot ; f++) { float lam; assert(fts); fts >> lam; //cerr << which << " " << f << " " << b << " " << lam << endl; if(i == 0) Feature::setLambda(which,f,b,lam); else lamVal(which,f,b) += lam; } } } for(b = 1; b < 15 ; b++) for(f = 2; f <= tot ; f++) lamVal(which,f,b) /= 20.0; ECString ftstr(path); ftstr += tmp; ftstr += ".lambdas"; ofstream res(ftstr.c_str()); assert(res); res.precision(3); printLambdas(res); }
int main(int argc, char *argv[]) { struct rlimit core_limits; core_limits.rlim_cur = 0; core_limits.rlim_max = 0; setrlimit( RLIMIT_CORE, &core_limits ); ECArgs args( argc, argv ); assert(args.nargs() == 2); conditionedType = args.arg(0); cerr << "start trainRs: " << conditionedType << endl; ECString path( args.arg( 1 ) ); if(args.isset('L')) Feature::setLM(); Term::init(path); readHeadInfo(path); Pst pst(path); if(Feature::isLM) ClassRule::readCRules(path); addSubFeatureFns(); Feature::init(path, conditionedType); whichInt = Feature::whichInt; int ceFunInt = Feature::conditionedFeatureInt[Feature::whichInt]; Feature::conditionedEvent = SubFeature::Funs[ceFunInt]; Feat::Usage = PARSE; ECString ftstr(path); ftstr += conditionedType; ftstr += ".g"; ifstream fts(ftstr.c_str()); if(!fts) { cerr << "Could not find " << ftstr << endl; assert(fts); } tRoot = new FeatureTree(fts); //puts it in root; cout.precision(3); cerr.precision(3); lamInit(); InputTree* trainingData[1001]; int usedCount = 0; sentenceCount = 0; for( ; ; sentenceCount++) { if(sentenceCount%10000 == 1) { // cerr << conditionedType << ".tr " //<< sentenceCount << endl; } if(usedCount >= 1000) break; InputTree* correct = new InputTree; cin >> (*correct); if(correct->length() == 0) break; if(!cin) break; EcSPairs wtList; correct->make(wtList); InputTree* par; par = correct; trainingData[usedCount++] = par; } if(Feature::isLM) pickLogBases(trainingData,sentenceCount); procGSwitch = true; for(pass = 0 ; pass < 10 ; pass++) { if(pass%2 == 1) cout << "Pass " << pass << endl; goThroughSents(trainingData, sentenceCount); updateLambdas(); //printLambdas(cout); zeroData(); } ECString resS(path); resS += conditionedType; resS += ".lambdas"; ofstream res(resS.c_str()); res.precision(3); printLambdas(res); printLambdas(cout); cout << "Total params = " << FeatureTree::totParams << endl; cout << "Done: " << (int)sbrk(0) << endl; }