pub struct Grid<A: Ord> { /* private fields */ }
Expand description

A Grid is a partition of a rectangular region of an n-dimensional space—e.g. [a0, b0) × ⋯ × [an−1, bn−1)—into a collection of rectangular n-dimensional bins.

The grid is fully determined by its 1-dimensional projections on the coordinate axes. For example, this is a partition that can be represented as a Grid struct:

+---+-------+-+
|   |       | |
+---+-------+-+
|   |       | |
|   |       | |
|   |       | |
|   |       | |
+---+-------+-+

while the next one can’t:

+---+-------+-+
|   |       | |
|   +-------+-+
|   |         |
|   |         |
|   |         |
|   |         |
+---+-------+-+

Example:

extern crate ndarray_stats;
extern crate ndarray;
extern crate noisy_float;
use ndarray::{Array, array};
use ndarray_stats::{HistogramExt,
                    histogram::{Histogram, Grid, GridBuilder,
                                Edges, Bins, strategies::Auto}};
use noisy_float::types::{N64, n64};

// 1-dimensional observations, as a (n_observations, 1) 2-d matrix
let observations = Array::from_shape_vec(
    (12, 1),
    vec![1, 4, 5, 2, 100, 20, 50, 65, 27, 40, 45, 23],
).unwrap();

// The optimal grid layout is inferred from the data,
// specifying a strategy (Auto in this case)
let grid = GridBuilder::<Auto<usize>>::from_array(&observations).build();
let expected_grid = Grid::from(vec![Bins::new(Edges::from(vec![1, 20, 39, 58, 77, 96, 115]))]);
assert_eq!(grid, expected_grid);

let histogram = observations.histogram(grid);

let histogram_matrix = histogram.counts();
// Bins are left inclusive, right exclusive!
let expected = array![4, 3, 3, 1, 0, 1];
assert_eq!(histogram_matrix, expected.into_dyn());

Implementations

Returns n, the number of dimensions of the region partitioned by the grid.

Returns the number of bins along each coordinate axis.

Returns the grid projections on the coordinate axes as a slice of immutable references.

Returns the index of the n-dimensional bin containing the point, if one exists.

Returns None if the point is outside the grid.

Panics if point.len() does not equal self.ndim().

Given i=(i_0, ..., i_{n-1}), an n-dimensional index, it returns I_{i_0}x...xI_{i_{n-1}}, an n-dimensional bin, where I_{i_j} is the i_j-th interval on the j-th projection of the grid on the coordinate axes.

Panics if at least one among (i_0, ..., i_{n-1}) is out of bounds on the respective coordinate axis - i.e. if there exists j such that i_j >= self.projections[j].len().

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Get a Grid instance from a Vec<Bins<A>>.

The i-th element in Vec<Bins<A>> represents the 1-dimensional projection of the bin grid on the i-th axis.

Alternatively, a Grid can be built directly from data using a GridBuilder.

This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.