Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cookbook for chi_square distance (#4324)
* updated csv_file in chi_square.sg to new api and wrote a cookbook for the chi_square distance
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
=================== | ||
Chi Square Distance | ||
=================== | ||
|
||
The Chi Square Distance for real valued features :math:`\bf{x},\bf{x'} \in \mathbb{R}^{n}` extends the concept of :math:`\chi^{2}` distance to negative values. | ||
This distance is calculated by the equation: | ||
|
||
.. math:: | ||
d(\bf{x},\bf{x'}) = \sum_{i=1}^{n}\frac{(x_{i}-x'_{i})^2}{|x_{i}|+|x'_{i}|} | ||
------- | ||
Example | ||
------- | ||
|
||
We first create some sample data. So we instantiate CDenseFeatures containing the sample data. | ||
|
||
.. sgexample:: chi_square.sg:create_features | ||
|
||
We create an instance of :sgclass:`CChiSquareDistance` by passing it the sample data :sgclass:`CDenseFeatures`. | ||
|
||
.. sgexample:: cosine.sg:create_instance | ||
|
||
The distance matrix can be extracted as follows: | ||
|
||
.. sgexample:: chi_square.sg:extract_distance | ||
|
||
We can use the same instance with new :sgclass:`CDenseFeatures` to compute asymmetrical distance as follows: | ||
|
||
.. sgexample:: chi_square.sg:refresh_distance | ||
|
||
---------- | ||
References | ||
---------- | ||
:wiki:`Chi-squared_test` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters