- Main Page
- Modules
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

# sample9.cpp

Go to the documentation of this file.

    00001 /*
    00002 Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)
    00003
    00004 Permission is hereby granted, free of charge, to any person
    00005 obtaining a copy of this software and associated documentation
    00006 files (the "Software"), to deal in the Software without restriction,
    00007 including without limitation the rights to use, copy, modify, merge,
    00008 publish, distribute, sublicense, and/or sell copies of the Software,
    00009 and to permit persons to whom the Software is furnished to do so,
    00010 subject to the following conditions:
    00011
    00012 The above copyright notice and this permission notice shall be included
    00013 in all copies or substantial portions of the Software.
    00014
    00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    00016 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
    00017 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    00018 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    00019 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    00020 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    00021 OTHER DEALINGS IN THE SOFTWARE.
    00022 */
    00023
    00024 /** \example sample9.cpp
    00025
    00026     Example demonstrates binary distance metrics.
    00027
    00028   \sa bm::count_and
    00029   \sa bm::count_xor
    00030   \sa bm::count_sub
    00031   \sa bm::count_or
    00032   \sa bm::distance_operation
    00033
    00034    For more information please visit:  http://bmagic.sourceforge.net
    00035
    00036 */
    00037
    00038 #include <iostream>
    00039
    00040 #include "bm.h"
    00041 #include "bmalgo.h"
    00042
    00043
    00044 using namespace std;
    00045
    00046
    00047 int main(void)
    00048 {
    00049     bm::bvector<>   bv1;
    00050     bm::bvector<>   bv2;
    00051
    00052     bv1[10] = true;
    00053     bv1[100] = true;
    00054     bv1[10000] = true;
    00055
    00056     bv2[10] = true;
    00057     bv2[100] = true;
    00058     bv2[20000] = true;
    00059     bv2[30000] = true;
    00060
    00061     // Hamming distance:
    00062
    00063     unsigned hamming = bm::count_xor(bv1, bv2);
    00064
    00065     cout << "Hamming distance = " << hamming << endl;
    00066
    00067     // Dice distance using basic distance functions
    00068
    00069     double dice =
    00070         double(2 * bm::count_and(bv1, bv2))/double(bv1.count() + bv2.count());
    00071
    00072     cout << "Dice distance = " << dice << endl;
    00073
    00074
    00075     // Dice distance, can be computed using "metric pipeline"
    00076
    00077     bm::distance_metric_descriptor dmd[3];
    00078     dmd[0].metric = bm::COUNT_AND;
    00079     dmd[1].metric = bm::COUNT_A;
    00080     dmd[2].metric = bm::COUNT_B;
    00081
    00082     bm::distance_operation(bv1, bv2, dmd, dmd+3);
    00083
    00084     double dice_p =
    00085         double(2 *  dmd[0].result) / double(dmd[1].result + dmd[2].result);
    00086
    00087     cout << "Dice distance (pipeline) = " << dice_p << endl;
    00088
    00089     return 0;
    00090 }
    00091