weka.classifiers.bayes.BayesNet

weka.classifiers.bayes.BayesNet 為貝氏網路學習器,
可克服屬性之間相關性,學得貝氏網路結構及其機率表,以進行類別預測。
若遇數值屬性,將先進行離散化後再學習。

參數說明:
 -B <BIF file> 供結構比對之用的貝氏網路描述檔,副檔名.bif。預設無。

 -D  不要使用ADTree資料結構,較省記憶體,但跑較慢。預設使用,較耗記憶體,但跑較快。

 -Q <weka.classifiers.bayes.net.search.searchAlgorithm> 結構學習演算法。
    -- 條件獨立法
     weka.classifiers.bayes.net.search.ci.CISearchAlgorithm
     weka.classifiers.bayes.net.search.ci.ICSSearchAlgorithm
    -- 採用固定結構
     weka.classifiers.bayes.net.search.fixed.FromFile  外部檔案結構
     weka.classifiers.bayes.net.search.fixed.NaiveBayes  簡單貝氏結構
    -- 全域法,-S LOO-CV 預設值表示選用留一法交叉驗證決定好壞
     weka.classifiers.bayes.net.search.global.GeneticSearch
     weka.classifiers.bayes.net.search.global.HillClimber
     weka.classifiers.bayes.net.search.global.K2
     weka.classifiers.bayes.net.search.global.SimulatedAnnealing
     weka.classifiers.bayes.net.search.global.TabuSearch
     weka.classifiers.bayes.net.search.global.TAN
    -- 區域法,-S BAYES 預設值表示選用Bayes評分指標決定好壞
     weka.classifiers.bayes.net.search.local.GeneticSearch
     weka.classifiers.bayes.net.search.local.HillClimber
     weka.classifiers.bayes.net.search.local.K2 (-P 1 表示親節點個數限制1個)
     weka.classifiers.bayes.net.search.local.SimulatedAnnealing
     weka.classifiers.bayes.net.search.local.TabuSearch
     weka.classifiers.bayes.net.search.local.TAN
     預設值weka.classifiers.bayes.net.search.local.K2。

 -E <weka.classifiers.bayes.net.estimate.estimateAlgorithm> 機率表學習演算法。
     weka.classifiers.bayes.net.estimate.BayesNetEstimator
     weka.classifiers.bayes.net.estimate.BMAEstimator
     weka.classifiers.bayes.net.estimate.MultinomialBMAEstimator
     weka.classifiers.bayes.net.estimate.SimpleEstimator (-A 0.5 表示初始機率值0.5)
     預設值weka.classifiers.bayes.net.estimate.SimpleEstimator。


>java -cp weka.jar;. weka.classifiers.bayes.BayesNet -t data\weather.nominal.arff
    -D 
    -Q weka.classifiers.bayes.net.search.local.K2 -- -P 1 -S BAYES 
    -E weka.classifiers.bayes.net.estimate.SimpleEstimator -- -A 0.5

Options: -D -Q weka.classifiers.bayes.net.search.local.K2 -- -P 1 -S BAYES -E weka.classifiers.bayes.net.estimate.SimpleEstimator -- -A 0.5


Bayes Network Classifier
not using ADTree
#attributes=5 #classindex=4
Network structure (nodes followed by parents)
outlook(3): play
temperature(3): play
humidity(2): play
windy(2): play
play(2):
LogScore Bayes: -69.07317135664013
LogScore BDeu: -83.46880542273107
LogScore MDL: -82.71568504897063
LogScore ENTROPY: -65.56181240647145
LogScore AIC: -78.56181240647145


Time taken to build model: 0.02 seconds Time taken to test model on training data: 0 seconds === Error on training data === Correctly Classified Instances 13 92.8571 % Incorrectly Classified Instances 1 7.1429 % Kappa statistic 0.8372 Mean absolute error 0.2615 Root mean squared error 0.3242 Relative absolute error 56.3272 % Root relative squared error 67.6228 % Total Number of Instances 14 === Confusion Matrix === a b <-- classified as 9 0 | a = yes 1 4 | b = no === Stratified cross-validation === Correctly Classified Instances 8 57.1429 % Incorrectly Classified Instances 6 42.8571 % Kappa statistic -0.0244 Mean absolute error 0.415 Root mean squared error 0.4909 Relative absolute error 87.1501 % Root relative squared error 99.5104 % Total Number of Instances 14 === Confusion Matrix === a b <-- classified as 7 2 | a = yes 4 1 | b = no 如下 weather.nominal.arff 案例集的14個案例有9個yes、5個no。
outlook temperature humidity windy play
sunny hot high FALSE no
sunny hot high TRUE no
rainy cool normal TRUE no
sunny mild high FALSE no
rainy mild high TRUE no
overcast hot high FALSE yes
rainy mild high FALSE yes
rainy cool normal FALSE yes
overcast cool normal TRUE yes
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
參考: 1.weka.classifiers.bayes.BayesNet code | doc 2.weka.classifiers.bayes.net.search code | doc 3.weka.classifiers.bayes.net.estimate code | doc

