Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mgiza.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mgizapp/src/transpair_model4.cpp')
-rw-r--r--mgizapp/src/transpair_model4.cpp92
1 files changed, 41 insertions, 51 deletions
diff --git a/mgizapp/src/transpair_model4.cpp b/mgizapp/src/transpair_model4.cpp
index ebc2666..93f5b6f 100644
--- a/mgizapp/src/transpair_model4.cpp
+++ b/mgizapp/src/transpair_model4.cpp
@@ -9,14 +9,14 @@ modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-This program is distributed in the hope that it will be useful,
+This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
*/
@@ -38,7 +38,7 @@ LogProb transpair_model4::_scoreOfMove(const alignment&a, WordIndex new_i, WordI
else
return 1.0;
}
-LogProb transpair_model4::_scoreOfSwap(const alignment&a, WordIndex j1, WordIndex j2,double)const
+LogProb transpair_model4::_scoreOfSwap(const alignment&a, WordIndex j1, WordIndex j2,double)const
{
LogProb a_prob=prob_of_target_and_alignment_given_source(a);
alignment b(a);
@@ -71,7 +71,7 @@ LogProb transpair_model4::scoreOfMove(const alignment&a, WordIndex new_i, WordIn
return change;
}
//increasing efficiency: no copy of alignment (calc. everything incrementally)
-LogProb transpair_model4::scoreOfSwap(const alignment&a, WordIndex j1, WordIndex j2,double thisValue)const
+LogProb transpair_model4::scoreOfSwap(const alignment&a, WordIndex j1, WordIndex j2,double thisValue)const
{
WordIndex aj1=a(j1),aj2=a(j2);
if( aj1==aj2 )
@@ -105,47 +105,40 @@ LogProb transpair_model4::prob_of_target_and_alignment_given_source_1(const alig
for (WordIndex i = 1 ; i <= al.fert(0) ; i++)
total *= double(m - al.fert(0) - i + 1) / (double(DeficientDistortionForEmptyWord?(max(2,int(m))/DeficientDistortionForEmptyWord):i)) ;
if( verb) cerr << "IBM-4: +NULL:binomial+distortion " << total << endl;
- for (WordIndex i = 1 ; i <= l ; i++)
- {
- total *= get_fertility(i, al.fert(i));// * (LogProb) factorial(al.fert(i));
- if( verb) cerr << "IBM-4: fertility of " << i << " " << get_fertility(i, al.fert(i)) << " -> " << total << endl;
- }
- for (WordIndex j = 1 ; j <= m ; j++)
- {
- total*= get_t(al(j), j) ;
- if( verb) cerr << "IBM-4: t of j:" << j << " i:" << al(j) << ": " << get_t(al(j), j) << " -> " << total << endl;
- }
+ for (WordIndex i = 1 ; i <= l ; i++) {
+ total *= get_fertility(i, al.fert(i));// * (LogProb) factorial(al.fert(i));
+ if( verb) cerr << "IBM-4: fertility of " << i << " " << get_fertility(i, al.fert(i)) << " -> " << total << endl;
+ }
+ for (WordIndex j = 1 ; j <= m ; j++) {
+ total*= get_t(al(j), j) ;
+ if( verb) cerr << "IBM-4: t of j:" << j << " i:" << al(j) << ": " << get_t(al(j), j) << " -> " << total << endl;
+ }
return total;
}
LogProb transpair_model4::prob_of_target_and_alignment_given_source(const alignment&al, short distortionType,bool verb)const
{
LogProb total = 1.0 ;
- static const LogProb almostZero = 1E-299 ;
- if( distortionType&1 )
- {
- total *= prob_of_target_and_alignment_given_source_1(al,verb);
- }
- if( distortionType&2 )
- {
- for(WordIndex j=1;j<=m;j++)
- if( al(j) )
- if( al.get_head(al(j))==j)
- {
- int ep=al.prev_cept(al(j));
- float x2=probFirst[ep](j,al.get_center(ep));
- massert(x2<=1.0);
- total*=x2;
- if( verb) cerr << "IBM-4: d=1 of " << j << ": " << x2 << " -> " << total << endl;
- }
- else
- {
- float x2=probSecond(j,al.prev_in_cept(j));
- massert(x2<=1.0);
- total*=x2;
- if( verb) cerr << "IBM-4: d>1 of " << j << ": " << x2 << " -> " << total << endl;
- }
- }
+ static const LogProb almostZero = 1E-299 ;
+ if( distortionType&1 ) {
+ total *= prob_of_target_and_alignment_given_source_1(al,verb);
+ }
+ if( distortionType&2 ) {
+ for(WordIndex j=1; j<=m; j++)
+ if( al(j) )
+ if( al.get_head(al(j))==j) {
+ int ep=al.prev_cept(al(j));
+ float x2=probFirst[ep](j,al.get_center(ep));
+ massert(x2<=1.0);
+ total*=x2;
+ if( verb) cerr << "IBM-4: d=1 of " << j << ": " << x2 << " -> " << total << endl;
+ } else {
+ float x2=probSecond(j,al.prev_in_cept(j));
+ massert(x2<=1.0);
+ total*=x2;
+ if( verb) cerr << "IBM-4: d>1 of " << j << ": " << x2 << " -> " << total << endl;
+ }
+ }
return total?total:almostZero;
}
@@ -159,19 +152,16 @@ void transpair_model4::computeScores(const alignment&al,vector<double>&d)const
total2 *= get_fertility(i, al.fert(i));// * (LogProb) factorial(al.fert(i));
for (WordIndex j = 1 ; j <= m ; j++)
total3*= get_t(al(j), j) ;
- for(WordIndex j=1;j<=m;j++)
+ for(WordIndex j=1; j<=m; j++)
if( al(j) )
- if( al.get_head(al(j))==j)
- {
- int ep=al.prev_cept(al(j));
- float x2=probFirst[ep](j,al.get_center(ep));
- total4*=x2;
- }
- else
- {
- float x2=probSecond(j,al.prev_in_cept(j));
- total4*=x2;
- }
+ if( al.get_head(al(j))==j) {
+ int ep=al.prev_cept(al(j));
+ float x2=probFirst[ep](j,al.get_center(ep));
+ total4*=x2;
+ } else {
+ float x2=probSecond(j,al.prev_in_cept(j));
+ total4*=x2;
+ }
d.push_back(total1);//9
d.push_back(total2);//10
d.push_back(total3);//11