File: a00042.html

package info (click to toggle)
bmagic 3.4.0-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,208 kB
  • ctags: 2,500
  • sloc: cpp: 9,399; ansic: 3,142; sh: 2,430; makefile: 340
file content (110 lines) | stat: -rw-r--r-- 6,953 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>BitMagic: sample9.cpp</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="examples.html">Examples</a></div>
<h1>sample9.cpp</h1>Example demonstrates binary distance metrics.<p>
<dl compact><dt><b>See also:</b></dt><dd><a class="el" href="a00101.html#ga1">bm::count_and</a> <p>
<a class="el" href="a00101.html#ga2">bm::count_xor</a> <p>
<a class="el" href="a00101.html#ga3">bm::count_sub</a> <p>
<a class="el" href="a00101.html#ga4">bm::count_or</a> <p>
<a class="el" href="a00101.html#ga0">bm::distance_operation</a></dd></dl>
For more information please visit: <a href="http://bmagic.sourceforge.net">http://bmagic.sourceforge.net</a><p>
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
<span class="comment">Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span>
<span class="comment"></span>
<span class="comment">Permission is hereby granted, free of charge, to any person </span>
<span class="comment">obtaining a copy of this software and associated documentation </span>
<span class="comment">files (the "Software"), to deal in the Software without restriction, </span>
<span class="comment">including without limitation the rights to use, copy, modify, merge, </span>
<span class="comment">publish, distribute, sublicense, and/or sell copies of the Software, </span>
<span class="comment">and to permit persons to whom the Software is furnished to do so, </span>
<span class="comment">subject to the following conditions:</span>
<span class="comment"></span>
<span class="comment">The above copyright notice and this permission notice shall be included </span>
<span class="comment">in all copies or substantial portions of the Software.</span>
<span class="comment"></span>
<span class="comment">THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, </span>
<span class="comment">EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES </span>
<span class="comment">OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. </span>
<span class="comment">IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, </span>
<span class="comment">DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, </span>
<span class="comment">ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR </span>
<span class="comment">OTHER DEALINGS IN THE SOFTWARE.</span>
<span class="comment">*/</span>
<span class="comment"></span>
<span class="comment">/** \example sample9.cpp</span>
<span class="comment"></span>
<span class="comment">    Example demonstrates binary distance metrics.</span>
<span class="comment"> </span>
<span class="comment">  \sa bm::count_and </span>
<span class="comment">  \sa bm::count_xor</span>
<span class="comment">  \sa bm::count_sub</span>
<span class="comment">  \sa bm::count_or</span>
<span class="comment">  \sa bm::distance_operation</span>
<span class="comment"></span>
<span class="comment">   For more information please visit:  http://bmagic.sourceforge.net</span>
<span class="comment"></span>
<span class="comment">*/</span>

<span class="preprocessor">#include &lt;iostream&gt;</span>

<span class="preprocessor">#include "<a class="code" href="a00074.html">bm.h</a>"</span>
<span class="preprocessor">#include "<a class="code" href="a00075.html">bmalgo.h</a>"</span>


<span class="keyword">using</span> <span class="keyword">namespace </span>std;


<span class="keywordtype">int</span> <a name="a59"></a><a class="code" href="a00083.html#a0">main</a>(<span class="keywordtype">void</span>)
{
    <a name="_a60"></a><a class="code" href="a00048.html">bm::bvector&lt;&gt;</a>   bv1;    
    <a class="code" href="a00048.html">bm::bvector&lt;&gt;</a>   bv2;    

    bv1[10] = <span class="keyword">true</span>;
    bv1[100] = <span class="keyword">true</span>;
    bv1[10000] = <span class="keyword">true</span>;
    
    bv2[10] = <span class="keyword">true</span>;
    bv2[100] = <span class="keyword">true</span>;
    bv2[20000] = <span class="keyword">true</span>;
    bv2[30000] = <span class="keyword">true</span>;
    
    <span class="comment">// Hamming distance: </span>
    
    <span class="keywordtype">unsigned</span> hamming = <a name="a61"></a><a class="code" href="a00101.html#ga2">bm::count_xor</a>(bv1, bv2);
    
    cout &lt;&lt; <span class="stringliteral">"Hamming distance = "</span> &lt;&lt; hamming &lt;&lt; endl;

    <span class="comment">// Dice distance using basic distance functions</span>
    
    <span class="keywordtype">double</span> dice = 
        double(2 * bm::count_and(bv1, bv2))/double(bv1.<a name="a62"></a><a class="code" href="a00048.html#a26">count</a>() + bv2.<a class="code" href="a00048.html#a26">count</a>());
    
    cout &lt;&lt; <span class="stringliteral">"Dice distance = "</span> &lt;&lt; dice &lt;&lt; endl;
    
    
    <span class="comment">// Dice distance, can be computed using "metric pipeline"</span>
    
    <a name="_a63"></a><a class="code" href="a00065.html">bm::distance_metric_descriptor</a> dmd[3];
    dmd[0].<a name="a64"></a><a class="code" href="a00065.html#o0">metric</a> = bm::COUNT_AND;
    dmd[1].<a class="code" href="a00065.html#o0">metric</a> = bm::COUNT_A;
    dmd[2].<a class="code" href="a00065.html#o0">metric</a> = bm::COUNT_B;
            
    <a name="a65"></a><a class="code" href="a00101.html#ga0">bm::distance_operation</a>(bv1, bv2, dmd, dmd+3);
    
    <span class="keywordtype">double</span> dice_p = 
        double(2 *  dmd[0].result) / double(dmd[1].result + dmd[2].result);  
    
    cout &lt;&lt; <span class="stringliteral">"Dice distance (pipeline) = "</span> &lt;&lt; dice_p &lt;&lt; endl;
    
    <span class="keywordflow">return</span> 0;
}

</pre></div> <hr size="1"><address style="align: right;"><small>Generated on Thu Apr 20 13:28:45 2006 for BitMagic by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.1 </small></address>
</body>
</html>