# Histogram2D-class: Two Dimensional Histogram for Spatial Data In SpatialKWD: Spatial KWD for Large Spatial Maps

## 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 u. Type: positive double.

## 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 ∑_{i=1,…,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 ≥ts \frac{w_i}{∑_{i=1,…,n} w_i}.

balance():

return the total mass balance of this histogram, that is, return the quantity ∑_{i=1,…,n} w_i.

See also compareOneToOne, compareOneToMany, compareAll, focusArea, and Solver.
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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()))
{"ft_lang_label":"__label__en","ft_lang_prob":0.7630609,"math_prob":0.96904385,"size":2832,"snap":"2021-31-2021-39","text_gpt3_token_len":786,"char_repetition_ratio":0.14179632,"word_repetition_ratio":0.092369474,"special_character_ratio":0.2750706,"punctuation_ratio":0.1633987,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9981623,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-28T21:12:15Z\",\"WARC-Record-ID\":\"<urn:uuid:93a84493-02c8-41f4-8ce3-57120c2480a4>\",\"Content-Length\":\"36907\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:73726a69-1da6-4bea-b925-22a355fb318e>\",\"WARC-Concurrent-To\":\"<urn:uuid:e63a8984-da55-4e19-9647-7a2ee6e16c2d>\",\"WARC-IP-Address\":\"51.81.83.12\",\"WARC-Target-URI\":\"https://rdrr.io/cran/SpatialKWD/man/Histogram2D-class.html\",\"WARC-Payload-Digest\":\"sha1:L7IQ37OLRPSXL6QSE6EQYMO56HZVLYT4\",\"WARC-Block-Digest\":\"sha1:54SXUG2O56HK6YHLT72XJBH2X2DVFJ3V\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046153791.41_warc_CC-MAIN-20210728185528-20210728215528-00690.warc.gz\"}"}