TensorDistribution<T>.fitScalarsIndependently constructor Null safety

TensorDistribution<T>.fitScalarsIndependently(
  1. Iterable<Tensor<double>> iterable,
  2. Distribution<T> scalarFitter(
    1. Iterable<double> iterable
    )
)

Constructs a distribution by fitting a distribution to each index independently.

Implementation

factory TensorDistribution.fitScalarsIndependently(
  Iterable<Tensor<double>> iterable,
  Distribution<T> Function(Iterable<double> iterable) scalarFitter,
) {
  final shape = iterable.first.tensorShape;
  assert(iterable.skip(1).every((element) => element.tensorShape == shape));
  return TensorDistribution.generate(shape, (shape, index) {
    return scalarFitter(iterable.map((e) => e.elements[index]));
  });
}