diff options
| author | linh.kitty <linh.kitty@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-16 17:44:44 +0000 | 
|---|---|---|
| committer | linh.kitty <linh.kitty@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-16 17:44:44 +0000 | 
| commit | fe67163cec1cc80e55c490e80070047239c1120d (patch) | |
| tree | 0a5bde8f32ac6c1d1a2e79b368cf6cb1db129a4c /gi/scfg/abc/agrammar.h | |
| parent | 26111abd81573b1460bcb9aad5dc91a6f7fb9770 (diff) | |
add
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@286 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'gi/scfg/abc/agrammar.h')
| -rw-r--r-- | gi/scfg/abc/agrammar.h | 54 | 
1 files changed, 51 insertions, 3 deletions
| diff --git a/gi/scfg/abc/agrammar.h b/gi/scfg/abc/agrammar.h index 8a7186bf..0a8a60ac 100644 --- a/gi/scfg/abc/agrammar.h +++ b/gi/scfg/abc/agrammar.h @@ -2,10 +2,39 @@  #define AGRAMMAR_H_  #include "grammar.h" +#include "hg.h"  using namespace std; +class aTRule: public TRule{ + public: + aTRuleTRule : TRule(){ResetScore(0.00000001); } +  aTRule(TRulePtr rule_); + +  void ResetScore(double initscore){//cerr<<"Reset Score "<<this->AsString()<<endl; +    sum_scores_.set_value(FD::Convert("Prob"), initscore);} +  void AddProb(double p ){ +    //    cerr<<"in AddProb p="<<p<<endl; +    //    cerr<<"prob sumscores ="<<sum_scores_[FD::Convert("Prob")]<<endl; +    sum_scores_.add_value(FD::Convert("Prob"), p); +    //    cerr<<"after AddProb\n"; +  } + +  void UpdateScore(double sumprob){ +    double minuslogp = 0 - log( sum_scores_.value(FD::Convert("Prob")) /sumprob); +    if (sumprob<  sum_scores_.value(FD::Convert("Prob"))){ +      cerr<<"UpdateScore sumprob="<<sumprob<< "  sum_scores_.value(FD::Convert(\"Prob\"))="<< sum_scores_.value(FD::Convert("Prob"))<< this->AsString()<<endl; +      exit(1); +    } +    this->scores_.set_value(FD::Convert("MinusLogP"), minuslogp); + +  } + private: +  SparseVector<double> sum_scores_; +}; + +  class aTGImpl;  struct NTRule{ @@ -20,17 +49,19 @@ struct NTRule{      for (int i=0; i< rule->f().size(); i++)        if (rule->f().at(i) * -1 == nt)  	ntPos_.push_back(i); + +    }    TRulePtr rule_; -  WordID nt_; //the labelID of the nt (WordID>0); +  WordID nt_; //the labelID of the nt (nt_>0);    vector<int> ntPos_; //position of nt_ -1: lhs, from 0...f_.size() for nt of f_()    //i.e the rules is: NP-> DET NP; if nt_=5 is the labelID of NP then ntPos_ = (-1, 1): the indexes of nonterminal NP -    }; +  struct aTextGrammar : public Grammar {    aTextGrammar();    aTextGrammar(const std::string& file); @@ -46,9 +77,20 @@ struct aTextGrammar : public Grammar {    void setMaxSplit(int max_split);    void splitNonterminal(WordID wordID); -  void PrintAllRules() const; + +  void splitAllNonterminals(); + +  void PrintAllRules(const string & filename) const;    void PrintNonterminalRules(WordID nt) const;    void SetGoalNT(const string & goal_str); + +  void ResetScore(); + +  void UpdateScore(); + +  void UpdateHgProsteriorProb(Hypergraph & hg); + +  void set_alpha(double alpha){alpha_ = alpha;}   private:    void RemoveRule(const TRulePtr & rule); @@ -57,9 +99,15 @@ struct aTextGrammar : public Grammar {    int max_span_;    int max_split_;    boost::shared_ptr<aTGImpl> pimpl_; +    map <WordID, vector<TRulePtr> > lhs_rules_;// WordID >0    map <WordID, vector<NTRule> > nt_rules_;  +  map <WordID, double> sum_probs_; +  map <WordID, double> cnt_rules; + +  double alpha_; +    //  map<WordID, vector<WordID> > grSplitNonterminals;    WordID goalID;  }; | 
