#include /* YASMET 1.0 toolkit Copyright (C) 2002 Franz Josef Och */ #include /* This program is free software; you can redistribute */ #include /* it and/or modify it under the terms of the GNU General */ #include /* Public License. */ #include /* This program is distributed WITHOUT ANY WARRANTY */ typedef double D;typedef pair fea;typedef vector vfea;size_t v=0; using namespace std; template ostream &operator<<(ostream&out,const vector&x){ copy(x.begin(),x.end(),ostream_iterator(out," "));return out<()(s.c_str());}}; struct event {vector Ny;size_t y;vector f;vector fs; vector&computeProb(const vector&z,vector&pr)const { vector::iterator p=pr.begin(),pb=pr.begin(),pe=pr.end(); for(vector::const_iterator fi=f.begin();fi!=f.end();++fi,++p){*p=0.0; for(vfea::const_iterator j=fi->begin();j!=fi->end();++j) *p+=z[j->first].l*j->second;} transform(pb,pe,pb,bind2nd(plus(),-*max_element(pb,pe))); transform(pb,pe,pb,exp); transform(pb,pe,pb,bind2nd(divides(),accumulate(pb,pe,0.0))); return pr;}}; int main(int argc,char**av){string s; vector >E;bool lN=0;D TRN=0.0,TST=0.0;bool qt=0,initmu=0; vector > s2f;vector z;ifstream *muf=0;int mfc=-2,kfl=0; size_t st=0,C=0,it=0,maxIt=1000,ts=0,noF=0,Es,I,N=100000000;D ssi=0.0; D d,l=1e30,old_l,w=0.0,dSmoothN=0.0,minBetter=0.01,lt=0.0,wt=0.0,F=0.0; for(int i=1;i f2s;event e;size_t curY=0;double wi=1.0; s2f.push_back(pair("@@@CORRECTIVE-FEATURE@@@",0.0)); z.push_back(Z());f2s["@@@CORRECTIVE-FEATURE@@@"]=0; if(muf){ while(*muf>>s>>d){size_t p=(!f2s.count(s))?(f2s[s]=s2f.size()):(f2s[s]); Z k(0,kfl?1:d,0);pair sd(s,0.0); if(p>s)switch(st){ case 0: C=atoi(s.c_str());st=1;break; case 1: if(s=="TEST"){N=E.size();}else{e.f.resize(C);e.fs.resize(C); e.y=atoi(s.c_str());curY=0;st=2;wi=1.0;e.Ny.resize(C); for(size_t c=0;c>t;fc=atof(t.c_str());} if(st==4&&s=="@"){e.Ny[curY]=fc;} else{if(!f2s.count(s)){ if((muf&&kfl==0)||E.size()>=N||kfl==2) {if(v>1)cerr<<"new "< p(C);assert(z.size()==1||z.size()==I);z.resize(I); if(initmu==0&&muf&&kfl!=2){N=0;ts=E.size();} for(size_t n=0;nmfc) cout<1)cerr << "Expected feature counts: " << z; do{old_l=l;l=0.0;w=0.0;lt=0.0;wt=0.0;double wx=0.0,wtx=0.0,lx=0,ltx=0; for(size_t i=0;i::const_iterator me=max_element(p.begin(),p.end()); if(!N){cout<first].q+=pj*k->second;}} ((i1e-10;++iter,dl-=ddl) {double h=x.q*exp(dl*F);ddl=(h+(x.l+dl)*ssi-x.k)/(h*F+ssi);} x.l+=dl;}} if(v>1)cerr<minBetter&&it++