23
23
<div class="contents">
24
24
<h1>sample9.cpp</h1><p>Example demonstrates binary distance metrics. </p>
25
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="a00120.html#gae451cb4b87e8c0859b0614d2ffb99737" title="Computes bitcount of AND operation of two bitsets.">bm::count_and</a> </dd>
27
<a class="el" href="a00120.html#gafc64a082dcaee07f70f7faf3e24f844e" title="Computes bitcount of XOR operation of two bitsets.">bm::count_xor</a> </dd>
29
<a class="el" href="a00120.html#ga902d8c1cd1f8a2538cd47d47f5d8d605" title="Computes bitcount of SUB operation of two bitsets.">bm::count_sub</a> </dd>
31
<a class="el" href="a00120.html#ga803c564668703fc3bf80067570c2c905" title="Computes bitcount of OR operation of two bitsets.">bm::count_or</a> </dd>
33
<a class="el" href="a00120.html#ga815fef76f02576ab9ab58de0a45d8a4b" title="Distance computing template function.">bm::distance_operation</a></dd></dl>
25
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="a00125.html#gae451cb4b87e8c0859b0614d2ffb99737" title="Computes bitcount of AND operation of two bitsets.">bm::count_and</a> </dd>
27
<a class="el" href="a00125.html#gafc64a082dcaee07f70f7faf3e24f844e" title="Computes bitcount of XOR operation of two bitsets.">bm::count_xor</a> </dd>
29
<a class="el" href="a00125.html#ga902d8c1cd1f8a2538cd47d47f5d8d605" title="Computes bitcount of SUB operation of two bitsets.">bm::count_sub</a> </dd>
31
<a class="el" href="a00125.html#ga803c564668703fc3bf80067570c2c905" title="Computes bitcount of OR operation of two bitsets.">bm::count_or</a> </dd>
33
<a class="el" href="a00125.html#ga815fef76f02576ab9ab58de0a45d8a4b" title="Distance computing template function.">bm::distance_operation</a></dd></dl>
34
34
<p>For more information please visit: <a href="http://bmagic.sourceforge.net">http://bmagic.sourceforge.net</a></p>
35
35
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
36
36
<span class="comment">Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span>
72
72
<span class="preprocessor">#include <iostream></span>
74
<span class="preprocessor">#include "<a class="code" href="a00084.html">bm.h</a>"</span>
75
<span class="preprocessor">#include "<a class="code" href="a00085.html">bmalgo.h</a>"</span>
74
<span class="preprocessor">#include "<a class="code" href="a00087.html">bm.h</a>"</span>
75
<span class="preprocessor">#include "<a class="code" href="a00088.html">bmalgo.h</a>"</span>
78
78
<span class="keyword">using namespace </span>std;
81
<span class="keywordtype">int</span> <a name="a0"></a><a class="code" href="a00101.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
81
<span class="keywordtype">int</span> <a name="a0"></a><a class="code" href="a00105.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
83
<a name="_a1"></a><a class="code" href="a00043.html" title="bitvector with runtime compression of bits.">bm::bvector<></a> bv1;
84
<a class="code" href="a00043.html" title="bitvector with runtime compression of bits.">bm::bvector<></a> bv2;
83
<a name="_a1"></a><a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector<></a> bv1;
84
<a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector<></a> bv2;
86
86
bv1[10] = <span class="keyword">true</span>;
87
87
bv1[100] = <span class="keyword">true</span>;
95
95
<span class="comment">// Hamming distance: </span>
97
<span class="keywordtype">unsigned</span> hamming = <a name="a2"></a><a class="code" href="a00120.html#gafc64a082dcaee07f70f7faf3e24f844e" title="Computes bitcount of XOR operation of two bitsets.">bm::count_xor</a>(bv1, bv2);
97
<span class="keywordtype">unsigned</span> hamming = <a name="a2"></a><a class="code" href="a00125.html#gafc64a082dcaee07f70f7faf3e24f844e" title="Computes bitcount of XOR operation of two bitsets.">bm::count_xor</a>(bv1, bv2);
99
99
cout << <span class="stringliteral">"Hamming distance = "</span> << hamming << endl;
101
101
<span class="comment">// Dice distance using basic distance functions</span>
103
103
<span class="keywordtype">double</span> dice =
104
double(2 * <a name="a3"></a><a class="code" href="a00120.html#gae451cb4b87e8c0859b0614d2ffb99737" title="Computes bitcount of AND operation of two bitsets.">bm::count_and</a>(bv1, bv2))/double(bv1.<a name="a4"></a><a class="code" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() + bv2.<a class="code" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>());
104
double(2 * <a name="a3"></a><a class="code" href="a00125.html#gae451cb4b87e8c0859b0614d2ffb99737" title="Computes bitcount of AND operation of two bitsets.">bm::count_and</a>(bv1, bv2))/double(bv1.<a name="a4"></a><a class="code" href="a00044.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() + bv2.<a class="code" href="a00044.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>());
106
106
cout << <span class="stringliteral">"Dice distance = "</span> << dice << endl;
109
109
<span class="comment">// Dice distance, can be computed using "metric pipeline"</span>
111
<a name="_a5"></a><a class="code" href="a00060.html" title="Distance metric descriptor, holds metric code and result.">bm::distance_metric_descriptor</a> dmd[3];
112
dmd[0].<a name="a6"></a><a class="code" href="a00060.html#a3ece2ccdb7a6616f06a5a15679ccabb1">metric</a> = <a name="a7"></a><a class="code" href="a00120.html#ggac38d64c8b27b652413a664cddd4d40abacb39376469ba778e9a9099ddbae5e7ce" title="(A &amp; B).count()">bm::COUNT_AND</a>;
113
dmd[1].<a class="code" href="a00060.html#a3ece2ccdb7a6616f06a5a15679ccabb1">metric</a> = <a name="a8"></a><a class="code" href="a00120.html#ggac38d64c8b27b652413a664cddd4d40abaac7947d53eb3acf81251ee4130e6a4a2" title="A.count().">bm::COUNT_A</a>;
114
dmd[2].<a class="code" href="a00060.html#a3ece2ccdb7a6616f06a5a15679ccabb1">metric</a> = <a name="a9"></a><a class="code" href="a00120.html#ggac38d64c8b27b652413a664cddd4d40abac6dbadf2ab9405daa47dc0f10d082516" title="B.count().">bm::COUNT_B</a>;
111
<a name="_a5"></a><a class="code" href="a00061.html" title="Distance metric descriptor, holds metric code and result.">bm::distance_metric_descriptor</a> dmd[3];
112
dmd[0].<a name="a6"></a><a class="code" href="a00061.html#a3ece2ccdb7a6616f06a5a15679ccabb1">metric</a> = <a name="a7"></a><a class="code" href="a00125.html#ggac38d64c8b27b652413a664cddd4d40abacb39376469ba778e9a9099ddbae5e7ce" title="(A &amp; B).count()">bm::COUNT_AND</a>;
113
dmd[1].<a class="code" href="a00061.html#a3ece2ccdb7a6616f06a5a15679ccabb1">metric</a> = <a name="a8"></a><a class="code" href="a00125.html#ggac38d64c8b27b652413a664cddd4d40abaac7947d53eb3acf81251ee4130e6a4a2" title="A.count().">bm::COUNT_A</a>;
114
dmd[2].<a class="code" href="a00061.html#a3ece2ccdb7a6616f06a5a15679ccabb1">metric</a> = <a name="a9"></a><a class="code" href="a00125.html#ggac38d64c8b27b652413a664cddd4d40abac6dbadf2ab9405daa47dc0f10d082516" title="B.count().">bm::COUNT_B</a>;
116
<a name="a10"></a><a class="code" href="a00120.html#ga815fef76f02576ab9ab58de0a45d8a4b" title="Distance computing template function.">bm::distance_operation</a>(bv1, bv2, dmd, dmd+3);
116
<a name="a10"></a><a class="code" href="a00125.html#ga815fef76f02576ab9ab58de0a45d8a4b" title="Distance computing template function.">bm::distance_operation</a>(bv1, bv2, dmd, dmd+3);
118
118
<span class="keywordtype">double</span> dice_p =
119
119
double(2 * dmd[0].result) / double(dmd[1].result + dmd[2].result);
126
126
</pre></div> </div>
127
<hr size="1"/><address style="text-align: right;"><small>Generated on Sun Nov 22 10:49:34 2009 for BitMagic by
127
<hr size="1"/><address style="text-align: right;"><small>Generated on Fri Jan 8 20:09:19 2010 for BitMagic by
128
128
<a href="http://www.doxygen.org/index.html">
129
129
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>