perturb method
Returns a random vector of length dimensions
sampled from the interval
obtained by intersecting this
with the generalized rectangle
centred at position
with edge lengths
(position - deltaPosition, position + deltaPosition)
.
Note: If the intersection along a certain interval is empty then the corrsponding coordinate is set to double.nan.
Throws an error of type ErrorOf<SearchSpace>
if the
length of the position
or deltaPosition
does not match dimensions.
Implementation
List<num> perturb(List<num> position, List<num> deltaPosition) {
_updateCache();
try {
if (hasCustomOrder) {
final result = List<num>.filled(dimensions, 0.0);
for (var i in order) {
result[i] = _intervals[i].perturb(position[i], deltaPosition[i]);
}
return result;
} else {
return List<num>.generate(dimensions,
(i) => _intervals[i].perturb(position[i], deltaPosition[i]));
}
} on RangeError catch (_) {
if (position.length != dimensions) {
throw ErrorOf<SearchSpace>(
message: 'Could not generate random point around $position.',
invalidState:
'Dimension mismatch: $dimensions != ${position.length}.',
expectedState: 'The vector position must have length $dimensions.');
}
if (deltaPosition.length != dimensions) {
throw ErrorOf<SearchSpace>(
message:
'Could not generate perturbation using magnitudes $deltaPosition.',
invalidState:
'Dimension mismatch: $dimensions != ${deltaPosition.length}.',
expectedState:
'The vector deltaPosition must have length $dimensions.');
}
rethrow;
}
}