📄 apriori_8cpp-source.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: Apriori.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.9.1 --><div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a></div><h1>Apriori.cpp</h1><a href="Apriori_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/***************************************************************************</span>00002 <span class="comment"> apriori.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@cs.bme.hu</span>00007 <span class="comment"> ***************************************************************************/</span>00008 00009 <span class="preprocessor">#include "<a class="code" href="Apriori_8hpp.html">Apriori.hpp</a>"</span>00010 <span class="preprocessor">#include <iostream></span>00011 <span class="preprocessor">#include <vector></span>00012 <span class="preprocessor">#include <set></span>00013 <span class="preprocessor">#include <cmath></span> <span class="comment">//because of the ceil function</span>00014 00015 <span class="keyword">using</span> <span class="keyword">namespace </span>std;00016 <a name="l00021"></a><a class="code" href="classApriori.html#d0">00021</a> <span class="keywordtype">void</span> <a class="code" href="classApriori.html#d0">Apriori::support</a>( <span class="keyword">const</span> itemtype& candidate_size )00022 {00023 set<itemtype> basket;00024 vector<itemtype> basket_v;00025 <span class="keywordflow">if</span>( store_input )00026 {00027 <span class="keywordflow">if</span> (candidate_size == 2)00028 {00029 <span class="keywordflow">while</span>( <a class="code" href="classApriori.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="classApriori.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()>1) <a class="code" href="classApriori.html#r2">reduced_baskets</a>[basket_v]++;00033 }00034 }00035 <span class="keywordflow">for</span> (map<vector<itemtype>, <a class="code" href="common_8hpp.html#a1">countertype</a>>::iterator it = 00036 <a class="code" href="classApriori.html#r2">reduced_baskets</a>.begin(); it!=<a class="code" href="classApriori.html#r2">reduced_baskets</a>.end();it++)00037 <a class="code" href="classApriori.html#r0">apriori_trie</a>-><a class="code" href="classApriori__Trie.html#a3">find_candidate</a>(it->first,candidate_size,it->second);00038 }00039 <span class="keywordflow">else</span> <span class="keywordflow">while</span>( <a class="code" href="classApriori.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="classApriori.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="classApriori.html#r0">apriori_trie</a>-><a class="code" href="classApriori__Trie.html#a3">find_candidate</a>(basket_v,candidate_size);00043 }00044 }00045 00055 <span class="keywordtype">void</span> <a class="code" href="classApriori.html#a1">Apriori::APRIORI_alg</a>( <span class="keyword">const</span> <span class="keywordtype">double</span> min_supp, 00056 <span class="keyword">const</span> <span class="keywordtype">bool</span> quiet, 00057 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size_threshold )00058 {00059 <a class="code" href="common_8hpp.html#a1">countertype</a> basket_number; 00060 <span class="keywordflow">if</span>(!quiet) cout<<endl<<<span class="stringliteral">"\t\tFinding frequent itemsets..."</span><<endl<<endl;00061 <a class="code" href="common_8hpp.html#a0">itemtype</a> candidate_size=1;00062 <span class="keywordflow">if</span>(!quiet)00063 {00064 cout<<endl<<<span class="stringliteral">"Determining the support of the items"</span>;00065 cout<<<span class="stringliteral">" and deleting infrequent ones!"</span><<endl;00066 }00067 vector<countertype> support_of_items;00068 basket_number = <a class="code" href="classApriori.html#r1">input_output_manager</a>.<a class="code" href="classInput__Output__Manager.html#a2">find_frequent_items</a>( 00069 min_supp, support_of_items );00070 <a class="code" href="classApriori.html#r1">input_output_manager</a><< <span class="stringliteral">"Frequent 0-itemsets:\nitemset (occurrence)\n"</span>;00071 <a class="code" href="classApriori.html#r1">input_output_manager</a><< <span class="stringliteral">"{} ("</span><< basket_number << <span class="stringliteral">")\n"</span>;00072 <a class="code" href="classApriori.html#r1">input_output_manager</a><< <span class="stringliteral">"Frequent "</span> << 1;00073 <a class="code" href="classApriori.html#r1">input_output_manager</a><< <span class="stringliteral">"-itemsets:\nitemset (occurrence)\n"</span>;00074 set<itemtype> temp_set;00075 <span class="keywordflow">for</span>(vector<countertype>::size_type index = 0;00076 index < support_of_items.size(); index++)00077 {00078 temp_set.insert(index);00079 <a class="code" href="classApriori.html#r1">input_output_manager</a>.<a class="code" href="classInput__Output__Manager.html#a5">write_out_basket_and_counter</a>( 00080 temp_set, support_of_items[index] );00081 temp_set.erase(temp_set.begin());00082 }00083 00084 <a class="code" href="classApriori.html#r0">apriori_trie</a> = <span class="keyword">new</span> <a class="code" href="classApriori__Trie.html">Apriori_Trie</a>( basket_number );00085 <a class="code" href="classApriori.html#r0">apriori_trie</a>-><a class="code" href="classApriori__Trie.html#a1">insert_frequent_items</a>( support_of_items );00086 00087 <span class="comment">// apriori_trie->show_content();</span>00088 <span class="comment">// getchar();</span>00089 <span class="keywordtype">double</span> min_supp_abs = min_supp * (basket_number - 0.5);00090 <span class="comment">// apriori_trie->show_content();</span>00091 <span class="comment">// getchar();</span>00092 candidate_size++;00093 <span class="keywordflow">if</span>(!quiet) 00094 {00095 cout<<endl<<<span class="stringliteral">"Genarating "</span><<candidate_size;00096 cout<<<span class="stringliteral">"-itemset candidates!"</span><<endl;00097 }00098 <a class="code" href="classApriori.html#r0">apriori_trie</a>-><a class="code" href="classApriori__Trie.html#a2">candidate_generation</a>(candidate_size-1,00099 input_output_manager);00100 <span class="comment">// apriori_trie->show_content();</span>00101 <span class="comment">// getchar();</span>00102 <span class="keywordflow">while</span>( <a class="code" href="classApriori.html#r0">apriori_trie</a>-><a class="code" href="classApriori__Trie.html#a5">is_there_any_candidate</a>() )00103 {00104 <a class="code" href="classApriori.html#r1">input_output_manager</a>.<a class="code" href="classInput__Output__Manager.html#a6">rewind</a>();00105 <span class="keywordflow">if</span>(!quiet)00106 {00107 cout<<<span class="stringliteral">"Determining the support of the "</span><<candidate_size;00108 cout<<<span class="stringliteral">"-itemset candidates!"</span><<endl;00109 }00110 <a class="code" href="classApriori.html#d0">support</a>( candidate_size );00111 <span class="comment">// apriori_trie->show_content();</span>00112 <span class="comment">// getchar();</span>00113 <span class="keywordflow">if</span>(!quiet) cout<<<span class="stringliteral">"Deleting infrequent itemsets!"</span><<endl;00114 <a class="code" href="classApriori.html#r0">apriori_trie</a>-><a class="code" href="classApriori__Trie.html#a4">delete_infrequent</a>(min_supp_abs, candidate_size);00115 <span class="comment">// apriori_trie->show_content();</span>00116 <span class="comment">// getchar();</span>00117 <span class="keywordflow">if</span> (candidate_size == size_threshold )00118 {00119 <span class="keywordflow">if</span>(!quiet) cout<<<span class="stringliteral">"Size threshold is reached!"</span><<endl;00120 <span class="keywordflow">break</span>;00121 }00122 candidate_size++;00123 <span class="keywordflow">if</span>( !quiet )00124 {00125 cout<<endl<<<span class="stringliteral">"Genarating "</span><<candidate_size;00126 cout<<<span class="stringliteral">"-itemset candidates!"</span><<endl;00127 }00128 <a class="code" href="classApriori.html#r1">input_output_manager</a><< <span class="stringliteral">"Frequent "</span> << candidate_size-1;00129 <a class="code" href="classApriori.html#r1">input_output_manager</a><< <span class="stringliteral">"-itemsets:\nitemset (occurrence)\n"</span>;00130 <a class="code" href="classApriori.html#r0">apriori_trie</a>-><a class="code" href="classApriori__Trie.html#a2">candidate_generation</a>(candidate_size-1,00131 input_output_manager);00132 <span class="comment">// apriori_trie->show_content_preorder();</span>00133 <span class="comment">// getchar();</span>00134 }00135 <span class="keywordflow">if</span>(!quiet) cout<<endl<<<span class="stringliteral">"Mining is done!"</span><<endl;00136 }</pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Mar 11 14:48:06 2005 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.9.1 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -