tEnd method

Future<num> tEnd(
  1. num gamma, {
  2. dynamic deltaPosition = const <num>[],
  3. int sampleSize = 200,
})

Returns the temperature at which the expectation value of the acceptance probability of up-hill transitions approaches gamma.

Note: The algorithm converges only for gamma in the range: 0 < gamma < 1.

Implementation

Future<num> tEnd(
  num gamma, {
  deltaPosition = const <num>[],
  int sampleSize = 200,
}) async {
  if (gamma <= 0 || gamma >= 1) {
    throw ErrorOf<EnergyField>(
        message: 'Error in function tEnd()',
        invalidState: 'Found \'gamma\': $gamma.',
        expectedState: 'Expected: 0 < gamma < 1.');
  }
  // Initial transition values.
  final e0 = _minValue;
  if (deltaPosition.isEmpty) {
    deltaPosition = size * 1e-6;
  }

  // Final transition values.
  final e1 = await sampleEnergyCloseTo(
    _minPosition,
    deltaPosition,
    sampleSize: sampleSize,
    selectUphillMoves: true,
  );

  /// First estimate for the initial temperature.
  var optTemperature = -e1.stdDev() / log(gamma);
  num gammaEstimate = 0;
  var counter = 0;
  //Rescaling energy
  for (var i = 0; i < e1.length; i++) {
    e1[i] -= e0;
  }
  do {
    gammaEstimate = _gammaEnd(e1, optTemperature);
    optTemperature = optTemperature *
        pow(
          log(gammaEstimate) / log(gamma),
          0.2,
        );
    ++counter;
    //print('gamma: $gammaEstimate temperature: $optTemperature');
  } while ((gammaEstimate - gamma).abs() > gamma * 1e-3 && counter < 100);
  return optTemperature;
}