示例#1
0
inline typename McSimulation<MC,RNG,S>::result_type
McSimulation<MC,RNG,S>::value(Real tolerance,
                              Size maxSamples,
                              Size minSamples) const {
    Size sampleNumber =
        mcModel_->sampleAccumulator().samples();
    if (sampleNumber<minSamples) {
        mcModel_->addSamples(minSamples-sampleNumber);
        sampleNumber = mcModel_->sampleAccumulator().samples();
    }

    Size nextBatch;
    Real order;
    result_type error(mcModel_->sampleAccumulator().errorEstimate());
    while (maxError(error) > tolerance) {
        QL_REQUIRE(sampleNumber<maxSamples,
                   "max number of samples (" << maxSamples
                   << ") reached, while error (" << error
                   << ") is still above tolerance (" << tolerance << ")");

        // conservative estimate of how many samples are needed
        order = maxError(error*error)/tolerance/tolerance;
        nextBatch =
            Size(std::max<Real>(static_cast<Real>(sampleNumber)*order*0.8 - static_cast<Real>(sampleNumber),
                                static_cast<Real>(minSamples)));

        // do not exceed maxSamples
        nextBatch = std::min(nextBatch, maxSamples-sampleNumber);
        sampleNumber += nextBatch;
        mcModel_->addSamples(nextBatch);
        error = result_type(mcModel_->sampleAccumulator().errorEstimate());
    }

    return result_type(mcModel_->sampleAccumulator().mean());
}
示例#2
0
// ##### getErrorComb() ##############################################
AxIndex ScanLine::getErrorComb(AxComb testAxComb) {
  NodeIndex testError= getErrorCombVec(testAxComb);
  return maxError(testError);
}
示例#3
0
// ##### getError() ##################################################
AxIndex ScanLine::getError(Axis testAx) {
  NodeIndex testError= getErrorVec(testAx);

  return maxError(testError);
}