evaluate method

  1. @override
List<double> evaluate(
  1. List<double> inputs
)
override

Implementation

@override
List<double> evaluate(List<double> inputs) {
  if (functions.isEmpty) return const <double>[0];
  final double low = domain.isNotEmpty ? domain[0] : 0;
  final double high = domain.length > 1 ? domain[1] : 1;
  final double t = UPdfFunction._clamp(inputs.isEmpty ? 0 : inputs.first, low, high);
  int index = 0;
  while (index < bounds.length && t >= bounds[index]) {
    index++;
  }
  if (index >= functions.length) index = functions.length - 1;
  final double segmentLow = index == 0 ? low : bounds[index - 1];
  final double segmentHigh = index >= bounds.length ? high : bounds[index];
  final double encodeLow = index * 2 < encode.length ? encode[index * 2] : 0;
  final double encodeHigh = index * 2 + 1 < encode.length ? encode[index * 2 + 1] : 1;
  final double span = segmentHigh - segmentLow;
  final double mapped = span == 0 ? encodeLow : encodeLow + (t - segmentLow) * (encodeHigh - encodeLow) / span;
  return functions[index].evaluate(<double>[mapped]);
}