mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
class to inplement a set of lambda parameter and their stat score
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1642 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
parent
36b25323c9
commit
43ba7835bb
25
mert/Point.cpp
Normal file
25
mert/Point.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "Point.h"
|
||||
#include<cmath>
|
||||
|
||||
using namespace std;
|
||||
void Point::randomize(const vector<lambda>& min,const vector<lambda>& max){
|
||||
for (int i=0; i<size(); i++)
|
||||
operator[](i)= min[i] + (float)random()/RAND_MAX * (max[i]-min[i]);
|
||||
}
|
||||
|
||||
void Point::normalize(){
|
||||
lambda norm=0.0;
|
||||
for (int i=0; i<size(); i++)
|
||||
norm+= operator[](i)*operator[](i);
|
||||
if(norm!=0.0){
|
||||
norm=sqrt(norm);
|
||||
for (int i=0; i<size(); i++)
|
||||
operator[](i)/=norm;
|
||||
}
|
||||
}
|
||||
|
||||
double Point::operator*(FeatureStats& F)const{
|
||||
double prod=0.0;
|
||||
for (int i=0; i<size(); i++)
|
||||
prod+= operator[](i)*F.get(i);
|
||||
}
|
17
mert/Point.h
Normal file
17
mert/Point.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef POINT_H
|
||||
#define POINT_H
|
||||
#include <vector>
|
||||
#include "FeatureStats.h"
|
||||
typedef float lambda,statscore;
|
||||
|
||||
class Point: public std::vector<lambda>{
|
||||
public:
|
||||
statscore score;
|
||||
Point(unsigned s):std::vector<lambda>(s,0.0){};
|
||||
Point(vector<lambda> init):vector<lambda>(init),score(numeric_limits<statscore>::max()){};
|
||||
void randomize(const std::vector<lambda>&min,const std::vector<lambda>& max);
|
||||
double operator*(FeatureStats&)const;//compute the feature function
|
||||
void normalize();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user