transitions method
Returns a list containing the energy values at two
positions separated at most by deltaPosition
.
- The lower energy state is listed first.
- Throws an exception of type
ExceptionOf<EnergyField>
if no transition could be generated inmaxTrials
trials.
Implementation
List<List<num>> transitions(
List<num> deltaPosition, {
int sampleSize = 100,
int maxTrials = 20,
}) {
maxTrials = maxTrials < 1 ? 10 : maxTrials;
final result = <List<num>>[[], []];
var count = 0;
num state0 = 0;
num state1 = 0;
for (var i = 0; i < sampleSize; i++) {
count = 0;
do {
++count;
state0 = next();
state1 = perturb(position, deltaPosition);
} while (state0 == state1 && count < maxTrials);
if (count > maxTrials) {
throw ExceptionOf<EnergyField>(
message: 'Error in function \'transitions($deltaPosition).\'',
invalidState: 'Could not generate an uphill transition. '
'in $maxTrials trials.',
expectedState: 'A non-constant energy function.');
} else {
if (state0 < state1) {
result.first.add(state0);
result.last.add(state1);
} else {
result.first.add(state1);
result.last.add(state0);
}
}
}
return result;
}