how to build an osm map server for taiwan on docker

最近集眾人智慧的開放街圖(OpenStreetMap)很熱門,以下介紹一個簡便架設台灣區 OSM 地圖伺服器的方法。
前提是需先安裝 docker 容器環境,例如: Windows 10 上安裝 docker for windows 容器軟體。
有了 docker 容器環境之後,取圖資及架網站的步驟如下:

0.主機打開命令列工具,例如: Windows 10 的 powershell 命令列工具。


以下分成手動及自動安裝兩種說明,手動說明方便理解安裝步驟,自動說明方便快速安裝。

A.【手動安裝法】以下利用原始映像檔,手動建立新映像檔taiwan-osmbright:v1

1.主機下載 dmakan/ubuntu-opentileserver:v1 原始映像檔,啟動容器命名 twbright
    > docker pull dmakan/ubuntu-opentileserver:v1
    > docker run -t -i -p 80:80 --name twbright dmakan/ubuntu-opentileserver:v1
    註: -t for terminal, -i for interactive 表示取得容器的終端機互動視窗,可用 Ctrl-p Ctrl-q 退回主機
    註: -p host_port:container:port for port mapping 先主機埠,後容器埠,可將容器埠對應到主機埠,對外提供服務

2.容器修改 opentileserver.sh 批次檔,讓資料庫接受 utf8 文字編碼
    # vi /opentileserver/opentileserver.sh

    原始 if [ $(psql -Upostgres -c "select datname from pg_database" | grep -m 1 -c ${OSM_DB}) -eq 0 ]; then
    之前新增一行 psql -Upostgres -c "DROP DATABASE IF EXISTS ${OSM_DB};"

    原始 psql -Upostgres -c "create database ${OSM_DB} owner=${OSM_USER};"
    修改 psql -Upostgres -c "CREATE DATABASE ${OSM_DB} TEMPLATE template0 ENCODING 'UTF8' OWNER ${OSM_USER};"

    原始 CREATE EXTENSION hstore;
    修改 CREATE EXTENSION IF NOT EXISTS hstore;

    原始 CREATE EXTENSION postgis;
    修改 CREATE EXTENSION IF NOT EXISTS postgis;

    註: 要先刪除原有資料庫,再重新建立一個接受 utf8 統一碼的資料庫
    註: OSM_USER 預設資料庫用戶名為 tile,OSM_DB 預設資料庫名稱為 gis

3.容器執行 opentileserver.sh 批次檔,下載套件及圖資
    # cd /opentileserver/
    # ./opentileserver.sh web bright http://download.geofabrik.de/asia/taiwan-latest.osm.pbf

    註: 紅色州名/國名可替換成任何想提供服務的國家,詳http://download.geofabrik.de/
    註: geofabrik每日更新一次圖資,只要再執行 opentileserver.sh 批次檔,就重新下載最新圖資,覆寫原有資料庫內容

4.容器修改 OSMBright.xml 樣式檔,讓形狀檔路徑正確
   利用串流修改指令sed進行字串取代
    # sed -ie 's/pulated_places/pulated_places_simple/g' /usr/local/share/maps/style/OSMBright/OSMBright.xml

   或者利用編輯器vi進行修改
    # vi /usr/local/share/maps/style/OSMBright/OSMBright.xml

    原始 <Parameter name="file">
          <![CDATA[/usr/local/share/maps/style/osm-bright-master/shp/
                      ne_10m_populated_places/ne_10m_populated_places.shp]]>
        </Parameter>
    修改 <Parameter name="file">
          <![CDATA[/usr/local/share/maps/style/osm-bright-master/shp/
                      ne_10m_populated_places_simple/ne_10m_populated_places_simple.shp]]>
        </Parameter>

5.容器開啟資料庫,網站,圖磚服務
    # service postgresql restart
    # service apache2 restart
    # service renderd restart

6.主機開啟瀏覽器驗證
    http://localhost/openlayers-example.html

7.主機儲存容器內容為新映像檔,供下回使用
    > docker commit twbright taiwan-osmbright:v1   # 新映像檔命名 taiwan-osmbright:v1
    > docker stop twbright     # 關閉容器
    > docker rm twbright    # 刪除容器


8.主機利用新映像檔,開啟容器,仍命名為 twbright,提供地圖服務
    > docker run -i -t -p 80:80 --name twbright taiwan-osmbright:v1
    http://localhost:80/openlayers-example.html



B.【自動安裝法】以下利用Github映像檔製作環境包快速製作新映像檔taiwan-osmbright:v1

1.下載映像檔製作環境包
  利用瀏覽器連線到網址 https://github.com/sekewei/docker-opentileserver
  點選下載映像檔製作環境包 taiwan-osmbright_v1_build.tar.gz

