有理數加法的幾種設計: 結果回傳或覆蓋 vs 類別或物件方法
(1) public static Rational add(Ratinoal r1, Rational r2)
// 用法: Rational r3 = Rational.add(r1,r2); // r3=r1+r2
(2) public static void add(Ratinoal r1, Rational r2)
// 用法: Rational.add(r1,r2); // r1=r1+r2
(3) public Rational add(Rational r2)
// 用法: Rational r3 = r1.add(r2); // r3=r1+r2
(4) public void add(Rational r2)
// 用法: r1.add(r2); // r1=r1+r2
four kinds of design for adding operation of two rationals
Canonical Weighted Sum (CWS) Gates for Simplifying Bayesian Network Inference
decampos-10-ijar-combining content-based and collaborative recommendations- a hybrid approach based on bayesian networks
The following will explain the examples in pp793-794 of the paper.
Assume that I and F nodes in the bayesian network are binary random variables.
If the set of parent nodes of node I6 is Pa(I6) = { F6, F7, F8},
then the 8 possible configurations of conditional joint probabilities are
pa1(I6) = (f6,1 & f7,1 & f8,1)
pa2(I6) = (f6,0 & f7,1 & f8,1)
pa3(I6) = (f6,1 & f7,0 & f8,1)
pa4(I6) = (f6,1 & f7,1 & f8,0)
pa5(I6) = (f6,0 & f7,0 & f8,1)
pa6(I6) = (f6,0 & f7,1 & f8,0)
pa7(I6) = (f6,1 & f7,0 & f8,0)
pa8(I6) = (f6,0 & f7,0 & f8,0)
By use of Canonical Weighted Sum (CWS) Gates, which consist of 2x2x3=12 weights,
computation of 16 conditional joint probabilities (having 8 degrees of freedom)
can be decomposed into the summation of 12 weights (having 3 degrees of freedom):
w(f6,1&i6,1) = w(f6,0&i6,0) = 0.3
w(f7,1&i6,1) = w(f7,0&i6,0) = 0.4
w(f8,1&i6,1) = w(f8,0&i6,0) = 0.3
and
w(f6,1&i6,0) = w(f6,0&i6,1) = 0
w(f7,1&i6,0) = w(f7,0&i6,1) = 0
w(f8,1&i6,0) = w(f8,0&i6,1) = 0
Pr(i6,0 | pa1(I6))= Pr(i6,0 | f6,1 & f7,1 & f8,1) = w(f6,1&i6,0) + w(f7,1&i6,0) + w(f8,1&i6,0) = 0
Pr(i6,1 | pa1(I6))= Pr(i6,1 | f6,1 & f7,1 & f8,1) = w(f6,1&i6,1) + w(f7,1&i6,1) + w(f8,1&i6,1) = 0.3 + 0.4 + 0.3 = 1
Pr(i6,0 | pa2(I6))= Pr(i6,0 | f6,0 & f7,1 & f8,1) = w(f6,0&i6,0) + w(f7,1&i6,0) + w(f8,1&i6,0) = 0.3
Pr(i6,1 | pa2(I6))= Pr(i6,1 | f6,0 & f7,1 & f8,1) = w(f6,0&i6,1) + w(f7,1&i6,1) + w(f8,1&i6,1) = 0 + 0.4 + 0.3 = 0.7
Pr(i6,0 | pa3(I6))= Pr(i6,0 | f6,1 & f7,0 & f8,1) = w(f6,1&i6,0) + w(f7,0&i6,0) + w(f8,1&i6,0) = 0.4
Pr(i6,1 | pa3(I6))= Pr(i6,1 | f6,1 & f7,0 & f8,1) = w(f6,1&i6,1) + w(f7,0&i6,1) + w(f8,1&i6,1) = 0.3 + 0 + 0.3 = 0.6
Pr(i6,0 | pa4(I6))= Pr(i6,0 | f6,1 & f7,1 & f8,0) = w(f6,1&i6,0) + w(f7,1&i6,0) + w(f8,0&i6,0) = 0.3
Pr(i6,1 | pa4(I6))= Pr(i6,1 | f6,1 & f7,1 & f8,0) = w(f6,1&i6,1) + w(f7,1&i6,1) + w(f8,0&i6,1) = 0.3 + 0.4 + 0 = 0.7
Pr(i6,0 | pa5(I6))= Pr(i6,0 | f6,0 & f7,0 & f8,1) = w(f6,0&i6,0) + w(f7,0&i6,0) + w(f8,1&i6,0) = 0.3 + 0.4 = 0.7
Pr(i6,1 | pa5(I6))= Pr(i6,1 | f6,0 & f7,0 & f8,1) = w(f6,0&i6,1) + w(f7,0&i6,1) + w(f8,1&i6,1) = 0 + 0 + 0.3 = 0.3
Pr(i6,0 | pa6(I6))= Pr(i6,0 | f6,0 & f7,1 & f8,0) = w(f6,0&i6,0) + w(f7,1&i6,0) + w(f8,0&i6,0) = 0.3 + 0 + 0.3 = 0.6
Pr(i6,1 | pa6(I6))= Pr(i6,1 | f6,0 & f7,1 & f8,0) = w(f6,0&i6,1) + w(f7,1&i6,1) + w(f8,0&i6,1) = 0 + 0.4 + 0 = 0.4
Pr(i6,0 | pa7(I6))= Pr(i6,0 | f6,1 & f7,0 & f8,0) = w(f6,1&i6,0) + w(f7,0&i6,0) + w(f8,0&i6,0) = 0 + 0.4 + 0.3 = 0.7
Pr(i6,1 | pa7(I6))= Pr(i6,1 | f6,1 & f7,0 & f8,0) = w(f6,1&i6,1) + w(f7,0&i6,1) + w(f8,0&i6,1) = 0.3 + 0 + 0 = 0.3
Pr(i6,0 | pa8(I6))= Pr(i6,0 | f6,0 & f7,0 & f8,0) = w(f6,0&i6,0) + w(f7,0&i6,0) + w(f8,0&i6,0) = 0.3 + 0.4 + 0.3 = 1
Pr(i6,1 | pa8(I6))= Pr(i6,1 | f6,0 & f7,0 & f8,0) = w(f6,0&i6,1) + w(f7,0&i6,1) + w(f8,0&i6,1) = 0
1 = Pr(i6,0 | pa(I6)) + Pr(i6,1 | pa(I6))
= w(f6,1&i6,0) + w(f7,1&i6,0) + w(f8,1&i6,0) + w(f6,1&i6,1) + w(f7,1&i6,1) + w(f8,1&i6,1) = 1
============================
Given Pa(U4) = { I1, I3, I6, I7, I8, I10 } with six-value (0,1,~,5) random variable U,
the network consists of 2x6x6=72 weights.
By the following 12 nonzero weights having 6 degrees of freedom (with all other weights being 0):
w(i1,1&u4,1) = w(i3,1&u4,1) = w(i6,1&u4,2) = w(i7,1&u4,1) = w(i8,1&u4,3) = w(i10,1&u4,5) = 0.166
and
w(i1,0&u4,0) = w(i3,0&u4,0) = w(i6,0&u4,0) = w(i7,0&u4,0) = w(i8,0&u4,0) = w(i10,0&u4,0) = 0.166
we can compute any Pr(U4 | pa(U4)) conditional probabilities by summation of the 12 nonzero weights.
(1) pa(U4) = { i1,1 & i3,1 & i6,1 & i7,1 & i8,1 & i10,1 }
Pr(u4,0 | pa(U4)) = w(i1,1&u4,0) + w(i3,1&u4,0) + w(i6,1&u4,0) + w(i7,1&u4,0) + w(i8,1&u4,0) + w(i10,1&u4,0)
= 0 + 0 + 0 + 0 + 0 + 0
= 0
Pr(u4,1 | pa(U4)) = w(i1,1&u4,1) + w(i3,1&u4,1) + w(i6,1&u4,1) + w(i7,1&u4,1) + w(i8,1&u4,1) + w(i10,1&u4,1)
= 0.166 + 0.166 + 0 + 0.166 + 0 + 0
= 0.5
Pr(u4,2 | pa(U4)) = w(i1,1&u4,2) + w(i3,1&u4,2) + w(i6,1&u4,2) + w(i7,1&u4,2) + w(i8,1&u4,2) + w(i10,1&u4,2)
= 0 + 0 + 0.166 + 0 + 0 + 0
= 0.166
Pr(u4,3 | pa(U4)) = w(i1,1&u4,3) + w(i3,1&u4,3) + w(i6,1&u4,3) + w(i7,1&u4,3) + w(i8,1&u4,3) + w(i10,1&u4,3)
= 0 + 0 + 0 + 0 + 0.166 + 0
= 0.166
Pr(u4,4 | pa(U4)) = w(i1,1&u4,4) + w(i3,1&u4,4) + w(i6,1&u4,4) + w(i7,1&u4,4) + w(i8,1&u4,4) + w(i10,1&u4,4)
= 0 + 0 + 0 + 0 + 0 + 0
= 0
Pr(u4,5 | pa(U4)) = w(i1,1&u4,5) + w(i3,1&u4,5) + w(i6,1&u4,5) + w(i7,1&u4,5) + w(i8,1&u4,5) + w(i10,1&u4,5)
= 0 + 0 + 0 + 0 + 0 + 0.166
= 0.166
1 = Pr(u4,1 | pa(U4)) + Pr(u4,2 | pa(U4)) + Pr(u4,3 | pa(U4)) + Pr(u4,4 | pa(U4)) + Pr(u4,5 | pa(U4))
= 0.5 + 0.166 + 0.166 + 0 + 0.166
(2) pa(U4) = { i1,0 & i3,0 & i6,1 & i7,1 & i8,0 & i10,0 }
Pr(u4,0 | pa(U4)) = w(i1,0&u4,0) + w(i3,0&u4,0) + w(i6,1&u4,0) + w(i7,1&u4,0) + w(i8,0&u4,0) + w(i10,0&u4,0)
= 0.166 + 0.166 + 0 + 0 + 0.166 + 0.166
= 0.666
Pr(u4,1 | pa(U4)) = w(i1,0&u4,1) + w(i3,0&u4,1) + w(i6,1&u4,1) + w(i7,1&u4,1) + w(i8,0&u4,1) + w(i10,0&u4,1)
= 0 + 0 + 0 + 0.166 + 0 + 0
= 0.166
Pr(u4,2 | pa(U4)) = w(i1,0&u4,2) + w(i3,0&u4,2) + w(i6,1&u4,2) + w(i7,1&u4,2) + w(i8,0&u4,2) + w(i10,0&u4,2)
= 0 + 0 + 0.166 + 0 + 0 + 0
= 0.166
Pr(u4,3 | pa(U4)) = w(i1,0&u4,3) + w(i3,0&u4,3) + w(i6,1&u4,3) + w(i7,1&u4,3) + w(i8,0&u4,3) + w(i10,0&u4,3)
= 0 + 0 + 0 + 0 + 0 + 0
= 0
Pr(u4,4 | pa(U4)) = w(i1,0&u4,4) + w(i3,0&u4,4) + w(i6,1&u4,4) + w(i7,1&u4,4) + w(i8,0&u4,4) + w(i10,0&u4,4)
= 0 + 0 + 0 + 0 + 0 + 0
= 0
Pr(u4,5 | pa(U4)) = w(i1,0&u4,5) + w(i3,0&u4,5) + w(i6,1&u4,5) + w(i7,1&u4,5) + w(i8,0&u4,5) + w(i10,0&u4,5)
= 0 + 0 + 0 + 0 + 0 + 0
= 0
1 = Pr(u4,1 | pa(U4)) + Pr(u4,2 | pa(U4)) + Pr(u4,3 | pa(U4)) + Pr(u4,4 | pa(U4)) + Pr(u4,5 | pa(U4))
= 0.666 + 0.166 + 0.166 + 0 + 0
============================
Suppose that Acf = A4 or user 4.
Given Pa(Acf) = { Ux, Uy, Uz } with with six-value (0,1,~,5) random variable Acf,
the network consists of 6x6x3=108 weights.
By the following ? nonzero weights having ? degrees of freedom (with all other weights being 0):
w(ux,5&acf,4) = 0.54
w(uy,1&acf,4) = 0.15
w(uz,4&acf,4) = 0.09
and
w(ux,0&acf,0) = 0.6
w(uy,0&acf,0) = 0.3
w(uz,0&acf,0) = 0.1
we can compute any Pr(Acf | pa(Acf)) conditional probabilities by summation of the ? nonzero weights.
(1) pa(Acf) = { ux,5 & uy,1 & uz,4 }
Pr(acf,4 | pa(U4)) = w(ux,5&acf,4) + w(uy,1&acf,4) + w(uz,4&acf,4)
= RSim(Ux,Acf) * Pr(A=4|Ux=5) + RSim(Uy,Acf) * Pr(A=4|Uy=1) + RSim(Uz,Acf) * Pr(A=4|Uz=4)
= 0.6 * 0.9 + 0.3 * 0.5 + 0.1 * 0.9
= 0.78
(2) pa(Acf) = { ux,0 & uy,1 & uz,4 }
Pr(acf,4 | pa(U4)) = w(ux,0&acf,4) + w(uy,1&acf,4) + w(uz,4&acf,4)
= 0 + RSim(Uy,Acf) * Pr(A=4|Uy=1) + RSim(Uz,Acf) * Pr(A=4|Uz=4)
= 0 + 0.3 * 0.5 + 0.1 * 0.9
= 0.24
(3) pa(Acf) = { ux,0 & uy,1 & uz,4 }
Pr(acf,0 | pa(U4)) = w(ux,0&acf,0) + w(uy,1&acf,0) + w(uz,4&acf,0)
= RSim(Ux,Acf) + 0 + 0
= 0.6 + 0 + 0
= 0.6
why object-oriented programming provides encapsulation, inheritance, and polymorphism
一般完整的物件導向語言提供封裝、繼承、多型三大功能,允許以合成或繼承方式建構新物件。 其中,封裝(encapsulation)旨在保護私密資料的安全、完整性,其存取唯有透過公開的屬性存取(窗口)或運算方法達成之。 合成(composition)是一種利用物件建構物件的方法,物件之間的擁有(has-a)關係可形成階層樹狀圖。 繼承(inheritance)旨在提供新用舊的機制,讓後代需要用到親代原來的屬性及方法時,直接沿用,不必重造車輪。 繼承也是一種利用物件建構物件的方法,物件之間的屬於(is-a)關係可形成階層樹狀圖。 多型(polymorphism)旨在繼承架構下提供舊用新的機制,讓親代也有機會用到後代創新的新行為、新功能。
find the unique second smallest number in excel
一般 Excel 找最小或最大值可以使用 MIN(range) 或 MAX(range)函數,其中,range表示儲存格範圍。 如果想要找第2小或第2大也可以使用 SMALL(range, 2) 或 LARGE(range, 2),其中,2表示順序第2。 但是以找最小為例,有時候遇到第1小及第2小值一樣,就看不出值分布情形。若希望能看到不同值的第2小數字,可以使用如下函數:
= SMALL(range, COUNTIF(range, MIN(range)) + 1)
其中, SMALL(range, n) 可回傳 range 範圍內順序第 n 小的數字。 COUNTIF(range, MIN(range)) 可回傳 range 範圍內符合最小值的儲存格個數。 此個數加1之後,即為不同值第2小數字之順序。 因此可餵給 SMALL 函數,回傳不同值第2小數字出來。
至於不同值第3或第n小數字,可能就需要更複雜的 FREQUENCY 陣列函數或自己寫巨集計算了。
how to retrieve access-denied files in an old disk drive
系統掛載舊硬碟之後,因原始身份別不同,常有權限不符,無法讀取現象
--
因為目錄常啟用繼承上一層目錄的權限,因此比較省事的方法就是
找到最上一層開始出現讀不到的共通目錄,由此設定Everyone完全控制
其餘子層目錄根據繼承就會沿用Everyone完全控制
--
目錄/內容/安全性/進階/
權限:按[停用繼承],選[從此物件中移除所有繼承權限]
新增/允許/Everyone/完全控制/繼承自無/套用到這個資料夾、子資料夾及檔案
勾選[以可從此物件繼承的權限項目取代所有子物件的權限項目(P)]
選[套用]
擁有者:變更
請輸入物件名稱來選取(E): Everyone
檢查名稱
確定
勾選[取代子容器與物件的擁有者]
選[套用]
--
目錄檔案權限:各符合身份之帳號權限的最寬鬆集合
分享權限:各符合身份之帳號權限的最寬鬆集合
最終權限: 兩者之最嚴謹集合
three kinds of traffic segmentation functions on a switch
企業在區網內會使用較高階的交換器,主要看重其3種分隔流量的功能:
- 針對1對1單播訊框 (unicast frame),可依照訊框的去處網卡住址,又稱媒介存取控制 (mac) 住址,決定訊框將轉送到交換器的哪一個出口,以提升交換器同時間的會談 (session) 數量。
- 針對1對多廣播訊框 (broadcast frame),可依照延伸樹 STP 協定,決定交換器的哪一個連接埠 (switch port) 須暫時性開啟或關閉傳送功能,以防止廣播風暴 (broadcast storm)。
- 擁有虛擬區網 VLAN 功能,可跨越互連的交換器,將訊框轉送給所有相同 VLAN 的接收者,不擔心資料會外洩給其他 VLAN 用戶看到。
以上相關功能可參考下文進一步說明:
Example of Converting Taiwan Skills Certification Test Bank for Moodle Use
勞動部技術士技能檢定學科題庫轉成moodle平台試題法
如果想利用Moodle平台的測驗卷功能練習技術士檢定學科題目,
必須先將題庫轉成Aiken純文字格式,才能匯入平台開測驗卷。
本方法只適用純文字單選題,不適用含圖形之題目。
用到的軟體工具有一般瀏覽器、微軟Word、UltraEdit、微軟記事本。
其轉換步驟如下:
A.下載檢定題目
從如下題庫網址,
勞動部技術士檢定學科題庫
http://www.labor.gov.tw/home.jsp?pageno=201109290020
選擇適當級別及科目之學科題目,格式為.pdf。
B.轉換題目檔案格式
利用如下線上轉檔網址,
Convert PDF to Word (Free!)
http://www.pdfonline.com/pdf-to-word-converter/
將題目從.pdf格式還原為.rtf格式。
C.轉換題目為Big5純文字檔
從微軟Word軟體,
先用常用/取代功能,作如下1,2,3,4選項的字串取代,
"①" 替換為 "A. "
"②" 替換為 "B. "
"③" 替換為 "C. "
"④" 替換為 "D. "
再用另存新檔功能,
將.rtf格式轉換為.txt純文字格式。
例如:
1. (2) 在 OSI 7 層協定中「網路硬體協定」,屬於以下哪一層?①網路層(Network)②實體層(Physical)③應用層 (Application)④傳輸層(Transport)。
變成:
1. (2) 在 OSI 7 層協定中「網路硬體協定」,屬於以下哪一層?A. 網路層(Network)B. 實體層(Physical)C. 應用層 (Application)D. 傳輸層(Transport)。
D.調整題目內容符合Aiken格式
利用UltraEdit的如下正規式功能
UltraEdit/Search/Replace/Regular_Expressions
逐步調整欄位相關內容:
D1.每個選項獨立為一行
"A. " 替換為 "^pA. "
"B. " 替換為 "^pB. "
"C. " 替換為 "^pC. "
"D. " 替換為 "^pD. "
說明:
^p表示換行字元
例如:
1. (2) 在 OSI 7 層協定中「網路硬體協定」,屬於以下哪一層?A. 網路層(Network)B. 實體層(Physical)C. 應用層 (Application)D. 傳輸層(Transport)。
變成:
1. (2) 在 OSI 7 層協定中「網路硬體協定」,屬於以下哪一層?
A. 網路層(Network)
B. 實體層(Physical)
C. 應用層 (Application)
D. 傳輸層(Transport)。
D2.擷取答案1,2,3,4
"%[0-9]+.*(^([1-4]^))" 替換為 "ANSWER: ^1 ^p"
說明:
%表示行開頭,[0-9]+表示1個以上由0~9任一字元組成的字串,
.*表示任意字元數的字串,[1-4]表示1~4任一字元,
^(.....^)表示擷取.....範圍內的字串,^1表示代入匹配擷取成功的第1組字串。
例如:
1. (2) 在 OSI 7 層協定中「網路硬體協定」,屬於以下哪一層?
變成:
ANSWER: 2
在 OSI 7 層協定中「網路硬體協定」,屬於以下哪一層?
D3.調整答案欄位到題目之後
"%^(ANSWER: [A-D]^)^p ^(?*^pA.?*^pB.?*^pC.?*^pD.?*^)$"
替換為
"^2^p^1"
說明:
%表示行開頭,$表示行結尾,[A-D]表示A~D任一字元,^p表示換行字元,
^(.....^)表示擷取.....範圍內的字串,
^1表示代入匹配擷取成功的第1組字串,^2表示代入匹配擷取成功的第2組字串。
例如:
ANSWER: 2
在 OSI 7 層協定中「網路硬體協定」,屬於以下哪一層?
A. 網路層(Network)
B. 實體層(Physical)
C. 應用層 (Application)
D. 傳輸層(Transport)。
變成:
在 OSI 7 層協定中「網路硬體協定」,屬於以下哪一層?
A. 網路層(Network)
B. 實體層(Physical)
C. 應用層 (Application)
D. 傳輸層(Transport)。
ANSWER: 2
E.存成UTF-8格式
利用記事本讀入修改題庫,另存新檔成UTF-8格式。
F.匯入moodle平台
利用moodle的[課程管理/題庫/匯入]選單,選擇Aiken格式,選擇一檔案,匯入。
再為題庫設定階層類型的名稱,供後續出試題之用。
參考:
1. UltraEdit 正規式說明:
http://www.ultraedit.com/support/tutorials_power_tips/ultraedit/regular_expressions.html
2. Moodle載入題庫及出試題說明:
http://budamedia.blogspot.tw/2014/12/moodle.html
cache-based memory access time
mchoes-11-cengage-understanding operating systems, 6ed.
上述課本第3章提到快取記憶體時,有計算平均記憶體存取時間(AvgMemAccessTime)的公式。其中變數包含
- 快取命中率 (h)
- 快取存取時間 (AvgCacheAccessTime)
- 主記憶體存取時間 (AvgMainMemAccTime)
(1)當假設CPU取用記憶體前,採用一律先詢問快取記憶體,若沒有再詢問主記憶體的循序作法時, 則所花時間依下式計算,可簡化為課本式子。 AvgMemAccessTime = h * AvgCacheAccessTime + (1-h) * [AvgCacheAccessTime + AvgMainMemAccTime] = AvgCacheAccessTime + (1-h) * AvgMainMemAccTime (2)當假設CPU取用記憶體前,採用快取記憶體及主記憶體兩者同時詢問,看誰先回覆的並行作法時, 則所花時間依下式計算,即為如下式子。 AvgMemAccessTime = h * AvgCacheAccessTime + (1-h) * AvgMainMemAccTime 雖然課本提到兩種作法都可能採用,但是多數為第1種循序作法,故建議用課本式子計算。
How to Save and Load a Model in Weka for Training and Testing
Two Weka Command Line Examples of Using Models in Training and Testing:
(1) train and save an OneR model
load and test an OneR model
both using the weather.nominal.arff dataset
(2) train and save a FilteredClassifier (StringToWordVector + J48) model
load and test a FilteredClassifier (StringToWordVector + J48) model
using the crude_oil_train.arff dataset for training
and the crude_oil_test.arff dataset for testing
#-------------------------------
#ask for classifiers options
>java -cp weka.jar weka.classifiers.rules.OneR -h -info
Help requested.
General options:
-h or -help
Output help information.
-synopsis or -info
Output synopsis for classifier (use in conjunction with -h)
-t <name of training file>
Sets training file.
-T <name of test file>
Sets test file. If missing, a cross-validation will be performed
on the training data.
-c <class index>
Sets index of class attribute (default: last).
-x <number of folds>
Sets number of folds for cross-validation (default: 10).
-no-cv
Do not perform any cross validation.
-split-percentage <percentage>
Sets the percentage for the train/test set split, e.g., 66.
-preserve-order
Preserves the order in the percentage split.
-s <random number seed>
Sets random number seed for cross-validation or percentage split
(default: 1).
-m <name of file with cost matrix>
Sets file with cost matrix.
-l <name of input file>
Sets model input file. In case the filename ends with '.xml',
a PMML file is loaded or, if that fails, options are loaded
from the XML file.
-d <name of output file>
Sets model output file. In case the filename ends with '.xml',
only the options are saved to the XML file, not the model.
-v
Outputs no statistics for training data.
-o
Outputs statistics only, not the classifier.
-i
Outputs detailed information-retrieval statistics for each class.
-k
Outputs information-theoretic statistics.
-p <attribute range>
Only outputs predictions for test instances (or the train
instances if no test instances provided and -no-cv is used),
along with attributes (0 for none).
-distribution
Outputs the distribution instead of only the prediction
in conjunction with the '-p' option (only nominal classes).
-r
Only outputs cumulative margin distribution.
-z <class name>
Only outputs the source representation of the classifier,
giving it the supplied name.
-xml filename | xml-string
Retrieves the options from the XML-data instead of the command line.
-threshold-file <file>
The file to save the threshold data to.
The format is determined by the extensions, e.g., '.arff' for ARFF
format or '.csv' for CSV.
-threshold-label <label>
The class label to determine the threshold data for
(default is the first label)
Options specific to weka.classifiers.rules.OneR:
-B <minimum bucket size>
The minimum number of objects in a bucket (default: 6).
Synopsis for weka.classifiers.rules.OneR: # synopsis is shown with -info option
Class for building and using a 1R classifier; in other words, uses the minimum-error attribute for prediction, discretizing numeric attributes. For more information, see:
R.C. Holte (1993). Very simple classification rules perform well on most commonly used datasets. Machine Learning. 11:63-91.
#---------------------------------------------------------
# Example (1): use OneR to train and test on weather.nominal.arff
#train classifier by train_data and output model without evaluation
>java -cp weka.jar weka.classifiers.rules.OneR \
> -t data/weather.nominal.arff -no-cv -v -d model.dat
outlook:
sunny -> no
overcast -> yes
rainy -> yes
(10/14 instances correct)
=== Error on training data === # this report not shown with -v option
Correctly Classified Instances 10 71.4286 %
.....
=== Stratified cross-validation === # this report not shown with -no-cv option
Correctly Classified Instances 6 42.8571 %
.....
#load model and test classifier by test_data
>java -cp weka.jar weka.classifiers.rules.OneR \
> -T data/weather.nominal.arff -l model.dat
outlook:
sunny -> no
overcast -> yes
rainy -> yes
(10/14 instances correct)
=== Error on test data ===
Correctly Classified Instances 10 71.4286 %
Incorrectly Classified Instances 4 28.5714 %
Kappa statistic 0.3778
Mean absolute error 0.2857
Root mean squared error 0.5345
Total Number of Instances 14
=== Confusion Matrix ===
a b <-- classified as
7 2 | a = yes
2 3 | b = no
>java -cp weka.jar weka.classifiers.rules.OneR \
> -T data/weather.nominal.arff -l model.dat -p first-last
=== Predictions on test data ===
inst# actual predicted error prediction (outlook,temperature,humidity,windy)
1 2:no 2:no 1 (sunny,hot,high,FALSE)
2 2:no 2:no 1 (sunny,hot,high,TRUE)
3 1:yes 1:yes 1 (overcast,hot,high,FALSE)
4 1:yes 1:yes 1 (rainy,mild,high,FALSE)
5 1:yes 1:yes 1 (rainy,cool,normal,FALSE)
6 2:no 1:yes + 1 (rainy,cool,normal,TRUE)
7 1:yes 1:yes 1 (overcast,cool,normal,TRUE)
8 2:no 2:no 1 (sunny,mild,high,FALSE)
9 1:yes 2:no + 1 (sunny,cool,normal,FALSE)
10 1:yes 1:yes 1 (rainy,mild,normal,FALSE)
11 1:yes 2:no + 1 (sunny,mild,normal,TRUE)
12 1:yes 1:yes 1 (overcast,mild,high,TRUE)
13 1:yes 1:yes 1 (overcast,hot,normal,FALSE)
14 2:no 1:yes + 1 (rainy,mild,high,TRUE)
#--------------------------------------------------------------------
#Example (2): use FilteredClassifier (StringToWordVector + J48) to
# train on crude_oil_train.arff and test on crude_oil_test.arff
#train classifier by train_data and output model without evaluation
> java -cp weka.jar weka.classifiers.meta.FilteredClassifier \
> -no-cv -v -t data/crude_oil_train.arff -d model.dat \
> -F weka.filters.unsupervised.attribute.StringToWordVector \
> -W weka.classifiers.trees.J48
Options: -F weka.filters.unsupervised.attribute.StringToWordVector -W weka.classifiers.trees.J48
FilteredClassifier using weka.classifiers.trees.J48 -C 0.25 -M 2 on data filtered through weka.filters.unsupervised.attribute.StringToWordVector -R 1 -W 1000 -prune-rate -1.0 -N 0 -stemmer weka.core.stemmers.NullStemmer -M 1 -tokenizer "weka.core.tokenizers.WordTokenizer -delimiters \" \\r\\n\\t.,;:\\\'\\\"()?!\""
Filtered Header
@relation 'crude_oil_train-weka.filters.unsupervised.attribute.StringToWordVector-R1-W1000-prune-rate-1.0-N0-stemmerweka.core.stemmers.NullStemmer-M1-tokenizerweka.core.tokenizers.WordTokenizer -delimiters \" \\r\\n\\t.,;:\\\'\\\"()?!\"'
@attribute class {yes,no}
@attribute Crude numeric
@attribute Demand numeric
@attribute The numeric
@attribute crude numeric
@attribute for numeric
@attribute has numeric
@attribute in numeric
@attribute increased numeric
@attribute is numeric
@attribute of numeric
@attribute oil numeric
@attribute outstrips numeric
@attribute price numeric
@attribute short numeric
@attribute significantly numeric
@attribute supply numeric
@attribute Some numeric
@attribute Use numeric
@attribute a numeric
@attribute bit numeric
@attribute cooking numeric
@attribute do numeric
@attribute flavor numeric
@attribute food numeric
@attribute frying numeric
@attribute like numeric
@attribute not numeric
@attribute oily numeric
@attribute olive numeric
@attribute pan numeric
@attribute people numeric
@attribute the numeric
@attribute very numeric
@attribute was numeric
@data
Classifier Model
J48 pruned tree
------------------
crude <= 0: no (4.0/1.0)
crude > 0: yes (2.0)
Number of Leaves : 2
Size of the tree : 3
#load model and test classifier by test_data
> java -cp weka.jar weka.classifiers.meta.FilteredClassifier \
> -T data/crude_oil_test.arff -l model.dat -p first-last
=== Predictions on test data ===
inst# actual predicted error prediction (document)
1 1:yes 1:yes 1 ('Oil platforms extract crude oil')
2 2:no 2:no 0.75 ('Canola oil is supposed to be healthy')
3 1:yes 2:no + 0.75 ('Iraq has significant oil reserves')
4 2:no 2:no 0.75 ('There are different types of cooking oil')
> java -cp weka.jar weka.classifiers.meta.FilteredClassifier \
> -T data/crude_oil_test2.arff -l model.dat -p first-last
=== Predictions on test data ===
inst# actual predicted error prediction (document)
1 1:? 1:yes 1 ('Oil platforms extract crude oil')
2 1:? 2:no 0.75 ('Canola oil is supposed to be healthy')
3 1:? 2:no 0.75 ('Iraq has significant oil reserves')
4 1:? 2:no 0.75 ('There are different types of cooking oil')
######### data/weather.nominal.arff
@relation weather.symbolic
@attribute outlook {sunny, overcast, rainy}
@attribute temperature {hot, mild, cool}
@attribute humidity {high, normal}
@attribute windy {TRUE, FALSE}
@attribute play {yes, no}
@data
sunny,hot,high,FALSE,no
sunny,hot,high,TRUE,no
overcast,hot,high,FALSE,yes
rainy,mild,high,FALSE,yes
rainy,cool,normal,FALSE,yes
rainy,cool,normal,TRUE,no
overcast,cool,normal,TRUE,yes
sunny,mild,high,FALSE,no
sunny,cool,normal,FALSE,yes
rainy,mild,normal,FALSE,yes
sunny,mild,normal,TRUE,yes
overcast,mild,high,TRUE,yes
overcast,hot,normal,FALSE,yes
rainy,mild,high,TRUE,no
######### data/crude_oil_train.arff
%
% witten-12-mkp-data mining- practical machine learning tools and techniques
% ch17 tutorial exercises for the weka explorer
% ch17.5 document classification
%
%
@relation 'crude_oil_train'
%
@attribute document string
@attribute class {yes,no}
%
@data
'The price of crude oil has increased significantly',yes
'Demand for crude oil outstrips supply',yes
'Some people do not like the flavor of olive oil',no
'The food was very oily',no
'Crude oil is in short supply',yes
'Use a bit of cooking oil in the frying pan',no
######### data/crude_oil_test.arff
%
% witten-12-mkp-data mining- practical machine learning tools and techniques
% ch17 tutorial exercises for the weka explorer
% ch17.5 document classification
%
%
@relation 'crude_oil_test'
%
@attribute document string
@attribute class {yes,no}
%
@data
'Oil platforms extract crude oil',yes
'Canola oil is supposed to be healthy',no
'Iraq has significant oil reserves',yes
'There are different types of cooking oil',no
######### data/crude_oil_test2.arff
%
% witten-12-mkp-data mining- practical machine learning tools and techniques
% ch17 tutorial exercises for the weka explorer
% ch17.5 document classification
%
%
@relation 'crude_oil_test'
%
@attribute document string
@attribute class {yes,no}
%
@data
'Oil platforms extract crude oil',?
'Canola oil is supposed to be healthy',?
'Iraq has significant oil reserves',?
'There are different types of cooking oil',?
summary of graph algorithms
goodrich-15-wiley-data structures & algorithms in java
ch14.1 Graphs
‧圖(graph)由頂點(vertex)及邊(edge)組成。
‧頂點又稱節點(node),邊又稱弧(arc)。
‧依邊有方向與否分成有向邊(directed edge)及無向邊(undirected edge)。
‧圖若純由有向邊組成,稱為有向圖(directed graph, digraph)。
‧圖若純由無向邊組成,稱為無向圖(undirected graph)。
‧混合圖(mixed graph)的邊包含有向邊及無向邊。
‧每個邊有兩個端頂點(end vertices)或稱端點(endpoints)。
‧有向邊的端點又分成起點(origin)及終點(destination)。
‧若兩頂點為某邊的兩端點,稱兩頂點相鄰(adjacent)。
‧若頂點為邊的端點,稱邊接於(incident to)頂點。
‧頂點的去向邊(outgoing edge)包含所有以頂點為起點的有向邊。
‧頂點的來向邊(incoming edge)包含所有以頂點為終點的有向邊。
‧頂點的邊數(degree)為接於頂點的所有邊個數,
可細分成去向邊數(out-degree)及來向邊數(in-degree)。
‧存放圖的邊容器為收藏容器(collection),而非集合(set),
表示兩頂點可以有兩個以上的有向或無向邊相接,
稱為平行邊(parallel edges)或多重邊(multiple edges)。
‧若有向/無向邊的兩端點相同,稱邊為自我迴圈。
‧若圖不包含平行邊或自我迴圈,稱圖為簡單圖(simple graph),
簡單圖可用不允許重複的邊集合描述。
‧路徑(path)由一連串的頂點及邊交替組成,起源於某頂點,終止於某頂點,
串列中每個邊的起點為其前一個頂點,終點為其下一個頂點。
‧迴圈(cycle)為一路徑,其起點及終點為同一頂點,且至少有一個邊。
‧若路徑的每個頂點皆不同,稱為簡單路徑(simple path)。
‧若迴圈的每個頂點皆不同,起終兩頂點相同不算,稱為簡單迴圈(simple cycle)。
‧有向路徑(directed path)的每個邊皆為有向邊。
‧有向迴圈(directed cycle)的每個邊皆為有向邊。
‧無迴圈的有向圖(acyclic directed graph)不存在有向迴圈。
‧若存在頂點u到頂點v的路徑,稱u可到達v,或v可由u到達(reachable)。
‧無向圖的可到達性(reachability)具對稱性,即u可到達v等同v可達u,有向圖則否。
‧若圖的任兩頂點存在路徑相連,稱為連通圖(connected graph)。
‧若有向圖的任兩頂點存在雙向路徑相連,稱為強連通圖(strongly connected graph)。
‧圖G的子圖(subgraph)為一圖H,其頂點及邊分別為G的頂點及邊的子集合。
‧圖G的生成子圖(spanning subgraph)為G的子圖,包含G的所有頂點。
‧若圖G不連通,其最大連通子圖稱為G的連通組件(connected components)。
‧沒有迴圈的圖稱為森林(forest)。
‧樹(tree)為一連通森林,即沒有迴圈的連通圖。
‧圖的生成樹(spanning tree)為圖的生成子圖,本身也是樹。
ch14.2 Data Structures for Graphs
‧四種表現圖的資料結構
1.邊清單(edge list)
2.相鄰清單(adjacency list)
3.相鄰映射(adjacency map) <== 課本採用,可由點找邊,及邊找點
圖有頂點鏈結清單vertices,邊鏈結清單edges,及有向狀態isDirected
頂點記錄元素element,所處頂點鏈結清單位置pos,
去向邊的<頂點,邊>映射表outgoing,
來向邊的<頂點,邊>映射表incoming,
註:有向圖outgoing及incoming才不同,無向圖兩者一樣
邊記錄元素element,所處邊鏈結清單位置pos,及兩端頂點endpoints
4.相鄰矩陣(adjacency matrix)
14.3 Graph Traversals
‧圖走訪(graph traversal)基本上在作圖轉樹的工作,
可產生走訪樹(search tree),回答有關頂點間可到達性問題。
其困難點在如何有效率的檢視圖的所有頂點及邊,
最好花費的時間能和頂點數及邊數成線性正比。
‧無向圖的可到達性問題:
1.給定圖形G頂點u,v,若到得了,找出u到v的任一條路徑
2.給定圖形G頂點u,若到得了,找出u到每個頂點v的路徑,路徑的邊數需最少
3.給定圖形G,判定所有頂點是否相連
4.給定圖形G,若存在,找出G的任一迴圈
*5.給定連通圖形G,找出任一G的生成樹
*6.給定圖形G,找出所有連通組件(最大相連子圖).
註: 無向圖走訪樹的邊分類:
樹幹邊(tree edge): 尋獲邊(discovery edge)
非樹幹邊(nontree edge): 後退邊(back edge), 跨越邊(cross edge)
‧有向圖的可到達性問題
1.給定圖形G頂點u,v,若到得了,找出u到v的任一條有向路徑
2.給定圖形G頂點u,列出所有u可到達頂點
3.給定圖形G,判定G是否強相連
4.給定圖形G,判定有無迴圈
註: 有向圖走訪樹的邊分類:
樹幹邊: 尋獲邊
非樹幹邊: 後退邊, 前進邊(forward edge), 跨越邊
‧兩種最基本的圖走訪法:
1.深度優先走訪(depth-first search)
2.寬度優先走訪(breadth-first search)
GraphAlgorithms.DFS(g, u, known, forest)
從圖 g 的頂點 u 出發,建立深度優先走訪樹,
回傳走訪頂點 known,走訪頂點的尋獲邊 forest
GraphAlgorithms.DFSComplete(g)
回傳圖 g 的深度優先走訪森林,其走訪頂點的尋獲邊 forest
GraphAlgorithms.BFS(g, u, known, forest)
從圖 g 的頂點 u 出發,建立寬度優先走訪樹,
回傳走訪頂點 known,走訪頂點的尋獲邊 forest
GraphAlgorithms.BFSComplete(g)
回傳圖 g 的深度優先走訪森林,其走訪頂點的尋獲邊 forest
GraphAlgorithms.constructPath(g, u, v, forest)
從圖 g 的走訪樹森林 forest
回傳頂點 u 到 v 的路徑 (由路徑沿途的邊組成)
訂閱:
文章 (Atom)
Disable UDP to solve frequent RDP disconnection
解決 RDP 遠端桌面經常斷線問題:「關閉 UDP 傳輸」 在使用 Windows 內建的 遠端桌面(RDP, Remote Desktop Protocol) 連線時,你是否也常遇到連線突然卡死、畫面凍結,或是頻繁跳出「連線已中...