Esempio n. 1
0
FValue inner_product(const FVector& lhs, const FVector& rhs)
{
  if (lhs.size() >= rhs.size()) {
    return rhs.inner_product(lhs);
  } else {
    return lhs.inner_product(rhs);
  }
}
Esempio n. 2
0
void IOWrapper::OutputSparseFeatureScores( std::ostream& out, const ChartTrellisPath &path, const FeatureFunction *ff, std::string &lastName )
{
  const StaticData &staticData = StaticData::Instance();
  bool labeledOutput = staticData.IsLabeledNBestList();
  const FVector scores = path.GetScoreBreakdown().GetVectorForProducer( ff );

  // report weighted aggregate
  if (! ff->GetSparseFeatureReporting()) {
  	const FVector &weights = staticData.GetAllWeights().GetScoresVector();
  	if (labeledOutput && !boost::contains(ff->GetScoreProducerDescription(), ":"))
  		out << " " << ff->GetScoreProducerWeightShortName() << ":";
    out << " " << scores.inner_product(weights);
  }

  // report each feature
  else {
  	for(FVector::FNVmap::const_iterator i = scores.cbegin(); i != scores.cend(); i++) {
  		if (i->second != 0) { // do not report zero-valued features
  			if (labeledOutput)
  				out << " " << i->first << ":";
        out << " " << i->second;
      }
    }
  }
}
Esempio n. 3
0
void OutputFeatureScores( std::ostream& out, const TrellisPath &path, const FeatureFunction *ff, std::string &lastName )
{
  const StaticData &staticData = StaticData::Instance();
  bool labeledOutput = staticData.IsLabeledNBestList();

  // regular features (not sparse)
  if (ff->GetNumScoreComponents() != ScoreProducer::unlimited) {
    if( labeledOutput && lastName != ff->GetScoreProducerWeightShortName() ) {
      lastName = ff->GetScoreProducerWeightShortName();
      out << " " << lastName << ":";
    }
    vector<float> scores = path.GetScoreBreakdown().GetScoresForProducer( ff );
    for (size_t j = 0; j<scores.size(); ++j) {
      out << " " << scores[j];
    }
  }

  // sparse features
  else {
    const FVector scores = path.GetScoreBreakdown().GetVectorForProducer( ff );

    // report weighted aggregate
    if (! ff->GetSparseFeatureReporting()) {
      const FVector &weights = staticData.GetAllWeights().GetScoresVector();
      if (labeledOutput && !boost::contains(ff->GetScoreProducerDescription(), ":"))
        out << " " << ff->GetScoreProducerWeightShortName() << ":";
      out << " " << scores.inner_product(weights);
    }

    // report each feature
    else {
      for(FVector::FNVmap::const_iterator i = scores.cbegin(); i != scores.cend(); i++) 
	out << " " << i->first << ": " << i->second;
	/*        if (i->second != 0) { // do not report zero-valued features
	  float weight = staticData.GetSparseWeight(i->first);
          if (weight != 0)
	  out << " " << i->first << "=" << weight;
	  }*/
    }
  }
}