2.製作地圖服務映像檔
  利用如下指令製作地圖服務映像檔,其中,- 表示映像檔製作環境取自導向(<)進來的環境包檔案,
    -f ./Dockerfile 表示製作步驟檔位於映像檔製作環境之路徑
  > docker build -f ./Dockerfile -t taiwan-osmbright:v1 - < taiwan-osmbright_v1_build.tar.gz

3.啟動地圖服務容器
  利用如下指令啟動服務容器,命名twbright,介接到主機80號埠
  > docker run -it -p 80:80 --name twbright taiwan-osmbright:v1
  按Ctrl-p + Ctrl-q跳出容器終端機

4.測試地圖服務
  利用瀏覽器連線到本地主機80號埠測試地圖服務
  http://localhost:80/openlayers-example.html

  註: 如果要修改初始地圖顯示位置為(lon,lat),方法如下:
        # vi /var/www/html/openlayers-example.html
            var toProjection   = new OpenLayers.Projection("EPSG:900913"); // spherical mercator projection
            var fromProjection = new OpenLayers.Projection("EPSG:4326"); // WGS 1984
            var position       = new OpenLayers.LonLat(lon,lat).transform(fromProjection, toProjection);
            var zoom           = 15;
            map.setCenter(position, zoom);

5.更新地圖資料
  利用如下指令連入容器終端機,執行腳本下載圖資,匯入資料庫,重新啟動服務
  > docker attach twbright
  # cd /opentileserver
  # sh ./reload-opentileserver.sh
  按Ctrl-p + Ctrl-q跳出容器終端機



C.【除錯資訊】以下為自動或手動建立新映像檔,啟動容器後的除錯要點:
0.本機進入容器的終端機 > docker attach twbright 

1.圖磚前景啟動 # sudo -u tile renderd -f -c /usr/local/etc/renderd.conf
     可確認字型檔 unifont.ttf 及形狀檔 ne_10m_populated_places_simple.shp 是否載入正確

2.圖磚快取位置 # ls /var/lib/mod_tile/default/
     可確認目錄下是否有.png圖磚產生

3.字型位置必須有unifont統一碼字型
     # ls /usr/share/fonts/truetype/unifont/unifont.ttf

4.資料庫設定檔必須驗證方式為trust才不必輸入密碼,如下:
     /etc/postgresql/9.3/main/pg_hba.conf
     local all all trust

5.資料庫驗證
     # psql -d gis -Utile   # 以用戶 tile 身份連入資料庫 gis
     gis=# \d         # 列出資料表
               List of relations
   Schema |        Name        | Type  |  Owner
  --------+--------------------+-------+----------
   public | geography_columns  | view  | postgres
   public | geometry_columns   | view  | tile
   public | planet_osm_line    | table | tile
   public | planet_osm_nodes   | table | tile
   public | planet_osm_point   | table | tile
   public | planet_osm_polygon | table | tile
   public | planet_osm_rels    | table | tile
   public | planet_osm_roads   | table | tile
   public | planet_osm_ways    | table | tile
   public | raster_columns     | view  | postgres
   public | raster_overviews   | view  | postgres
   public | spatial_ref_sys    | table | tile
  (12 rows)
 
     gis=# \d planet_osm_point  # 列出欄位
  osm_id             | bigint                 |
  access             | text                   |
  addr:housename     | text                   |
  addr:housenumber   | text                   |
  addr:interpolation | text                   |
  admin_level        | text                   |
  aerialway          | text                   |
  aeroway            | text                   |
  amenity            | text                   |
  area               | text                   |
  barrier            | text                   |
  bicycle            | text                   |
  brand              | text                   |
  bridge             | text                   |
  boundary           | text                   |
  building           | text                   |
  .....
  water              | text                   |
  waterway           | text                   |
  wetland            | text                   |
  width              | text                   |
  wood               | text                   |
  z_order            | integer                |
  way                | geometry(Point,900913) |

     gis=# select osm_id, name from planet_osm_point limit 10;  # 取10個點看中文名正確否
     osm_id   |   name
  ------------+-----------
     63252122 |
   1647048653 | 青屿
   1645249987 | 五膽島
   1645249985 | 四膽島
   1645249984 | 三膽島
   1645249983 | 二膽島
   1645249988 | 大膽島
   1645251414 | 獅球
   1645249986 | 大南礁
   1645249989 | 兔嶼

     gis=# select count(*) from planet_osm_point;  # 計算總共資料庫有幾個點
  count
--------
 198300
(1 row)

     gis=# \q         # 離開

revival of an installed cygwin system after change of os

Cygwin 是一個依附在 Windows 作業系統上的 Linux 作業系統,可以方便用戶同時享用兩者便利功能。
更換 Windows 作業系統後,若不想重灌 cygwin 系統,想利用原有安裝目錄資料,可參考如下復活法。
假設參數如下:
  舊根目錄 Root install directory: D:\Cygwin64
  舊套件目錄 Local package directory: D:\Install\Cygwin64
  新舊用戶名 Windows User Name: Old_User, New_User

