StepRegressor constructor

StepRegressor(
  1. String name,
  2. List<double> knots,
  3. List<double> values, {
  4. double before = 0,
})

A column named name that takes values[i] from knots[i] until the next knot, and before (default zero) before the first.

knots must be sorted ascending and the same length as values, and both finite. Both lists are copied.

Implementation

StepRegressor(
  this.name,
  List<double> knots,
  List<double> values, {
  this.before = 0,
}) : _knots = Float64List.fromList(knots),
     _values = Float64List.fromList(values) {
  if (knots.length != values.length) {
    throw ArgumentError(
      'there are ${knots.length} knots and '
      '${values.length} values; they must correspond one to one',
    );
  }
  for (var i = 0; i < knots.length; i++) {
    if (!knots[i].isFinite) {
      throw ArgumentError.value(knots[i], 'knots[$i]', 'not finite');
    }
    if (!values[i].isFinite) {
      throw ArgumentError.value(values[i], 'values[$i]', 'not finite');
    }
    if (i > 0 && knots[i] < knots[i - 1]) {
      throw ArgumentError(
        'knots must be sorted ascending, but knots[$i] '
        '(${knots[i]}) precedes knots[${i - 1}] (${knots[i - 1]})',
      );
    }
  }
}