nysol-take 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/mbiclique.rb +317 -0
- data/bin/mbipolish.rb +362 -0
- data/bin/mccomp.rb +235 -0
- data/bin/mclique.rb +295 -0
- data/bin/mclique2g.rb +105 -0
- data/bin/mcliqueInfo.rb +203 -0
- data/bin/mfriends.rb +202 -0
- data/bin/mgdiff.rb +252 -0
- data/bin/mhifriend.rb +456 -0
- data/bin/mhipolish.rb +465 -0
- data/bin/mitemset.rb +168 -0
- data/bin/mpal.rb +410 -0
- data/bin/mpolishing.rb +399 -0
- data/bin/msequence.rb +165 -0
- data/bin/mtra2g.rb +476 -0
- data/bin/mtra2gc.rb +360 -0
- data/ext/grhfilrun/extconf.rb +12 -0
- data/ext/grhfilrun/grhfilrun.c +85 -0
- data/ext/grhfilrun/src/_sspc.c +358 -0
- data/ext/grhfilrun/src/aheap.c +545 -0
- data/ext/grhfilrun/src/aheap.h +251 -0
- data/ext/grhfilrun/src/base.c +92 -0
- data/ext/grhfilrun/src/base.h +59 -0
- data/ext/grhfilrun/src/fstar.c +497 -0
- data/ext/grhfilrun/src/fstar.h +80 -0
- data/ext/grhfilrun/src/grhfil.c +214 -0
- data/ext/grhfilrun/src/itemset.c +713 -0
- data/ext/grhfilrun/src/itemset.h +170 -0
- data/ext/grhfilrun/src/problem.c +415 -0
- data/ext/grhfilrun/src/problem.h +179 -0
- data/ext/grhfilrun/src/queue.c +533 -0
- data/ext/grhfilrun/src/queue.h +182 -0
- data/ext/grhfilrun/src/sample.c +19 -0
- data/ext/grhfilrun/src/sspc.c +597 -0
- data/ext/grhfilrun/src/sspc2.c +491 -0
- data/ext/grhfilrun/src/stdlib2.c +1482 -0
- data/ext/grhfilrun/src/stdlib2.h +892 -0
- data/ext/grhfilrun/src/trsact.c +817 -0
- data/ext/grhfilrun/src/trsact.h +160 -0
- data/ext/grhfilrun/src/vec.c +745 -0
- data/ext/grhfilrun/src/vec.h +172 -0
- data/ext/lcmrun/extconf.rb +20 -0
- data/ext/lcmrun/lcmrun.cpp +99 -0
- data/ext/lcmrun/src/aheap.c +216 -0
- data/ext/lcmrun/src/aheap.h +111 -0
- data/ext/lcmrun/src/base.c +92 -0
- data/ext/lcmrun/src/base.h +59 -0
- data/ext/lcmrun/src/itemset.c +496 -0
- data/ext/lcmrun/src/itemset.h +157 -0
- data/ext/lcmrun/src/lcm.c +427 -0
- data/ext/lcmrun/src/problem.c +349 -0
- data/ext/lcmrun/src/problem.h +177 -0
- data/ext/lcmrun/src/queue.c +528 -0
- data/ext/lcmrun/src/queue.h +176 -0
- data/ext/lcmrun/src/sgraph.c +359 -0
- data/ext/lcmrun/src/sgraph.h +173 -0
- data/ext/lcmrun/src/stdlib2.c +1282 -0
- data/ext/lcmrun/src/stdlib2.h +823 -0
- data/ext/lcmrun/src/trsact.c +747 -0
- data/ext/lcmrun/src/trsact.h +159 -0
- data/ext/lcmrun/src/vec.c +731 -0
- data/ext/lcmrun/src/vec.h +171 -0
- data/ext/lcmseq0run/extconf.rb +20 -0
- data/ext/lcmseq0run/lcmseq0run.cpp +59 -0
- data/ext/lcmseq0run/src/aheap.c +216 -0
- data/ext/lcmseq0run/src/aheap.h +111 -0
- data/ext/lcmseq0run/src/base.c +92 -0
- data/ext/lcmseq0run/src/base.h +59 -0
- data/ext/lcmseq0run/src/itemset.c +518 -0
- data/ext/lcmseq0run/src/itemset.h +157 -0
- data/ext/lcmseq0run/src/itemset_zero.c +522 -0
- data/ext/lcmseq0run/src/lcm_seq.c +446 -0
- data/ext/lcmseq0run/src/lcm_seq_zero.c +446 -0
- data/ext/lcmseq0run/src/problem.c +439 -0
- data/ext/lcmseq0run/src/problem.h +179 -0
- data/ext/lcmseq0run/src/problem_zero.c +439 -0
- data/ext/lcmseq0run/src/queue.c +533 -0
- data/ext/lcmseq0run/src/queue.h +182 -0
- data/ext/lcmseq0run/src/stdlib2.c +1350 -0
- data/ext/lcmseq0run/src/stdlib2.h +864 -0
- data/ext/lcmseq0run/src/trsact.c +747 -0
- data/ext/lcmseq0run/src/trsact.h +159 -0
- data/ext/lcmseq0run/src/vec.c +779 -0
- data/ext/lcmseq0run/src/vec.h +172 -0
- data/ext/lcmseqrun/extconf.rb +20 -0
- data/ext/lcmseqrun/lcmseqrun.cpp +101 -0
- data/ext/lcmseqrun/src/aheap.c +216 -0
- data/ext/lcmseqrun/src/aheap.h +111 -0
- data/ext/lcmseqrun/src/base.c +92 -0
- data/ext/lcmseqrun/src/base.h +59 -0
- data/ext/lcmseqrun/src/itemset.c +518 -0
- data/ext/lcmseqrun/src/itemset.h +157 -0
- data/ext/lcmseqrun/src/itemset_zero.c +522 -0
- data/ext/lcmseqrun/src/lcm_seq.c +447 -0
- data/ext/lcmseqrun/src/lcm_seq_zero.c +446 -0
- data/ext/lcmseqrun/src/problem.c +439 -0
- data/ext/lcmseqrun/src/problem.h +179 -0
- data/ext/lcmseqrun/src/problem_zero.c +439 -0
- data/ext/lcmseqrun/src/queue.c +533 -0
- data/ext/lcmseqrun/src/queue.h +182 -0
- data/ext/lcmseqrun/src/stdlib2.c +1350 -0
- data/ext/lcmseqrun/src/stdlib2.h +864 -0
- data/ext/lcmseqrun/src/trsact.c +747 -0
- data/ext/lcmseqrun/src/trsact.h +159 -0
- data/ext/lcmseqrun/src/vec.c +779 -0
- data/ext/lcmseqrun/src/vec.h +172 -0
- data/ext/lcmtransrun/extconf.rb +18 -0
- data/ext/lcmtransrun/lcmtransrun.cpp +264 -0
- data/ext/macerun/extconf.rb +20 -0
- data/ext/macerun/macerun.cpp +57 -0
- data/ext/macerun/src/aheap.c +217 -0
- data/ext/macerun/src/aheap.h +112 -0
- data/ext/macerun/src/itemset.c +491 -0
- data/ext/macerun/src/itemset.h +158 -0
- data/ext/macerun/src/mace.c +503 -0
- data/ext/macerun/src/problem.c +346 -0
- data/ext/macerun/src/problem.h +174 -0
- data/ext/macerun/src/queue.c +529 -0
- data/ext/macerun/src/queue.h +177 -0
- data/ext/macerun/src/sgraph.c +360 -0
- data/ext/macerun/src/sgraph.h +174 -0
- data/ext/macerun/src/stdlib2.c +993 -0
- data/ext/macerun/src/stdlib2.h +811 -0
- data/ext/macerun/src/vec.c +634 -0
- data/ext/macerun/src/vec.h +170 -0
- data/ext/sspcrun/extconf.rb +20 -0
- data/ext/sspcrun/src/_sspc.c +358 -0
- data/ext/sspcrun/src/aheap.c +545 -0
- data/ext/sspcrun/src/aheap.h +251 -0
- data/ext/sspcrun/src/base.c +92 -0
- data/ext/sspcrun/src/base.h +59 -0
- data/ext/sspcrun/src/fstar.c +496 -0
- data/ext/sspcrun/src/fstar.h +80 -0
- data/ext/sspcrun/src/grhfil.c +213 -0
- data/ext/sspcrun/src/itemset.c +713 -0
- data/ext/sspcrun/src/itemset.h +170 -0
- data/ext/sspcrun/src/problem.c +415 -0
- data/ext/sspcrun/src/problem.h +179 -0
- data/ext/sspcrun/src/queue.c +533 -0
- data/ext/sspcrun/src/queue.h +182 -0
- data/ext/sspcrun/src/sample.c +19 -0
- data/ext/sspcrun/src/sspc.c +598 -0
- data/ext/sspcrun/src/sspc2.c +491 -0
- data/ext/sspcrun/src/stdlib2.c +1482 -0
- data/ext/sspcrun/src/stdlib2.h +892 -0
- data/ext/sspcrun/src/trsact.c +817 -0
- data/ext/sspcrun/src/trsact.h +160 -0
- data/ext/sspcrun/src/vec.c +745 -0
- data/ext/sspcrun/src/vec.h +172 -0
- data/ext/sspcrun/sspcrun.cpp +54 -0
- data/lib/nysol/enumLcmEp.rb +338 -0
- data/lib/nysol/enumLcmEsp.rb +284 -0
- data/lib/nysol/enumLcmIs.rb +275 -0
- data/lib/nysol/enumLcmSeq.rb +143 -0
- data/lib/nysol/items.rb +201 -0
- data/lib/nysol/seqDB.rb +256 -0
- data/lib/nysol/take.rb +39 -0
- data/lib/nysol/taxonomy.rb +113 -0
- data/lib/nysol/traDB.rb +257 -0
- metadata +239 -0
@@ -0,0 +1,284 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "rubygems"
|
3
|
+
require "nysol/mcmd"
|
4
|
+
require "nysol/take"
|
5
|
+
|
6
|
+
require "nysol/seqDB.rb"
|
7
|
+
|
8
|
+
module TAKE
|
9
|
+
|
10
|
+
#========================================================================
|
11
|
+
# 列挙関数:lcm_seq 利用DB:SeqDB
|
12
|
+
#========================================================================
|
13
|
+
class LcmEsp
|
14
|
+
attr_reader :size # 列挙されたパターン数
|
15
|
+
|
16
|
+
@@intMax=2147483646
|
17
|
+
#@@intMax=100
|
18
|
+
|
19
|
+
# posトランザクションの重み計算
|
20
|
+
# マニュアルの式(10)
|
21
|
+
def calOmega(posCnt)
|
22
|
+
return @@intMax/posCnt
|
23
|
+
end
|
24
|
+
|
25
|
+
# LCM最小サポートの計算
|
26
|
+
# マニュアルの式(9)
|
27
|
+
def calSigma(minPos,minGR,posCnt,negCnt)
|
28
|
+
omegaF=@@intMax.to_f/posCnt.to_f
|
29
|
+
beta=minPos
|
30
|
+
w=posCnt.to_f/negCnt.to_f
|
31
|
+
sigma=(beta*(omegaF-w/minGR)).to_i # 切り捨て
|
32
|
+
sigma=1 if sigma<=0
|
33
|
+
return sigma
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# 1:β 最小支持度
|
38
|
+
# 2:γ 最小GR
|
39
|
+
# 3:Dp クラス1トランザクション数
|
40
|
+
# 4:Dn クラス2トランザクション数
|
41
|
+
# 5:lcmq LCM列挙数調整パラメータ
|
42
|
+
# 1:γ 2:Dp 3:Dn 4:lcmq
|
43
|
+
#def calOmega(minGR,posCnt,negCnt,lcmq=0.5)
|
44
|
+
# #return (negCnt.to_f*(1-prob))/(posCnt.to_f*prob)/(1-lcmq)
|
45
|
+
# return negCnt.to_f/posCnt.to_f/minGR.to_f/(1-lcmq)
|
46
|
+
#end
|
47
|
+
|
48
|
+
#def calAlphaD(minSup,minGR,posCnt,negCnt,lcmq=0.5)
|
49
|
+
# return lcmq*minSup.to_f*negCnt.to_f/minGR.to_f/(1-lcmq)
|
50
|
+
#end
|
51
|
+
|
52
|
+
def initialize(db)
|
53
|
+
@temp=MCMD::Mtemp.new
|
54
|
+
@db = db # 入力データベース
|
55
|
+
@file=@temp.file
|
56
|
+
items=@db.items
|
57
|
+
|
58
|
+
# 重みファイルの作成
|
59
|
+
# pos,negのTransactionオブジェクトに対してLCMが扱う整数アイテムによるトランザクションファイルを生成する。
|
60
|
+
# この時、pos,negを併合して一つのファイルとして作成され(@wNumTraFile)、
|
61
|
+
# 重みファイル(@weightFile[クラス])の作成は以下の通り。
|
62
|
+
# 1.対象クラスをpos、その他のクラスをnegとする。
|
63
|
+
# 2. negの重みは-1に設定し、posの重みはcalOmegaで計算した値。
|
64
|
+
# 3.@wNumTraFileの各行のクラスに対応した重みデータを出力する(1項目のみのデータ)。
|
65
|
+
@weightFile = Hash.new
|
66
|
+
@posWeight = Hash.new
|
67
|
+
@sigma = Hash.new
|
68
|
+
@db.clsNameRecSize.each {|cName,posSize|
|
69
|
+
@weightFile[cName] = @temp.file
|
70
|
+
@posWeight[cName]=calOmega(posSize)
|
71
|
+
|
72
|
+
f=""
|
73
|
+
f << "mcut -nfno f=#{@db.clsFN} i=#{@db.cFile} |"
|
74
|
+
f << "mchgstr -nfn f=0 c=#{cName}:#{@posWeight[cName]} O=-1 o=#{@weightFile[cName]}"
|
75
|
+
system(f)
|
76
|
+
}
|
77
|
+
|
78
|
+
# アイテムをシンボルから番号に変換する。
|
79
|
+
f=""
|
80
|
+
f << "msortf f=#{@db.itemFN} i=#{@db.file} |"
|
81
|
+
f << "mjoin k=#{@db.itemFN} K=#{items.itemFN} m=#{items.file} f=#{items.idFN} |"
|
82
|
+
f << "mcut f=#{@db.idFN},#{@db.timeFN},#{items.idFN} |"
|
83
|
+
f << "msortf f=#{@db.idFN},#{@db.timeFN}%n |"
|
84
|
+
f << "mtra k=#{@db.idFN} f=#{items.idFN} |"
|
85
|
+
f << "mcut f=#{items.idFN} -nfno o=#{@file}"
|
86
|
+
system(f)
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def enumerate(eArgs)
|
91
|
+
tf=MCMD::Mtemp.new
|
92
|
+
|
93
|
+
# 最小サポートと最小サポート件数
|
94
|
+
if eArgs["minCnt"] then
|
95
|
+
@minCnt = eArgs["minCnt"].to_i
|
96
|
+
@minSup = @minCnt.to_f / @db.size.to_f
|
97
|
+
else
|
98
|
+
@minSup = eArgs["minSup"].to_f
|
99
|
+
@minCnt = (@minSup * @db.size.to_f + 0.99).to_i
|
100
|
+
end
|
101
|
+
|
102
|
+
# 最大サポートと最大サポート件数
|
103
|
+
@maxCnt=nil
|
104
|
+
if eArgs["maxCnt"] or eArgs["maxSup"] then
|
105
|
+
if eArgs["maxCnt"] then
|
106
|
+
@maxCnt = eArgs["maxCnt"].to_i
|
107
|
+
@maxSup = @maxCnt.to_f / @db.size.to_f
|
108
|
+
else
|
109
|
+
@maxSup = eArgs["maxSup"].to_f
|
110
|
+
@maxCnt = (@maxSup * @db.size.to_f + 0.99).to_i
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
#@minProb = eArgs["minProb"].to_f # 事後確率
|
115
|
+
#@minGR = @minProb/(1-@minProb) # 増加率
|
116
|
+
#@minGR = eArgs["minGR"].to_f if eArgs["minGR"]
|
117
|
+
|
118
|
+
# あるクラスをpos、他のクラスをnegにして、パターン列挙した結果ファイル名を格納する
|
119
|
+
pFiles=[]
|
120
|
+
tFiles=[]
|
121
|
+
@db.clsNameRecSize.each{|cName,posSize|
|
122
|
+
negSize=@db.size-posSize
|
123
|
+
|
124
|
+
# minGRの計算
|
125
|
+
if eArgs["minGR"] then
|
126
|
+
@minGR=eArgs["minGR"]
|
127
|
+
else
|
128
|
+
minProb=0.5
|
129
|
+
minProb=eArgs["minProb"] if eArgs["minProb"]
|
130
|
+
if eArgs["uniform"] then
|
131
|
+
@minGR = (minProb/(1-minProb)) * (@db.clsSize-1) # マニュアルの式(4)
|
132
|
+
else
|
133
|
+
@minGR = (minProb/(1-minProb)) * (negSize.to_f/posSize.to_f) # マニュアルの式(4)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# 最小サポートと最小サポート件数
|
138
|
+
if eArgs["minCnt"] then
|
139
|
+
@minPos = eArgs["minCnt"]
|
140
|
+
else
|
141
|
+
@minPos = (eArgs["minSup"] * posSize.to_f + 0.99).to_i
|
142
|
+
end
|
143
|
+
|
144
|
+
# 最大サポートと最大サポート件数
|
145
|
+
if eArgs["maxCnt"] or eArgs["maxSup"] then
|
146
|
+
if eArgs["maxCnt"] then
|
147
|
+
@maxCnt = eArgs["maxCnt"].to_i
|
148
|
+
else
|
149
|
+
@maxCnt = (eArgs["maxSup"] * posSize.to_f + 0.99).to_i
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
@sigma[cName] = calSigma(@minPos,@minGR,posSize,negSize)
|
154
|
+
|
155
|
+
# lcm_seqのパラメータ設定と実行
|
156
|
+
lcmout = tf.file # lcm_seq出力ファイル
|
157
|
+
# 頻出パターンがなかった場合、lcm出力ファイルが生成されないので
|
158
|
+
# そのときのために空ファイルを生成しておいく。
|
159
|
+
system("touch #{lcmout}")
|
160
|
+
|
161
|
+
run="CIA"
|
162
|
+
run << " -U #{@maxCnt}" if @maxCnt # windowサイズ上限
|
163
|
+
run << " -l #{eArgs['minLen']}" if eArgs["minLen"] # パターンサイズ下限
|
164
|
+
run << " -u #{eArgs['maxLen']}" if eArgs['maxLen'] # パターンサイズ上限
|
165
|
+
run << " -g #{eArgs['gap']}" if eArgs['gap'] # gap上限
|
166
|
+
run << " -G #{eArgs['win']}" if eArgs['win'] # windowサイズ上限
|
167
|
+
run << " -w #{@weightFile[cName]} #{@file} #{@sigma[cName]} #{lcmout}"
|
168
|
+
|
169
|
+
# lcm_seq実行
|
170
|
+
MCMD::msgLog("#{run}")
|
171
|
+
if eArgs['padding'] # padding指定時は、0アイテムを出力しないlcm_seqを実行
|
172
|
+
TAKE::run_lcmseq_zero(run)
|
173
|
+
else
|
174
|
+
TAKE::run_lcmseq(run)
|
175
|
+
end
|
176
|
+
#system run
|
177
|
+
|
178
|
+
# パターンのサポートを計算しCSV出力する
|
179
|
+
MCMD::msgLog("output patterns to CSV file ...")
|
180
|
+
pFiles << @temp.file
|
181
|
+
transle = @temp.file
|
182
|
+
TAKE::run_lcmtrans(lcmout,"e",transle)
|
183
|
+
f=""
|
184
|
+
#f << "lcm_trans #{lcmout} e |" # pattern,countP,countN,size,pid
|
185
|
+
f << "mdelnull f=pattern i=#{transle} |"
|
186
|
+
f << "mcal c='round(${countN},1)' a=neg |"
|
187
|
+
f << "mcal c='round(${countP}/#{@posWeight[cName]},1)' a=pos |"
|
188
|
+
f << "mdelnull f=pattern |"
|
189
|
+
f << "msetstr v=#{cName} a=class |"
|
190
|
+
f << "msetstr v=#{posSize} a=posTotal |"
|
191
|
+
f << "msetstr v=#{@minGR} a=minGR |"
|
192
|
+
f << "mcut f=class,pid,pattern,size,pos,neg,posTotal,minGR o=#{pFiles.last}"
|
193
|
+
system(f)
|
194
|
+
|
195
|
+
s = MCMD::mrecount("i=#{pFiles.last}") # 列挙されたパターンの数
|
196
|
+
MCMD::msgLog("the number of contrast patterns on class `#{cName}' enumerated is #{s}")
|
197
|
+
|
198
|
+
# トランザクション毎に出現するシーケンスを書き出す
|
199
|
+
MCMD::msgLog("output tid-patterns ...")
|
200
|
+
tFiles << @temp.file
|
201
|
+
|
202
|
+
xxw= tf.file
|
203
|
+
f=""
|
204
|
+
f << "mcut f=#{@db.idFN} i=#{@db.file} |"
|
205
|
+
f << "muniq k=#{@db.idFN} |"
|
206
|
+
f << "mnumber S=0 a=__tid -q|"
|
207
|
+
f << "msortf f=__tid o=#{xxw}"
|
208
|
+
system(f)
|
209
|
+
translt = @temp.file
|
210
|
+
TAKE::run_lcmtrans(lcmout,"t",translt)
|
211
|
+
|
212
|
+
f=""
|
213
|
+
#f << "lcm_trans #{lcmout} t |" #__tid,pid
|
214
|
+
f << "msortf f=__tid i=#{translt} |"
|
215
|
+
f << "mjoin k=__tid m=#{xxw} f=#{@db.idFN} |"
|
216
|
+
f << "msetstr v=#{cName} a=class |"
|
217
|
+
f << "mcut f=#{@db.idFN},class,pid o=#{tFiles.last}"
|
218
|
+
system(f)
|
219
|
+
}
|
220
|
+
|
221
|
+
# クラス別のパターンとtid-pidファイルを統合して最終出力
|
222
|
+
@pFile = @temp.file
|
223
|
+
@tFile = @temp.file
|
224
|
+
|
225
|
+
# パターンファイル併合
|
226
|
+
xxpCat = tf.file
|
227
|
+
f=""
|
228
|
+
f << "mcat i=#{pFiles.join(",")} |"
|
229
|
+
f << "msortf f=class,pid |"
|
230
|
+
f << "mnumber s=class,pid S=0 a=ppid o=#{xxpCat}"
|
231
|
+
system(f)
|
232
|
+
|
233
|
+
# パターンファイル計算
|
234
|
+
items=@db.items
|
235
|
+
f=""
|
236
|
+
f << "mcut f=class,ppid:pid,pattern,size,pos,neg,posTotal,minGR i=#{xxpCat} |"
|
237
|
+
f << "msetstr v=#{@db.size} a=total |" # トータル件数
|
238
|
+
f << "mcal c='${total}-${posTotal}' a=negTotal |" # negのトータル件数
|
239
|
+
f << "mcal c='${pos}/${posTotal}' a=support |" # サポートの計算
|
240
|
+
f << "mcal c='if(${neg}==0,1.797693135e+308,(${pos}/${posTotal})/(${neg}/${negTotal}))' a=growthRate |"
|
241
|
+
|
242
|
+
if eArgs["uniform"] then
|
243
|
+
f << "mcal c='(${pos}/${posTotal})/(${pos}/${posTotal}+(#{@db.clsSize}-1)*${neg}/${negTotal})' a=postProb |"
|
244
|
+
else
|
245
|
+
f << "mcal c='${pos}/(${pos}+${neg})' a=postProb |"
|
246
|
+
end
|
247
|
+
f << "msel c='${pos}>=#{@minPos}&&${growthRate}>=${minGR}' |" # minSupとminGRによる選択
|
248
|
+
f << "mvreplace vf=pattern m=#{items.file} K=#{items.idFN} f=#{items.itemFN} |"
|
249
|
+
f << "mcut f=class,pid,pattern,size,pos,neg,posTotal,negTotal,total,support,growthRate,postProb |"
|
250
|
+
f << "mvsort vf=pattern |"
|
251
|
+
f << "msortf f=class%nr,postProb%nr,pos%nr o=#{@pFile}"
|
252
|
+
system(f)
|
253
|
+
|
254
|
+
# 列挙されたパターンを含むtraのみ選択するためのマスタ
|
255
|
+
xxp4=tf.file
|
256
|
+
f=""
|
257
|
+
f << "mcut f=class,pid i=#{@pFile} |"
|
258
|
+
f << "msortf f=class,pid o=#{xxp4}"
|
259
|
+
system(f)
|
260
|
+
|
261
|
+
# tid-pidファイル計算
|
262
|
+
f=""
|
263
|
+
f << "mcat i=#{tFiles.join(",")} |"
|
264
|
+
f << "msortf f=class,pid |"
|
265
|
+
f << "mjoin k=class,pid m=#{xxpCat} f=ppid |" # 全クラス統一pid(ppid)結合
|
266
|
+
f << "msortf f=class,ppid |"
|
267
|
+
f << "mcommon k=class,ppid K=class,pid m=#{xxp4} |" # 列挙されたパターンの選択
|
268
|
+
f << "mcut f=#{@db.idFN},class,ppid:pid |"
|
269
|
+
f << "msortf f=#{@db.idFN},class,pid o=#{@tFile}"
|
270
|
+
system(f)
|
271
|
+
|
272
|
+
@size = MCMD::mrecount("i=#{@pFile}") # 列挙されたパターンの数
|
273
|
+
MCMD::msgLog("the number of emerging sequence patterns enumerated is #{@size}")
|
274
|
+
end
|
275
|
+
|
276
|
+
def output(outpath)
|
277
|
+
system "mv #{@pFile} #{outpath}/patterns.csv"
|
278
|
+
system "mv #{@tFile} #{outpath}/tid_pats.csv"
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
end #module
|
283
|
+
|
284
|
+
|
@@ -0,0 +1,275 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
require "rubygems"
|
4
|
+
require "nysol/mcmd"
|
5
|
+
|
6
|
+
require "nysol/zdd"
|
7
|
+
require "nysol/take"
|
8
|
+
require "nysol/traDB.rb"
|
9
|
+
|
10
|
+
module TAKE
|
11
|
+
|
12
|
+
#========================================================================
|
13
|
+
# 列挙関数:lcm 利用DB:TraDB
|
14
|
+
#========================================================================
|
15
|
+
class LcmIs
|
16
|
+
attr_reader :size # 列挙されたパターン数
|
17
|
+
attr_reader :pFile
|
18
|
+
attr_reader :tFile
|
19
|
+
|
20
|
+
|
21
|
+
def reduceTaxo(pat,items)
|
22
|
+
tf=MCMD::Mtemp.new
|
23
|
+
|
24
|
+
if items.taxonomy==nil then
|
25
|
+
return pat
|
26
|
+
end
|
27
|
+
|
28
|
+
xxrt = tf.file
|
29
|
+
taxo=items.taxonomy
|
30
|
+
f=""
|
31
|
+
f << "mtrafld f=#{taxo.itemFN},#{taxo.taxoFN} -valOnly a=__fld i=#{taxo.file} o=#{xxrt}"
|
32
|
+
system(f)
|
33
|
+
|
34
|
+
# xxrtの内容:oyakoに親子関係にあるアイテム集合のリストが格納される
|
35
|
+
# __fld
|
36
|
+
# A X
|
37
|
+
# B X
|
38
|
+
# C Y
|
39
|
+
# D Z
|
40
|
+
# E Z
|
41
|
+
# F Z
|
42
|
+
oyako=ZDD.constant(0)
|
43
|
+
MCMD::Mcsvin.new("i=#{xxrt}"){|csv|
|
44
|
+
csv.each{|fldVal|
|
45
|
+
items=fldVal["__fld"]
|
46
|
+
oyako=oyako+ZDD.itemset(items)
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
# 親子リストにあるアイテム集合を含むパターンを削除する
|
51
|
+
pat=pat.restrict(oyako).iif(0,pat)
|
52
|
+
|
53
|
+
return pat
|
54
|
+
end
|
55
|
+
|
56
|
+
def initialize(db)
|
57
|
+
@temp=MCMD::Mtemp.new
|
58
|
+
@db = db # 入力データベース
|
59
|
+
@file=@temp.file
|
60
|
+
items=@db.items
|
61
|
+
|
62
|
+
# アイテムをシンボルから番号に変換する。
|
63
|
+
f=""
|
64
|
+
f << "msortf f=#{@db.itemFN} i=#{@db.file} |"
|
65
|
+
f << "mjoin k=#{@db.itemFN} K=#{items.itemFN} m=#{items.file} f=#{items.idFN} |"
|
66
|
+
f << "mcut f=#{@db.idFN},#{items.idFN} |"
|
67
|
+
f << "msortf f=#{@db.idFN} |"
|
68
|
+
f << "mtra k=#{@db.idFN} f=#{items.idFN} |"
|
69
|
+
f << "mcut f=#{items.idFN} -nfno o=#{@file}"
|
70
|
+
system(f)
|
71
|
+
end
|
72
|
+
|
73
|
+
def enumerate(eArgs)
|
74
|
+
tf=MCMD::Mtemp.new
|
75
|
+
|
76
|
+
@type = eArgs["type"]
|
77
|
+
|
78
|
+
# 最小サポートと最小サポート件数
|
79
|
+
if eArgs["minCnt"] then
|
80
|
+
@minCnt = eArgs["minCnt"].to_i
|
81
|
+
@minSup = @minCnt.to_f / @db.size.to_f
|
82
|
+
else
|
83
|
+
@minSup = eArgs["minSup"].to_f
|
84
|
+
@minCnt = (@minSup * @db.size.to_f + 0.99).to_i
|
85
|
+
end
|
86
|
+
|
87
|
+
# 最大サポートと最大サポート件数
|
88
|
+
@maxCnt=nil
|
89
|
+
if eArgs["maxCnt"] or eArgs["maxSup"] then
|
90
|
+
if eArgs["maxCnt"] then
|
91
|
+
@maxCnt = eArgs["maxCnt"].to_i
|
92
|
+
@maxSup = @maxCnt.to_f / @db.size.to_f
|
93
|
+
else
|
94
|
+
@maxSup = eArgs["maxSup"].to_f
|
95
|
+
@maxCnt = (@maxSup * @db.size.to_f + 0.99).to_i
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# lcmのパラメータ設定と実行
|
100
|
+
#run=""
|
101
|
+
#run << "#{CMD} #{@type}If"
|
102
|
+
#run << " -U #{@maxCnt}" if @maxCnt # windowサイズ上限
|
103
|
+
#run << " -l #{eArgs['minLen']}" if eArgs["minLen"] # パターンサイズ下限
|
104
|
+
#run << " -u #{eArgs['maxLen']}" if eArgs['maxLen'] # パターンサイズ上限
|
105
|
+
|
106
|
+
run=""
|
107
|
+
run << "#{@type}If"
|
108
|
+
run << " -U #{@maxCnt}" if @maxCnt # windowサイズ上限
|
109
|
+
run << " -l #{eArgs['minLen']}" if eArgs["minLen"] # パターンサイズ下限
|
110
|
+
run << " -u #{eArgs['maxLen']}" if eArgs['maxLen'] # パターンサイズ上限
|
111
|
+
|
112
|
+
|
113
|
+
# 列挙パターン数上限が指定されれば、一度lcmを実行して最小サポートを得る
|
114
|
+
@top = eArgs["top"]
|
115
|
+
if(@top and @top>0) then
|
116
|
+
xxtop = tf.file
|
117
|
+
|
118
|
+
TAKE::run_lcmK("#{run} -K #{@top} #{@file} 1 #{xxtop}")
|
119
|
+
# system("#{run} -K #{@top} #{@file} 1 > #{xxtop}")
|
120
|
+
File.open(xxtop,"r"){|fpr| @minCnt=fpr.gets().to_i}
|
121
|
+
@minCnt=1 if @minCnt<0
|
122
|
+
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
# lcm_seq出力ファイル
|
127
|
+
lcmout = tf.file
|
128
|
+
# 頻出パターンがなかった場合、lcm出力ファイルが生成されないので
|
129
|
+
# そのときのために空ファイルを生成しておいく。
|
130
|
+
system("touch #{lcmout}")
|
131
|
+
|
132
|
+
# lcm実行
|
133
|
+
MCMD::msgLog("#{run} #{@file} #{@minCnt} #{lcmout}")
|
134
|
+
|
135
|
+
TAKE::run_lcm("#{run} #{@file} #{@minCnt} #{lcmout}")
|
136
|
+
#system("#{run} #{@file} #{@minCnt} #{lcmout}")
|
137
|
+
|
138
|
+
# caliculate one itemset for lift value
|
139
|
+
xxone= tf.file
|
140
|
+
TAKE::run_lcm("FIf -l 1 -u 1 #{@file} 1 #{xxone}")
|
141
|
+
#system("#{CMD} FIf -l 1 -u 1 #{@file} 1 #{xxone}")
|
142
|
+
|
143
|
+
# パターンのサポートを計算しCSV出力する
|
144
|
+
MCMD::msgLog("output patterns to CSV file ...")
|
145
|
+
xxp0=tf.file
|
146
|
+
@pFile = @temp.file
|
147
|
+
items=@db.items
|
148
|
+
trans0 = @temp.file
|
149
|
+
TAKE::run_lcmtrans(lcmout,"p",trans0)
|
150
|
+
|
151
|
+
f=""
|
152
|
+
# f << "lcm_trans #{lcmout} p |" # pattern,count,size,pid
|
153
|
+
f << "mdelnull f=pattern i=#{trans0} |"
|
154
|
+
f << "mvreplace vf=pattern m=#{items.file} K=#{items.idFN} f=#{items.itemFN} |"
|
155
|
+
f << "msetstr v=#{@db.size} a=total |" # トータル件数
|
156
|
+
f << "mcal c='${count}/${total}' a=support |" # サポートの計算
|
157
|
+
f << "mcut f=pid,pattern,size,count,total,support |"
|
158
|
+
f << "mvsort vf=pattern |"
|
159
|
+
f << "msortf f=pid o=#{xxp0}"
|
160
|
+
system(f)
|
161
|
+
# xxp0
|
162
|
+
# pid,count,total,support,pattern
|
163
|
+
# 0,13,13,1,A
|
164
|
+
# 4,6,13,0.4615384615,A B
|
165
|
+
|
166
|
+
xxp1=tf.file
|
167
|
+
# taxonomy指定がない場合(2010/11/20追加)
|
168
|
+
if items.taxonomy==nil then
|
169
|
+
FileUtils.mv(xxp0, xxp1)
|
170
|
+
|
171
|
+
# taxonomy指定がある場合
|
172
|
+
else
|
173
|
+
MCMD::msgLog("reducing redundant rules in terms of taxonomy ...")
|
174
|
+
zdd=ZDD.constant(0)
|
175
|
+
MCMD::Mcsvin.new("i=#{xxp0}"){|csv|
|
176
|
+
csv.each{|fldVal|
|
177
|
+
pat=fldVal['pattern']
|
178
|
+
zdd=zdd+ZDD.itemset(pat)
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
zdd=reduceTaxo(zdd,@db.items)
|
183
|
+
xxz1=tf.file
|
184
|
+
xxz2=tf.file
|
185
|
+
zdd.csvout(xxz1)
|
186
|
+
f=""
|
187
|
+
f << "mcut -nfni f=1:pattern i=#{xxz1} |"
|
188
|
+
f << "mvsort vf=pattern |"
|
189
|
+
f << "msortf f=pattern o=#{xxz2}"
|
190
|
+
system(f)
|
191
|
+
|
192
|
+
f=""
|
193
|
+
f << "msortf f=pattern i=#{xxp0} |"
|
194
|
+
f << "mcommon k=pattern m=#{xxz2} |"
|
195
|
+
f << "msortf f=pid o=#{xxp1}"
|
196
|
+
system(f)
|
197
|
+
end
|
198
|
+
|
199
|
+
# lift値の計算
|
200
|
+
xxp2=tf.file
|
201
|
+
|
202
|
+
transl = tf.file
|
203
|
+
|
204
|
+
TAKE::run_lcmtrans(xxone,"p",transl)
|
205
|
+
|
206
|
+
f=""
|
207
|
+
# f << "lcm_trans #{xxone} p |" # pattern,count,size,pid
|
208
|
+
f << "mdelnull f=pattern i=#{transl} |"
|
209
|
+
f << "mvreplace vf=pattern m=#{items.file} K=#{items.idFN} f=#{items.itemFN} |"
|
210
|
+
f << "msortf f=pattern o=#{xxp2}"
|
211
|
+
system(f)
|
212
|
+
|
213
|
+
xxp3=tf.file
|
214
|
+
f=""
|
215
|
+
f << "mcut f=pid,pattern i=#{xxp1} |"
|
216
|
+
f << "mtra f=pattern -r |"
|
217
|
+
f << "msortf f=pattern |"
|
218
|
+
f << "mjoin k=pattern m=#{xxp2} f=count:c1 |"
|
219
|
+
f << "mcal c='ln(${c1})' a=c1ln |"
|
220
|
+
f << "msortf f=pid |"
|
221
|
+
f << "msum k=pid f=c1ln o=#{xxp3}"
|
222
|
+
system(f)
|
223
|
+
|
224
|
+
# p3
|
225
|
+
# pid,pattern,c1,c1ln
|
226
|
+
# 0,A,13,2.564949357
|
227
|
+
# 1,E,7,1.945910149
|
228
|
+
f=""
|
229
|
+
f << "mjoin k=pid m=#{xxp3} f=c1ln i=#{xxp1} |"
|
230
|
+
f << "mcal c='round(exp(ln(${count})-${c1ln}+(${size}-1)*ln(${total})),0.0001)' a=lift |"
|
231
|
+
f << "mcut f=pid,size,count,total,support,lift,pattern |"
|
232
|
+
f << "msortf f=support%nr o=#{@pFile}"
|
233
|
+
system(f)
|
234
|
+
|
235
|
+
@size = MCMD::mrecount("i=#{@pFile}") # 列挙されたパターンの数
|
236
|
+
MCMD::msgLog("the number of patterns enumerated is #{@size}")
|
237
|
+
|
238
|
+
# トランザクション毎に出現するシーケンスを書き出す
|
239
|
+
MCMD::msgLog("output tid-patterns ...")
|
240
|
+
@tFile = @temp.file
|
241
|
+
|
242
|
+
xxw1= tf.file
|
243
|
+
f=""
|
244
|
+
f << "mcut f=#{@db.idFN} i=#{@db.file} |"
|
245
|
+
f << "muniq k=#{@db.idFN} |"
|
246
|
+
f << "mnumber S=0 a=__tid -q |"
|
247
|
+
f << "msortf f=__tid o=#{xxw1}"
|
248
|
+
system(f)
|
249
|
+
|
250
|
+
xxw2= tf.file
|
251
|
+
f=""
|
252
|
+
f << "mcut f=pid i=#{@pFile} |"
|
253
|
+
f << "msortf f=pid o=#{xxw2}"
|
254
|
+
system(f)
|
255
|
+
|
256
|
+
xxw3 = tf.file
|
257
|
+
TAKE::run_lcmtrans(lcmout,"t",xxw3)
|
258
|
+
f=""
|
259
|
+
# f << "lcm_trans #{lcmout} t |" #__tid,pid
|
260
|
+
f << "msortf f=pid i=#{xxw3} |"
|
261
|
+
f << "mcommon k=pid m=#{xxw2} |"
|
262
|
+
f << "msortf f=__tid |"
|
263
|
+
f << "mjoin k=__tid m=#{xxw1} f=#{@db.idFN} |"
|
264
|
+
f << "mcut f=#{@db.idFN},pid o=#{@tFile}"
|
265
|
+
system(f)
|
266
|
+
end
|
267
|
+
|
268
|
+
def output(outpath)
|
269
|
+
system "mv #{@pFile} #{outpath}/patterns.csv"
|
270
|
+
system "mv #{@tFile} #{outpath}/tid_pats.csv"
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
end #module
|
275
|
+
|
@@ -0,0 +1,143 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
require "rubygems"
|
4
|
+
require "nysol/mcmd"
|
5
|
+
require "nysol/take"
|
6
|
+
require "nysol/seqDB.rb"
|
7
|
+
|
8
|
+
module TAKE
|
9
|
+
|
10
|
+
#========================================================================
|
11
|
+
# 列挙関数:lcmseq 利用DB:SeqDB
|
12
|
+
#========================================================================
|
13
|
+
class LcmSeq
|
14
|
+
attr_reader :size # 列挙されたパターン数
|
15
|
+
|
16
|
+
def initialize(db)
|
17
|
+
@temp=MCMD::Mtemp.new
|
18
|
+
@db = db # 入力データベース
|
19
|
+
@file=@temp.file
|
20
|
+
items=@db.items
|
21
|
+
|
22
|
+
# アイテムをシンボルから番号に変換する。
|
23
|
+
f=""
|
24
|
+
f << "msortf f=#{@db.itemFN} i=#{@db.file} |"
|
25
|
+
f << "mjoin k=#{@db.itemFN} K=#{items.itemFN} m=#{items.file} f=#{items.idFN} |"
|
26
|
+
f << "mcut f=#{@db.idFN},#{@db.timeFN},#{items.idFN} |"
|
27
|
+
f << "msortf f=#{@db.idFN},#{@db.timeFN}%n |"
|
28
|
+
f << "mtra k=#{@db.idFN} s=#{@db.timeFN}%n f=#{items.idFN} |"
|
29
|
+
f << "mcut f=#{items.idFN} -nfno o=#{@file}"
|
30
|
+
system(f)
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def enumerate(eArgs)
|
35
|
+
tf=MCMD::Mtemp.new
|
36
|
+
|
37
|
+
# 最小サポートと最小サポート件数
|
38
|
+
if eArgs["minCnt"] then
|
39
|
+
@minCnt = eArgs["minCnt"].to_i
|
40
|
+
@minSup = @minCnt.to_f / @db.size.to_f
|
41
|
+
else
|
42
|
+
@minSup = eArgs["minSup"].to_f
|
43
|
+
@minCnt = (@minSup * @db.size.to_f + 0.99).to_i
|
44
|
+
end
|
45
|
+
|
46
|
+
# 最大サポートと最大サポート件数
|
47
|
+
@maxCnt=nil
|
48
|
+
if eArgs["maxCnt"] or eArgs["maxSup"] then
|
49
|
+
if eArgs["maxCnt"] then
|
50
|
+
@maxCnt = eArgs["maxCnt"].to_i
|
51
|
+
@maxSup = @maxCnt.to_f / @db.size.to_f
|
52
|
+
else
|
53
|
+
@maxSup = eArgs["maxSup"].to_f
|
54
|
+
@maxCnt = (@maxSup * @db.size.to_f + 0.99).to_i
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# 列挙パターン数上限が指定されれば、一度lcmを実行して最小サポートを得る
|
59
|
+
@top = eArgs["top"]
|
60
|
+
if(@top and @top>0) then
|
61
|
+
xxtop = tf.file
|
62
|
+
TAKE::run_lcmseqK("Cf -K #{@top} #{@file} 1 #{xxtop}")
|
63
|
+
#system("#{CMD} Cf -K #{@top} #{@file} 1 > #{xxtop}")
|
64
|
+
File.open(xxtop,"r"){|fpr| @minCnt=fpr.gets().to_i}
|
65
|
+
@minCnt=1 if @minCnt<0
|
66
|
+
end
|
67
|
+
|
68
|
+
# lcm_seq出力ファイル
|
69
|
+
lcmout = tf.file
|
70
|
+
# 頻出パターンがなかった場合、lcm出力ファイルが生成されないので
|
71
|
+
# そのときのために空ファイルを生成しておいく。
|
72
|
+
system("touch #{lcmout}")
|
73
|
+
|
74
|
+
# lcm_seqのパラメータ設定と実行
|
75
|
+
run="CIf"
|
76
|
+
run << " -U #{@maxCnt}" if @maxCnt # windowサイズ上限
|
77
|
+
run << " -l #{eArgs['minLen']}" if eArgs["minLen"] # パターンサイズ下限
|
78
|
+
run << " -u #{eArgs['maxLen']}" if eArgs['maxLen'] # パターンサイズ上限
|
79
|
+
run << " -g #{eArgs['gap']}" if eArgs['gap'] # gap上限
|
80
|
+
run << " -G #{eArgs['win']}" if eArgs['win'] # windowサイズ上限
|
81
|
+
run << " #{@file} #{@minCnt} #{lcmout}"
|
82
|
+
|
83
|
+
# lcm_seq実行
|
84
|
+
MCMD::msgLog("#{run}")
|
85
|
+
|
86
|
+
if eArgs['padding'] # padding指定時は、0アイテムを出力しないlcm_seqを実行
|
87
|
+
TAKE::run_lcmseq_zero(run)
|
88
|
+
else
|
89
|
+
TAKE::run_lcmseq(run)
|
90
|
+
end
|
91
|
+
#system run
|
92
|
+
|
93
|
+
# パターンのサポートを計算しCSV出力する
|
94
|
+
@pFile = @temp.file
|
95
|
+
items=@db.items
|
96
|
+
|
97
|
+
transl = @temp.file
|
98
|
+
TAKE::run_lcmtrans(lcmout,"p",transl)
|
99
|
+
|
100
|
+
f=""
|
101
|
+
#f << "lcm_trans #{lcmout} p |" # pattern,count,size,pid
|
102
|
+
f << "mdelnull f=pattern i=#{transl} |"
|
103
|
+
f << "mvreplace vf=pattern m=#{items.file} K=#{items.idFN} f=#{items.itemFN} |"
|
104
|
+
f << "msetstr v=#{@db.size} a=total |" # トータル件数
|
105
|
+
f << "mcal c=\'${count}/${total}\' a=support |" # サポートの計算
|
106
|
+
f << "mcut f=pid,pattern,size,count,total,support |"
|
107
|
+
f << "msortf f=support%nr o=#{@pFile}"
|
108
|
+
system(f)
|
109
|
+
|
110
|
+
# トランザクション毎に出現するシーケンスを書き出す
|
111
|
+
MCMD::msgLog("output tid-patterns ...")
|
112
|
+
@tFile = @temp.file
|
113
|
+
|
114
|
+
xxw = tf.file #Mtemp.new.name
|
115
|
+
f=""
|
116
|
+
f << "mcut f=#{@db.idFN} i=#{@db.file} |"
|
117
|
+
f << "muniq k=#{@db.idFN} |"
|
118
|
+
f << "mnumber S=0 a=__tid -q |"
|
119
|
+
f << "msortf f=__tid o=#{xxw}"
|
120
|
+
system(f)
|
121
|
+
|
122
|
+
translt = @temp.file
|
123
|
+
TAKE::run_lcmtrans(lcmout,"t",translt)
|
124
|
+
|
125
|
+
f=""
|
126
|
+
# f << "lcm_trans #{lcmout} t |" #__tid,pid
|
127
|
+
f << "msortf f=__tid i=#{translt} |"
|
128
|
+
f << "mjoin k=__tid m=#{xxw} f=#{@db.idFN} |"
|
129
|
+
f << "mcut f=#{@db.idFN},pid |"
|
130
|
+
f << "msortf f=#{@db.idFN},pid o=#{@tFile}"
|
131
|
+
system(f)
|
132
|
+
|
133
|
+
@size = MCMD::mrecount("i=#{@pFile}") # 列挙されたパターンの数
|
134
|
+
MCMD::msgLog("the number of contrast patterns enumerated is #{@size}")
|
135
|
+
end
|
136
|
+
|
137
|
+
def output(outpath)
|
138
|
+
system "mv #{@pFile} #{outpath}/patterns.csv"
|
139
|
+
system "mv #{@tFile} #{outpath}/tid_pats.csv"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end #module
|