1.利用安裝程式重建桌面終端機捷徑
    下載執行 Cygwin 安裝程式 setup-x86_64.exe (64位元)
    Choose a download source: Installed from local directory
    Select root install directory: Root directory: [D:\Cygwin64]
    Select local package directory: Local package directory: [D:\Install\Cygwin64]
    Select packages: Current
    不裝新套件,選[下一步],[完成]後,會在桌面產生 Cygwin64 Terminal

2.利用終端機重建用戶密碼檔
    點選桌面 Cygwin64 Terminal 右鍵,選擇 [以系統管理者身分執行(A)]
    以命令列指令重建用戶檔: mkpasswd -l > /etc/passwd

3.利用 Windows 檔案總管設定安裝目錄的用戶權限
    檔案總管開啟 D:\Cygwin64,按右鍵,點選 內容(R)/安全性/進階(V)

  a)設定新用戶為目錄擁有者
    點選 擁有者/變更(C): 請輸入物件名稱來選取(E): [New_User]/檢查名稱/確定

  b)設定新用戶對目錄擁有完全控制權限
    點選 權限項目: 主體: [Old_User]/移除(R)
     新增(D)/選取一個主體/請輸入物件名稱來選取(E): [New_User]/檢查名稱/確定
      類型: 允許
      套用到: 這個資料夾、子資料夾及檔案
      基本權限: 完全控制
      確定

註1: 若 ssh 對外連線時,出現個人憑證權限不可開放外界存取訊息,可設定如下:
      > chmod 0700 /home/NEW_USER/.ssh/id_*
    其中,針對如下3個個人憑證檔,需確定個人可讀 (有時要透過檔案總管安全性設定才能設定成功)。
          /home/NEW_USER/.ssh/id_dsa
          /home/NEW_USER/.ssh/id_rsa
          /home/NEW_USER/.ssh/identity

weka.classifiers.bayes.NaiveBayesSimple

weka.classifiers.bayes.NaiveBayesSimple 為簡單貝氏機率學習器的簡化版,
記錄各類別事前機率,及給定類別下各屬性值出現之條件機率,
再依案例,累乘得到給定屬性值下各類別出現之事後機率,取機率高者為預測類別,
可提供案例集不錯表現值供標竿比較之用。

NaiveBayesSimple 學習分類時,同樣為每個類別統計其類別事前機率(prior probability)、給定類別下各屬性值出現之條件機率。
遇數值屬性時,一律假設母體為常態分布,統計其平均值、標準差,供條件機率之推估。
預測分類時,依新案例,累乘得到給定屬性值下各類別出現之事後機率(posterior probability),取機率高者為預測類別。

參數說明:

出處: R. Duda and P. Hart (1973). Pattern Classification and Scene Analysis. Wiley, New York.

>java -cp simpleEducationalLearningSchemes.jar;weka.jar;. 
   weka.classifiers.bayes.NaiveBayesSimple -t data\weather.numeric.arff


Naive Bayes (simple)

Class yes: P(C) = 0.625

Attribute outlook
sunny   overcast        rainy
0.25            0.41666667      0.33333333

Attribute temperature
Mean: 73        Standard Deviation: 6.164414

Attribute humidity
Mean: 79.11111111       Standard Deviation: 10.21572861

Attribute windy
TRUE    FALSE
0.36363636      0.63636364



Class no: P(C) = 0.375

Attribute outlook
sunny   overcast        rainy
0.5             0.125           0.375

Attribute temperature
Mean: 74.6      Standard Deviation: 7.8930349

Attribute humidity
Mean: 86.2      Standard Deviation: 9.7313925

Attribute windy
TRUE    FALSE
0.57142857      0.42857143


Time taken to build model: 0.77 seconds
Time taken to test model on training data: 0 seconds

=== Error on training data ===

Correctly Classified Instances          13               92.8571 %
Incorrectly Classified Instances         1                7.1429 %
Kappa statistic                          0.8372
Mean absolute error                      0.3003
Root mean squared error                  0.3431
Relative absolute error                 64.6705 %
Root relative squared error             71.5605 %
Total Number of Instances               14


=== Detailed Accuracy By Class ===

                 TP Rate  FP Rate  Precision  Recall   F-Measure  MCC      ROC Area  PRC Area  Class
                 1.000    0.200    0.900      1.000    0.947      0.849    0.933     0.963     yes
                 0.800    0.000    1.000      0.800    0.889      0.849    0.933     0.925     no
Weighted Avg.    0.929    0.129    0.936      0.929    0.926      0.849    0.933     0.949


=== Confusion Matrix ===

 a b   <-- classified as
 9 0 | a = yes
 1 4 | b = no



=== Stratified cross-validation ===

