⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msapriori_8cpp-source.html

📁 Aprior的C++实现算法
💻 HTML
字号:
<!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>APRIORI algorithm: MSApriori.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.5 --><div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div><h1>MSApriori.cpp</h1><a href="MSApriori_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/***************************************************************************</span>00002 <span class="comment">                          MSApriori.cpp  -  description</span>00003 <span class="comment">                             -------------------</span>00004 <span class="comment">    begin                : cs dec 26 2002</span>00005 <span class="comment">    copyright            : (C) 2002 by Ferenc Bodon</span>00006 <span class="comment">    email                : bodon@mit.bme.hu</span>00007 <span class="comment"> ***************************************************************************/</span>00008 00009 <span class="preprocessor">#include "<a class="code" href="MSApriori_8hpp.html">MSApriori.hpp</a>"</span>00010 <span class="preprocessor">#include &lt;iostream&gt;</span>00011 <span class="preprocessor">#include &lt;vector&gt;</span>00012 <span class="preprocessor">#include &lt;set&gt;</span>00013 00014 00015 <span class="keyword">using</span> <span class="keyword">namespace </span>std;00016 <a name="l00021"></a><a class="code" href="classMSApriori.html#d0">00021</a> <span class="keywordtype">void</span> <a class="code" href="classMSApriori.html#d0">MSApriori::support</a>( <span class="keyword">const</span> <a class="code" href="common_8hpp.html#a0">itemtype</a>&amp; candidate_size )00022 {00023    set&lt;itemtype&gt; basket;00024    vector&lt;itemtype&gt; basket_v;00025    <span class="keywordflow">if</span>( <a class="code" href="classMSApriori.html#r3">store_input</a> )00026    {00027       <span class="keywordflow">if</span> (candidate_size == 2)00028       {00029          <span class="keywordflow">while</span>( <a class="code" href="classMSApriori.html#r1">input_output_manager</a>.<a class="code" href="classInput__Output__Manager.html#a1">read_in_a_line</a>( basket ) )00030          {00031             <a class="code" href="classMSApriori.html#r1">input_output_manager</a>.<a class="code" href="classInput__Output__Manager.html#a3">basket_recode</a>( basket, basket_v );00032             <span class="keywordflow">if</span> (basket_v.size()&gt;1) <a class="code" href="classMSApriori.html#r2">reduced_baskets</a>[basket_v]++;00033          }00034       }00035       <span class="keywordflow">for</span> (map&lt;vector&lt;itemtype&gt;,<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>&gt;::iterator it = <a class="code" href="classMSApriori.html#r2">reduced_baskets</a>.begin();00036            it!=<a class="code" href="classMSApriori.html#r2">reduced_baskets</a>.end();it++)00037          <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>-&gt;<a class="code" href="classMSApriori__Trie.html#a3">find_candidate</a>(it-&gt;first,candidate_size,it-&gt;second);00038    }00039    <span class="keywordflow">else</span> <span class="keywordflow">while</span>( <a class="code" href="classMSApriori.html#r1">input_output_manager</a>.<a class="code" href="classInput__Output__Manager.html#a1">read_in_a_line</a>( basket ) )00040    {00041       <a class="code" href="classMSApriori.html#r1">input_output_manager</a>.<a class="code" href="classInput__Output__Manager.html#a3">basket_recode</a>(basket, basket_v);00042           <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>-&gt;<a class="code" href="classMSApriori__Trie.html#a3">find_candidate</a>(basket_v,candidate_size);00043    }00044 }00045 <a name="l00054"></a><a class="code" href="classMSApriori.html#a0">00054</a> <a class="code" href="classMSApriori.html#a0">MSApriori::MSApriori</a>( ifstream&amp; basket_file, <span class="keyword">const</span> <span class="keywordtype">char</span>*  output_file_name, 00055                   <span class="keyword">const</span> <span class="keywordtype">bool</span> store_input):00056                   input_output_manager(basket_file, output_file_name ),00057                   store_input(store_input)00058 {00059 }00060 <a name="l00068"></a><a class="code" href="classMSApriori.html#a1">00068</a> <span class="keywordtype">void</span> <a class="code" href="classMSApriori.html#a1">MSApriori::MSAPRIORI_alg</a>( ifstream&amp; mis_file, <span class="keyword">const</span> <span class="keywordtype">double</span> min_conf, 00069                                <span class="keyword">const</span> <span class="keywordtype">bool</span> quiet, <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> size_threshold )00070 {00071    vector&lt;double&gt; mis_abs;00072    <span class="keywordflow">if</span>(!quiet) cout&lt;&lt;endl&lt;&lt;<span class="stringliteral">"\t\tFinding frequent itemsets..."</span>&lt;&lt;endl&lt;&lt;endl;00073    <a class="code" href="common_8hpp.html#a0">itemtype</a> candidate_size=1;00074    <a class="code" href="common_8hpp.html#a0">itemtype</a> longest_path,longest_path_after_delete=1;00075    <span class="keywordflow">if</span>(!quiet)00076       cout&lt;&lt;endl&lt;&lt;<span class="stringliteral">"Determining the support of the items and deleting infrequent ones!"</span>&lt;&lt;endl;00077    set&lt; pair&lt;itemtype, unsigned long&gt; &gt; support_of_items;00078    <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> basket_number = <a class="code" href="classMSApriori.html#r1">input_output_manager</a>.<a class="code" href="classInput__Output__Manager.html#a2">find_frequent_items</a>( mis_file,00079                                                                            support_of_items, mis_abs );00080    <a class="code" href="classMSApriori.html#r0">msapriori_trie</a> = <span class="keyword">new</span> <a class="code" href="classMSApriori__Trie.html">MSApriori_Trie</a>( basket_number, mis_abs );00081    <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>-&gt;<a class="code" href="classMSApriori__Trie.html#a1">insert_frequent_items</a>( support_of_items );00082 00083 <span class="comment">//   apriori_trie-&gt;show_content();</span>00084 <span class="comment">//   getchar();</span>00085    longest_path_after_delete = <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>-&gt;<a class="code" href="classMSApriori__Trie.html#a6">longest_path</a>();00086 <span class="comment">//   apriori_trie-&gt;show_content();</span>00087 <span class="comment">//   getchar();</span>00088    longest_path = <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>-&gt;<a class="code" href="classMSApriori__Trie.html#a6">longest_path</a>();00089    candidate_size++;00090    <span class="keywordflow">if</span>(!quiet) cout&lt;&lt;endl&lt;&lt;<span class="stringliteral">"Genarating "</span>&lt;&lt;candidate_size&lt;&lt;<span class="stringliteral">"-itemset candidates!"</span>&lt;&lt;endl;00091    <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>-&gt;<a class="code" href="classMSApriori__Trie.html#a2">candidate_generation</a>( candidate_size-1 );00092 <span class="comment">//   apriori_trie-&gt;show_content();</span>00093 <span class="comment">//   getchar();</span>00094    <span class="keywordflow">while</span>( longest_path &lt; <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>-&gt;<a class="code" href="classMSApriori__Trie.html#a6">longest_path</a>() )00095    {00096       <a class="code" href="classMSApriori.html#r1">input_output_manager</a>.<a class="code" href="classInput__Output__Manager.html#a6">rewind</a>();00097       <span class="keywordflow">if</span>(!quiet) cout&lt;&lt;<span class="stringliteral">"Determining the support of the "</span>&lt;&lt;candidate_size&lt;&lt;<span class="stringliteral">"-itemset candidates!"</span>&lt;&lt;endl;00098       <a class="code" href="classMSApriori.html#d0">support</a>( candidate_size );00099 <span class="comment">//      apriori_trie-&gt;show_content();</span>00100 <span class="comment">//      getchar();</span>00101       <span class="keywordflow">if</span>(!quiet) cout&lt;&lt;<span class="stringliteral">"Deleting infrequent itemsets!"</span>&lt;&lt;endl;00102       <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>-&gt;<a class="code" href="classMSApriori__Trie.html#a4">delete_infrequent</a>( candidate_size);00103       longest_path_after_delete = <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>-&gt;<a class="code" href="classMSApriori__Trie.html#a6">longest_path</a>();00104 <span class="comment">//      apriori_trie-&gt;show_content();</span>00105 <span class="comment">//      getchar();</span>00106       <span class="keywordflow">if</span> (candidate_size == size_threshold )00107       {00108          <span class="keywordflow">if</span>(!quiet) cout&lt;&lt;<span class="stringliteral">"Size threshold is reached!"</span>&lt;&lt;endl;00109          <span class="keywordflow">break</span>;00110       }00111       longest_path = <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>-&gt;<a class="code" href="classMSApriori__Trie.html#a6">longest_path</a>();00112       candidate_size++;00113       <span class="keywordflow">if</span>( !quiet ) cout&lt;&lt;endl&lt;&lt;<span class="stringliteral">"Genarating "</span>&lt;&lt;candidate_size&lt;&lt;<span class="stringliteral">"-itemset candidates!"</span>&lt;&lt;endl;00114       <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>-&gt;<a class="code" href="classMSApriori__Trie.html#a2">candidate_generation</a>(candidate_size-1);00115 <span class="comment">//      apriori_trie-&gt;show_content_preorder();</span>00116 <span class="comment">//      getchar();</span>00117    }00118    <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>-&gt;<a class="code" href="classMSApriori__Trie.html#a7">write_content_to_file</a>( <a class="code" href="classMSApriori.html#r1">input_output_manager</a> );00119    <span class="keywordflow">if</span> (min_conf)00120    {00121       <span class="keywordflow">if</span>(!quiet) cout&lt;&lt;<span class="stringliteral">"\nGenerating association rules...!\n"</span>;00122       <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>-&gt;<a class="code" href="classMSApriori__Trie.html#a5">association</a>( min_conf, <a class="code" href="classMSApriori.html#r1">input_output_manager</a> );00123    }00124    <span class="keywordflow">if</span>(!quiet) cout&lt;&lt;<span class="stringliteral">"\nMining is done!\n"</span>;00125 }00126 <a name="l00127"></a><a class="code" href="classMSApriori.html#a2">00127</a> <a class="code" href="classMSApriori.html#a2">MSApriori::~MSApriori</a>()00128 {00129    <span class="keyword">delete</span> <a class="code" href="classMSApriori.html#r0">msapriori_trie</a>;00130 }00131 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Jun 20 23:41:08 2004 for APRIORI algorithm by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.5 </small></address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -