Histogram2D-class {SpatialKWD} | R Documentation |
Two Dimensional Histogram for Spatial Data
Description
The Histogram2D
class represents a single spatial 2-dimensional histograms. The class is mainly composed of three vectors of the same length n
. The first two vectors of integers, called Xs
and Ys
, give the coordinates of each bin of the histogram, while the third
vector of doubles, called Ws
, gives the weight Ws[i]
of the i-th bin located at position Xs[i]
and Ys[i]
.
A 2D histogram can be also defined by adding (or updating) a single element a the time (see the second constructor).
Note that the positions of the bins are not required to lay on rectangular (or squared) grid, but they can lay everywhere in the plane. Before computing the distance between a pair of algorithms, the solver will compute a convex hull of all non-empty bins.
Arguments
n |
Number of non-empty bins. Type: positive integer. |
Xs |
Vector of horizontal coordinates the bins. Type: vector of integers. |
Ys |
Vector of vertical coordinates the bins. Type: vector of integers. |
Ws |
Vector of positive weights of the bin at position (x,y). Type: vector of positive doubles. |
x |
Horizontal coordinate of a bin. Type: integer. |
y |
Vertical coordinate of a bin. Type: integer. |
w |
Weight of the bin at position (x,y). Type: positive double. |
u |
Weight of the bin to be added to the weight at position (x,y). If a bin in position (x,y) is absent, then it is added with weight equal to |
Details
The public methods of the Histogram2D
class are described below.
Value
The add
, update
, and normalize
does not return any value.
The size
method returns the number of non-empty bins in h
.
The balance
method returns the sum of the weights in h
.
Methods
Histogram2D(n, Xs, Ys, Ws)
:c'tor.
add(x, y, w)
:it adds a bin located at position (x,y) with weight w.
update(x, y, u)
:return the total mass balance of this histogram, that is, return the quantity
\sum_{i=1,\dots,n} w_i
.size()
:return the number of non-empty bins n of this histogram.
normalize()
:normalize the weights of all non-empty bins, such that they all sum up to 1. Indeed, this method implements the operation:
w_i \gets \frac{w_i}{\sum_{i=1,\dots,n} w_i}
.balance()
:return the total mass balance of this histogram, that is, return the quantity
\sum_{i=1,\dots,n} w_i
.
See Also
See also compareOneToOne
, compareOneToMany
, compareAll
, focusArea
, and Solver
.
Examples
library(SpatialKWD)
# Define a simple histogram
h <- new(Histogram2D)
# Add half unit of mass at positions (1,0) and (0,1)
h$add(1, 0, 0.5)
h$add(0, 1, 0.5)
# Add at position (5,5) a unit of mass
h$add(5, 5, 1)
# Normalize the histogram
h$normalize()
# Print the total weight (mass) of the histogram
print(sprintf("Histogram total weight = %f", h$balance()))