Correctly Classified Instances           8               57.1429 %
Incorrectly Classified Instances         6               42.8571 %
Kappa statistic                         -0.0244
Mean absolute error                      0.4699
Root mean squared error                  0.5376
Relative absolute error                 98.6856 %
Root relative squared error            108.9683 %
Total Number of Instances               14


=== Detailed Accuracy By Class ===

                 TP Rate  FP Rate  Precision  Recall   F-Measure  MCC      ROC Area  PRC Area  Class
                 0.778    0.800    0.636      0.778    0.700      -0.026   0.444     0.636     yes
                 0.200    0.222    0.333      0.200    0.250      -0.026   0.444     0.398     no
Weighted Avg.    0.571    0.594    0.528      0.571    0.539      -0.026   0.444     0.551


=== Confusion Matrix ===

 a b   <-- classified as
 7 2 | a = yes
 4 1 | b = no


如下 weather.numeric.arff 案例集的14個案例利用2個文字屬性及2個數字屬性,預測文字屬性。
outlooktemperaturehumiditywindyplay
sunny8585FALSEno
sunny8090TRUEno
rainy6570TRUEno
sunny7295FALSEno
rainy7191TRUEno
overcast8386FALSEyes
rainy7096FALSEyes
rainy6880FALSEyes
overcast6465TRUEyes
sunny6970FALSEyes
rainy7580FALSEyes
sunny7570TRUEyes
overcast7290TRUEyes
overcast8175FALSEyes
參考: 1.weka.classifiers.bayes.NaiveBayesSimple code | doc 2.從Weka 3.7.2版之後,NaiveBayesSimple 類別 從 weka.jar 主套件改歸到 simpleEducationalLearningSchemes.jar 選擇性套件內, 可利用Tools/Package Manager/Search: simpleEducationalSchemes/Install進行安裝。 在Windows下,下載套件存放位置在 C:\Users\用戶名\wekafiles\packages\ 資料夾內。 simpleEducationalSchemes 包含IB1,Prism,Id3,NaiveBayesSimple四個簡單分類器

matlab backslash benchmarking on T3600 + Tesla C2075

Dell T3600 (CPU: Intel Xeon E5-1607, quad-core, 3GHz) +
(GPU: Tesla C2075, 14 MultiProcessor x 32 cores per MP = 448 cores, 1.15GHz)

>> paralleldemo_gpu_backslash
Warning: Support for GPU devices with Compute Capability 2.0 will be removed in a future MATLAB release.
To learn more about supported GPU devices, see www.mathworks.com/gpudevice. 
> In parallel.internal.gpu.selectDevice
  In parallel.gpu.GPUDevice.current (line 44)
  In gpuDevice (line 23)
  In paralleldemo_gpu_backslash (line 25) 

Starting benchmarks with 8 different single-precision matrices of sizes
ranging from 1024-by-1024 to 22528-by-22528.
Creating a matrix of size 1024-by-1024.
Gigaflops on CPU: 48.665627
Gigaflops on GPU: 88.271370
Creating a matrix of size 4096-by-4096.
Gigaflops on CPU: 100.882839
Gigaflops on GPU: 413.998827
Creating a matrix of size 7168-by-7168.
Gigaflops on CPU: 118.687441
Gigaflops on GPU: 509.776228
Creating a matrix of size 10240-by-10240.
Gigaflops on CPU: 133.868299
Gigaflops on GPU: 573.530695
Creating a matrix of size 13312-by-13312.
Gigaflops on CPU: 139.691629
Gigaflops on GPU: 599.239014
Creating a matrix of size 16384-by-16384.
Gigaflops on CPU: 137.981033
Gigaflops on GPU: 611.514780
Creating a matrix of size 19456-by-19456.
Gigaflops on CPU: 143.995683
Gigaflops on GPU: 620.246637
Creating a matrix of size 22528-by-22528.
Gigaflops on CPU: 149.399225
Gigaflops on GPU: 628.924035

Starting benchmarks with 6 different double-precision matrices of sizes
ranging from 1024-by-1024 to 16384-by-16384.
Creating a matrix of size 1024-by-1024.
Gigaflops on CPU: 29.380086
Gigaflops on GPU: 63.980649
Creating a matrix of size 4096-by-4096.
Gigaflops on CPU: 48.082489
Gigaflops on GPU: 227.926438
Creating a matrix of size 7168-by-7168.
Gigaflops on CPU: 61.270138
Gigaflops on GPU: 270.644244
Creating a matrix of size 10240-by-10240.
Gigaflops on CPU: 64.503818
Gigaflops on GPU: 291.146412
Creating a matrix of size 13312-by-13312.
Gigaflops on CPU: 68.655104
Gigaflops on GPU: 300.565164
Creating a matrix of size 16384-by-16384.
Gigaflops on CPU: 56.189737
Gigaflops on GPU: 302.010177

