sampleEnergyCloseTo method

Future<List<num>> sampleEnergyCloseTo(
  1. List<num> position,
  2. List<num> deltaPosition, {
  3. int sampleSize = 100,
  4. bool selectUphillMoves = false,
})

Returns a list of energy values sampled from a neighbourhood around position using perturbation magnitudes deltaPosition.

  • sampleSize: The length of the returned list containing the sample.
  • selectUphillMoves: Set to true to filter out down-hill transitions ( where the new energy value is lower than the energy at position).

Implementation

Future<List<num>> sampleEnergyCloseTo(
  List<num> position,
  List<num> deltaPosition, {
  int sampleSize = 100,
  bool selectUphillMoves = false,
}) async {
  if (selectUphillMoves) {
    var i = 0;
    var counter = 0;
    var eMin = energy(position);
    final result = <num>[];
    do {
      if (eMin < perturb(position, deltaPosition)) {
        result.add(value);
        ++i;
      } else {
        ++counter;
      }
    } while (i < sampleSize && counter < 50 * sampleSize);
    if (result.length < sampleSize) {
      throw ExceptionOf<EnergyField>(
          message: 'Error in function \'sampleCloseTo\'',
          invalidState: 'Could not generate $sampleSize uphill transitions '
              'with initial position: $position and energy: $eMin. ');
    }
    return result;
  } else {
    return List<num>.generate(
        sampleSize,
        (_) => perturb(
              position,
              deltaPosition,
            ));
  }
}