本文整理汇总了C++中ParamVector::length方法的典型用法代码示例。如果您正苦于以下问题:C++ ParamVector::length方法的具体用法?C++ ParamVector::length怎么用?C++ ParamVector::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParamVector
的用法示例。
在下文中一共展示了ParamVector::length方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: func
double
PerplexityOptimizer::Optimize(ParamVector ¶ms, Optimization technique) {
_numCalls = 0;
ComputeEntropyFunc func(*this);
int numIter;
double minEntropy;
clock_t startTime = clock();
switch (technique) {
case PowellOptimization:
minEntropy = MinimizePowell(func, params, numIter);
break;
case LBFGSOptimization:
minEntropy = MinimizeLBFGS(func, params, numIter);
break;
case LBFGSBOptimization:
minEntropy = MinimizeLBFGSB(func, params, numIter);
break;
default:
throw std::runtime_error("Unsupported optimization technique.");
}
clock_t endTime = clock();
Logger::Log(1, "Iterations = %i\n", numIter);
Logger::Log(1, "Elapsed Time = %f\n",
float(endTime - startTime) / CLOCKS_PER_SEC);
Logger::Log(1, "Perplexity = %f\n", exp(minEntropy));
Logger::Log(1, "Num OOVs = %lu\n", _numOOV);
Logger::Log(1, "Num ZeroProbs = %lu\n", _numZeroProbs);
Logger::Log(1, "Func Evals = %lu\n", _numCalls);
Logger::Log(1, "OptParams = [ ");
for (size_t i = 0; i < params.length(); i++)
Logger::Log(1, "%f ", params[i]);
Logger::Log(1, "]\n");
return minEntropy;
}
示例2: exp
void
KneserNeySmoothing::_ComputeWeights(const ParamVector &featParams) {
_ngramWeights.set(0);
for (size_t f = 0; f < featParams.length(); ++f)
if (featParams[f] != 0)
_ngramWeights += _pLM->features(_order)[f] * featParams[f];
_ngramWeights = exp(_ngramWeights);
}
示例3: r
bool
KneserNeySmoothing::Estimate(const ParamVector ¶ms,
const NgramLMMask *pMask,
ProbVector &probs,
ProbVector &bows) {
// Unpack discount parameters.
if (_tuneParams) {
// Check of out-of-bounds discount parameters.
for (size_t i = 0; i < _discOrder; i++)
if (params[i] < 0 || params[i] > i+1) {
Logger::Log(2, "Clipping\n");
return false;
}
_discParams[Range(1, _discParams.length())] = params[Range(_discOrder)];
}
// Check of out-of-bounds n-gram weighting parameters.
size_t numDiscParams = _tuneParams ? _discOrder : 0;
for (size_t i = numDiscParams; i < params.length(); i++)
if (fabs(params[i] > 100)) {
Logger::Log(2, "Clipping\n");
return false;
}
// Compute n-gram weights and inverse history counts, if necessary.
size_t numFeatures = _pLM->features(_order).size();
if (numFeatures > 0) {
Range r(numDiscParams, numDiscParams + numFeatures);
_ComputeWeights(ParamVector(params[r]));
_invHistCounts.set(0);
BinWeight(_pLM->hists(_order), _effCounts * _ngramWeights,
_invHistCounts);
_invHistCounts = CondExpr(_invHistCounts == 0,
0, (Param)1 / _invHistCounts);
}
// Estimate probs and bows using optimized methods.
if (numFeatures > 0) {
if (pMask != NULL)
_EstimateWeightedMasked(pMask, probs, bows);
else
_EstimateWeighted(probs, bows);
} else {
if (pMask != NULL)
_EstimateMasked(pMask, probs, bows);
else
_Estimate(probs, bows);
}
return true;
}