ans = 

  struct with fields:

         sizeSingle: [1024 4096 7168 10240 13312 16384 19456 22528]
    gflopsSingleCPU: [48.6656 100.8828 118.6874 133.8683 139.6916 137.9810 143.9957 149.3992]
    gflopsSingleGPU: [88.2714 413.9988 509.7762 573.5307 599.2390 611.5148 620.2466 628.9240]
         sizeDouble: [1024 4096 7168 10240 13312 16384]
    gflopsDoubleCPU: [29.3801 48.0825 61.2701 64.5038 68.6551 56.1897]
    gflopsDoubleGPU: [63.9806 227.9264 270.6442 291.1464 300.5652 302.0102]
Single precision GFlops
Double precision GFlops
Speedup

missing font display in ms word

當你在使用中文繁體Windows作業系統時,若突然發現怎麼純文字檔(.txt)的中文碼亂掉或Office的標楷體,細明體消失,出現楷体、DFKai-SB、PMinLiU等字型,這時別慌,你的繁體字型都還在,只是顯示不出來。只要修改如下位置的設定,一切就回復成繁體原狀。

    [控制台 / 時鐘、語言和區域 / 語言 / 系統管理 / 非Unicode程式的語言 / 變更系統地區設定(C)...]

將目前的系統地區設定由 [中文(簡體、中國)] 改為 [中文(繁體、台灣)],然後選擇 [立即重新啟動] 。

    註解:
  1.  Unicode字碼可同時顯示多國語言,但為了容舊,繁體中文Windows純文字檔仍使用Big5字碼,所以當非Unicode語言設定成簡體GB字碼時,原來的純文字檔顯示就變亂碼。
  2.  Office字型名稱的顯示會依據 [非Unicode程式的語言] 設定而決定。當正常設定為繁體時,DFKai-SB會顯示成標楷體、PMinLiU會顯示成細明體。所以當不知何原因被切換成簡體時,就顯示其英文名。至於楷体是簡體字型,在設定回復為繁體後,就顯示其英文名KaiTi。
  3. 常見漢字字型如下: 繁體中文字型有細明體(MinLiU) 、新細明體(PMinLiU)、標楷體(DFKai-SB)、微軟正黑體(Microsoft JhengHei);簡體中文字型有宋体(SimSun)、新宋体(NSimSun)、仿宋(FangSong)、楷体(KaiTi)、黑体(SimHei)、微软雅黑(Microsoft YaHei)、等线(DengXian);日文字型有明朝體(MS Mincho)、黑體(MS Gothic)。

benefits of installing guest additions in virtualbox guest os

電腦主機可以安裝虛擬機軟體VirtualBox,在主機上建立虛擬硬體層,
其上再安裝諸多客戶作業系統,同時間跑多個作業系統。
為了提升用戶體驗,VirtualBox同時提供客戶補充包(Guest Additions)套件,
若將其安裝在客戶作業系統上,使用起來會更上手,其具體好處如下:

1.滑鼠指標整合
    在客戶作業系統安裝滑鼠驅動器,進出視窗點選內容,不必再按主機鍵(右邊Ctrl鍵)跳出

2.共用資料夾
    可指定主機某資料夾分享給客戶作業系統,自動掛載顯示在桌面,
      Windows: 自動多一台磁碟機
      Linux: /media/sf_sharename
             用戶要對其讀寫須加入vboxsf群組

    或手動設定掛載點:
      Windows: net use x: \\vboxsvr\sharename
      Linux: mount -t vboxsf [-o OPTIONS] sharename mountpoint
          或 vi /etc/fstab
             sharename   mountpoint   vboxsf   defaults  0   0

3.共用剪貼簿
    主機和客戶系統可共用剪貼簿

4.檔案拖放
    主機和客戶系統可拖放檔案

5.較佳視訊支援
    支援更多非標準視訊模式,方便任意調整視窗大小

6.無縫視窗
    利用主機鍵(右邊Ctrl鍵)+"L"切換,可讓虛擬機桌面放大到主機桌面並且隱藏虛擬機桌面背景。
    這樣虛擬機桌面的視窗感覺就像主機桌面的視窗

7.時間同步
    確保客戶系統時間和主機相同.

8.通用主機客戶通訊管道
    方便主機控制和監看客戶系統

9.自動登入(傳送憑證)
    須透過複雜設定才能自動登入Windows或Linux系統

10.記憶體汽球調整及合併
    利用汽球調整(ballooning)及合併(fusion)技術,讓客戶系統間記憶體互相支援及共用,減少主機記憶體負荷

參考: https://www.virtualbox.org/manual/ch04.html#idm1721

weka.classifiers.rules.DecisionTable

 
weka.classifiers.rules.DecisionTable 為決策表學習器,適用於類別/數值預測。
預設利用最佳優先(登山)搜尋法,以交叉驗證之準確率或均方差為指標,找出最佳的屬性子集合。
然後,將訓練案例集縮減為只用留下的屬性子集合描述。
視每個案例為一條規則,其前件由留下屬性值組成,其後件則為多數決類別或平均值。
預測時若新案例有符合某規則之前件,則依其後件進行預測。
若遇決策表未涵蓋新案例,則使用k最近鄰居法,或背景多數決法作預測。

