2010-09-16 21:01:23 +04:00
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2010 University of Edinburgh
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library 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
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
|
|
|
|
2010-09-17 13:17:05 +04:00
|
|
|
#include "Optimiser.h"
|
2010-09-16 21:01:23 +04:00
|
|
|
|
|
|
|
using namespace Moses;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace Mira {
|
|
|
|
|
2011-04-15 15:34:51 +04:00
|
|
|
vector<int> Perceptron::updateWeightsAnalytically(ScoreComponentCollection& currWeights,
|
2011-05-09 13:39:57 +04:00
|
|
|
ScoreComponentCollection& featureValues,
|
2011-04-15 15:34:51 +04:00
|
|
|
float loss,
|
2011-05-09 13:39:57 +04:00
|
|
|
ScoreComponentCollection& oracleFeatureValues,
|
2011-04-15 15:34:51 +04:00
|
|
|
float oracleBleuScore,
|
|
|
|
size_t sentenceId,
|
|
|
|
float learning_rate,
|
|
|
|
float max_sentence_update,
|
|
|
|
size_t rank,
|
|
|
|
size_t epoch,
|
|
|
|
bool controlUpdates) {
|
|
|
|
vector<int> status(1);
|
|
|
|
status[0] = 0;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2011-04-11 02:07:41 +04:00
|
|
|
vector<int> Perceptron::updateWeights(ScoreComponentCollection& currWeights,
|
2010-12-06 22:32:59 +03:00
|
|
|
const vector< vector<ScoreComponentCollection> >& featureValues,
|
|
|
|
const vector< vector<float> >& losses,
|
2010-12-10 19:34:43 +03:00
|
|
|
const vector< vector<float> >& bleuScores,
|
2010-12-09 14:49:52 +03:00
|
|
|
const vector< ScoreComponentCollection>& oracleFeatureValues,
|
2010-12-10 19:34:43 +03:00
|
|
|
const vector< float> oracleBleuScores,
|
2011-03-08 19:58:02 +03:00
|
|
|
const vector< size_t> dummy,
|
|
|
|
float learning_rate,
|
2011-03-22 20:17:43 +03:00
|
|
|
float max_sentence_update,
|
2011-03-23 15:13:38 +03:00
|
|
|
size_t rank,
|
2011-04-11 16:22:19 +04:00
|
|
|
size_t epoch,
|
2011-04-08 16:45:01 +04:00
|
|
|
int updates_per_epoch,
|
|
|
|
bool controlUpdates)
|
2010-09-16 21:01:23 +04:00
|
|
|
{
|
2010-12-06 22:32:59 +03:00
|
|
|
for (size_t i = 0; i < featureValues.size(); ++i) {
|
|
|
|
for (size_t j = 0; j < featureValues[i].size(); ++j) {
|
2010-10-25 16:22:35 +04:00
|
|
|
if (losses[i][j] > 0) {
|
2010-12-06 22:32:59 +03:00
|
|
|
currWeights.MinusEquals(featureValues[i][j]);
|
|
|
|
currWeights.PlusEquals(oracleFeatureValues[i]);
|
2010-10-25 16:22:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-06 22:32:59 +03:00
|
|
|
|
2011-04-11 02:07:41 +04:00
|
|
|
vector<int> status(1);
|
|
|
|
status[0] = 0;
|
|
|
|
return status;
|
2010-09-16 21:01:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|