參數說明:
-X  crossVal: [1] 交叉驗證切割組數,1表只保留一測試案例,餘供訓練
-I  useIBk: [false] 遇未涵蓋新案例,使用k最近鄰居法,否則使用多數決法
-R  displayRules: [false] 列印決策表
-E  evaluationMeasure: [acc 或 rmse] 最佳指標遇類別採用準確率,遇數值採用均方差
                       其他指標還有  mae , auc
-S  search: [weka.attributeSelection.BestFirst] 子集合搜尋策略

  -- 以下為搜尋策略的參數 --

-D  direction: [1] 0表向後屬性變少,1表向前屬性變多,3表雙向
-S  lookupCacheSize: [1] 保留候選子集合的個數為案例集屬性個數的多少倍
-N  searchTermination: [5] 放棄搜尋前,能忍受指標無進步之試走步數
-P  startSet: [] 找尋初始點的屬性子集合,預設為空集合

參考: 
    kohavi-ecml-95-the power of decision tables

> java weka.classifiers.rules.DecisionTable -R -t data\weather.nominal.arff


Options: -R 

Decision Table:

Number of training instances: 14
Number of Rules : 1
Non matches covered by Majority class.
 Best first.
 Start set: no attributes
 Search direction: forward
 Stale search after 5 node expansions
 Total number of subsets evaluated: 12
 Merit of best subset found:   64.286
Evaluation (for feature selection): CV (leave one out) 
Feature set: 5

Rules:
================
play  
================
yes
================



Time taken to build model: 0 seconds
Time taken to test model on training data: 0 seconds

=== Error on training data ===

Correctly Classified Instances           9               64.2857 %
Incorrectly Classified Instances         5               35.7143 %
Kappa statistic                          0     
Mean absolute error                      0.4524
Root mean squared error                  0.4797
Relative absolute error                 97.4359 %
Root relative squared error            100.0539 %
Total Number of Instances               14     


=== Confusion Matrix ===

 a b   <-- classified as
 9 0 | a = yes
 5 0 | b = no



=== Stratified cross-validation ===

Correctly Classified Instances           6               42.8571 %
Incorrectly Classified Instances         8               57.1429 %
Kappa statistic                         -0.3659
Mean absolute error                      0.5318
Root mean squared error                  0.5583
Relative absolute error                111.6786 %
Root relative squared error            113.1584 %
Total Number of Instances               14     


=== Confusion Matrix ===

 a b   <-- classified as
 6 3 | a = yes
 5 0 | b = no

如下 weather.nominal.arff 案例集的14個案例有9個yes、5個no。
outlooktemperaturehumiditywindyplay
sunnyhothighFALSEno
sunnyhothighTRUEno
rainycoolnormalTRUEno
sunnymildhighFALSEno
rainymildhighTRUEno
overcasthothighFALSEyes
rainymildhighFALSEyes
rainycoolnormalFALSEyes
overcastcoolnormalTRUEyes
sunnycoolnormalFALSEyes
rainymildnormalFALSEyes
sunnymildnormalTRUEyes
overcastmildhighTRUEyes
overcasthotnormalFALSEyes
參考:
1.weka.classifiers.rules.DecisionTable
   code | doc

docker command line summary

docker command line summary

image: a read-only file system consisting of a base layer and a series of difference layers

container: a writable file system consisting of an image and a top writable layer with network and volume hooks

    Note:
  • an image has id, name, tag, read-only_layers, entrypoint, and cmd
  • a container has id, name, source_image, writable_layer, overwrite_cmd, cpu_limit, memory_limit, volume_hook, network_hook, and state (active/un-active)
what docker can do with images in a local image store
  -- creation --
  - import/export with docker hub
   search in a docker hub (docker search)
   pull from a docker hub (docker pull)
   push to a docker hub (docker push)
  - import/export with local filesystem
   load from a local file (docker load)
   save to a local file (docker save)
  - born from scratch
   commit an un-active container to create an image (docker commit)
   build an image with Dockerfile instructions (docker build)
 
  -- management --
  list (docker images)
  remove (docker rmi)

what docker can do with containers in a local container store
  -- creation -- 
   create an un-active container from an image (docker create)
   run from an image with an overwrite command (docker run)
   execute a command (docker exec)

  -- management
   stop an active container with a grace period (docker stop)
   kill an active container (docker kill)
   start an un-active container (docker start)
   restart an active container (docker restart = 
   		docker stop + docker start)
  -
   copy with local filesystem (docker cp)
  -
   attach the console to a container (docker attach)
  -
   commit an un-active container to create an image (docker commit)
  -
   list (docker ps [-a])
   remove (docker rm [-f])
    Note:
  • an image runs a new container with an overwrite command = an image creates a new container + the container starts with an overwrite command
  • a container is created when docker creates from an image or runs from an image with an overwrite command
  • an image is created when docker commits a container or builds from a base image and a Dockerfile
#
#
# image operation
#
#

#### search for an image
docker search image_keyword

#### download an image
docker pull [registry.hub.docker.com/]image_path[:tag] 

#### list images in local drive
docker images [image_path]

#### create new images
1.docker commit -m "submit message" -a "submit user" container_id image_path[:tag]

 $ vi ./Dockerfile
 # This is a comment
 FROM ubuntu:14.04
 MAINTAINER Docker Newbee <newbee docker.com="">
 RUN apt-get -qq update
 RUN apt-get -qqy install ruby ruby-dev
 RUN gem install sinatra
 # put my local web site in myApp folder to /var/www
 ADD myApp /var/www
 # expose httpd port
 EXPOSE 80
 # the command to run
 CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]

2.docker build -t="image_path:tag" .  

3.cat ubuntu-14.04-x86_64-minimal.tar.gz  | docker import - ubuntu:14.04

4.docker tag container_id image_path:new_tag

#### upload an image
docker push image_path # all tags

#### save and load an image as local file 
docker save -o ubuntu_14.04.tar ubuntu:14.04

docker load --input ubuntu_14.04.tar
docker load < ubuntu_14.04.tar

#### remove a local image
docker rmi image_path

#
#
# container operation
#
#

#### start and run a container with an image
docker run [-name container_name] ubuntu:14.04 /bin/echo 'Hello world'
docker run -t -i ubuntu:14.04 /bin/bash   ### start a container in interactive mode
docker start ubuntu:14.04

docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
docker ps [-a]     ### list containers, [all, inclusive of un-active containers]
docker logs insane_babbage

#### start and stop container
docker restart
docker stop
docker run -idt ubuntu
docker attach container_name

#### start a shell in a container, detach from it, and re-attach to it
docker exec -it container_name /bin/bash
# use Ctrl-p + Ctrl-q to detach from the container
docker attach container_name

#### import and export container 
docker export container_id > snapshot.tar
cat snapshot.tar | docker import - image_path[:tag]
docker import snapshot_url image_path

#### remove container
docker rm container_name
docker rm $(docker ps -aq)  ## remove all exited containers



References:
1.《Docker —— 從入門到實踐­》Run命令

2.How to use Docker without sudo on Ubuntu
  # grant docker permission to specific user 'foobar'
  > sudo setfacl -m user:foobar:rw /var/run/docker.sock
  > getfacl /var/run/docker.sock
  getfacl: 從絕對路徑名尾部去除"/"字符
  # file: var/run/docker.sock
  # owner: root
  # group: docker
  user::rw-
  user:foobar:rw-
  group::rw-
  mask::rw-
  other::---

3.Prepare docker.service.d/override.conf for the systemd drop-in service
  > sudo systemctl edit docker
  [Service]
  ExecStartPost=/bin/sh -c '/usr/bin/setfacl -m user:foobar:rw /var/run/docker.sock'
  > sudo systemctl daemon-reexec	# re-execute the systemd process
  > sudo systemctl daemon-reload	# reload the systemd manager configuration
  > sudo systemctl restart docker	# stop and start the docker service
    
4.Play With Docker provides an Alpine Linux 3.10 environment with docker and git ready for use
     CPU: Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz with 8 cores
     Memory: 32GB
     Drive: 64GB with 16GB used
     Limit: Use of up to 5 nodes for up to 4 hours per session

integer and float division in C

>celsius = (5 / 9) * (fahren - 32);
>不管打什麼fahren數字,celsius都是 0
>我把 5 或 9 換成 5.0 或 9.0, 再compile和execute就正常。

C或Java高階語言重視數字型別,將除法運算(/ operator)分成整數除法及實數除法。
整數除法的商結果為整數,小數忽略。
實數除法的商結果為實數。
決定整數或實數除法是由運算子(operand)型別決定:
(1)  整數 / 整數 = 整數商
(2)  實數 / 實數 = 實數商
(3)  整數 / 實數 = ?數商
(4)  實數 / 整數 = ?數商

例子 5/9 屬於情況(1)所以得到結果為0;
至於 5.0 / 9.0 屬於情況(2)所以得到結果有小數。
至於情況(3)及(4)結果為何,可以實驗一下。
(情况 3 跟 4 结果會以最精確的型別為準,輸出實數商)

除了加.0將整數變實數,也可以利用轉型運算子,寫法如下:

  celsius = ((float) 5 / (float) 9) * (fahren - 32);

數字前面加 (float) 運算子可將其型別轉為float。

Disable UDP to solve frequent RDP disconnection

解決 RDP 遠端桌面經常斷線問題:「關閉 UDP 傳輸」 在使用 Windows 內建的 遠端桌面(RDP, Remote Desktop Protocol) 連線時,你是否也常遇到連線突然卡死、畫面凍結,或是頻繁跳出「連線已中...

總網頁瀏覽量