かれ4

かれこれ4個目のブログ

Javaで鍵長256bitのAESを使う

Javaで鍵長256bit のAESを使おうとすると、

java.security.InvalidKeyException: Illegal key size or default parameters

こんなExceptionが出て、うまくいかない。

Java SE - Downloads | Oracle Technology Network | Oracle 上記ページから Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for JDK/JRE 8 をダウンロードしてきて /{jreディレクトリ}/lib/securityの中に以下の2つのファイルを放り込む。 - local_policy.jar - US_export_policy.jar

簡単に出来ることではあるけれど、PaaSを使う場合にどうしたものかとなってしまう。 そんな時にリフレクションを使って、 以下のようなコードをAESを使う前に一度だけ実行しておけばOK。

try {
    Field field = Class.forName("javax.crypto.JceSecurity").getDeclaredField("isRestricted");
    field.setAccessible(true);

    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
    field.set(null, false);
} catch (ClassNotFoundException | NoSuchFieldException | SecurityException | IllegalArgumentException
                | IllegalAccessException ex) {
    ex.printStackTrace(System.err);
}

Azure Machine Learningで入力されたデータに行番号をつける

データに行番号をつける理由

分類器を造っているときに、もしかしたら、復数のアルゴリズムを同時につかい、 各アルゴリズムの結果を元に、最終の分類をしたい事があるかもしれない。

f:id:tottokug:20170829231950p:plain

こんな感じで簡易マギシステムが出来上がるわけです。

行番号をつける方法

そもそもAzure Machine Learningに持ってくる前に付与しておけば良いという話ではあるんだけれども、、、 とりあえず、Azure Machine Learningには、便利なモジュール Apply SQL Transformation がある。 このモジュールを使えば簡単に出来る。

f:id:tottokug:20170829231356p:plain

まずは行番号を付けたいデータをApply SQL Transformationに入力します。 モジュールの中身のSQL Query Scriptは以下のようにします。

select 
ROWID as rowid, 
* from t1;

こんな感じ。

これでApply SQL Transformationの出力には今まであったカラムにrowidと言うカラムが追加されて出力されます。

便利。

Apply SQL Transformationとは

Azure Machine Learningの中でもPython,Rと同様にSQLで記述することで、データの加工が出来るモジュール。

データを最大3つまで入力することができ、SQLでJOINしたり値を整形したりすることができる。

SyntaxはSQLiteなので、今回のようなROWIDという隠れカラムも使用することが可能。

Cognitive Toolkitをwgetでダウンロード

Linux

# CPU Only
wget http://cntk.ai/BinaryDrop/CNTK-2-1-Linux-64bit-CPU-Only.tar.gz
# GPU
wget http://cntk.ai/BinaryDrop/CNTK-2-1-Linux-64bit-GPU.tar.gz
# GPU with 1bit SGD
wget http://cntk.ai/BinaryDrop/CNTK-2-1-Linux-64bit-GPU-1bit-SGD.tar.gz

Windows

# CPU Only
wget http://cntk.ai/BinaryDrop/CNTK-2-1-Windows-64bit-CPU-Only.zip
# GPU
wget http://cntk.ai/BinaryDrop/CNTK-2-1-Windows-64bit-GPU.zip
# GPU with 1bit SGD
wget http://cntk.ai/BinaryDrop/CNTK-2-1-Windows-64bit-GPU-1bit-SGD.zip

matebook E で DhotKeyなるプロセスがCPUをよく使う

matebookEを使い始めて大体1週間が過ぎたところで、DhotKeyなるプロセスが常時10%くらいのCPUを使ってることがわかった

huawei製の何かであるっぽいのだけれども、詳細は今の所不明。
ちょと調査するけど、たぶん指紋のやつな気がしている

追記:
よくわからないけれど、とりあえずタスクマネージャから優先度 低いにして、
普通に戻せば落ち着くことがわかった
あとで再起動しても大丈夫だったら、そのまま放置。
もし再起動するたびにやらなきゃいけないならスクリプト書く。

New Surface ProはSurface Pro 4から何が変わったか

変更点

変更点 Surface Pro 4 New Surface Pro
厚さ 8.45mm 8.5mm
キックスタンド 165°
CPU 第6世代 第7世代
Graphics m3: Intel HD graphics 515
i5: Intel HD graphics 520
i7: Intel Iris graphics
m3: Intel HD Graphics 615
i5: Intel HD Graphics 620
i7: Intel Iris Plus Graphics 640
Bluetooth 4.0 4.1
バッテリ 最大約 9 時間のビデオ再生が可能 最大約 13.5 時間のビデオ再生が可能
Surface Pen 1,024段階 4,096段階
Surface Dial - o
センサー 磁力計 -
LTE - o

以下参考情報


Introducing the new Surface Pro

Surface Pro

Surface Pro Technical Specs – Versatility & Performance

Surface Pro 4

No need to Sacrifice Power in a Tablet | See Surface Pro 4 Specs Here

比較表

項目 Surface Pro 4 New Surface Pro
Software Windows 10 Pro Office 365 30-day trial Windows 10 Pro Office 365 30-day trial
Exterior Casing: Magnesium Color: Silver Physical buttons: Volume, Power Volume key and power key Surface Pen (sold separately) Surface Keyboard (sold separately) Surface Mouse (sold separately)
Dimensions 11.50 x 7.93 x 0.33 in (292.10 x 201.42 x 8.45 mm) 11.50 x 7.93 x 0.33 in (292.10 x 201.42 x 8.5 mm)
Weight m3: 1.69 lbs (766 g) i5: 1.73 lbs (786 g) i7: 1.73 lbs (786 g) m3: 1.69 lbs (766 g) i5: 1.73 lbs (786 g) i7: 1.73 lbs (786 g)
Storage3 Solid state drive (SSD) options: 128GB, 256GB, 512GB, or 1TB Solid state drive (SSD) options: 128GB, 256GB, 512GB, or 1TB
Display Screen: 12.3” PixelSense Display Resolution: 2736 x 1824 (267 PPI) Aspect ratio: 3:2 Touch: 10-point multi-touch Screen: 12.3” PixelSense Display Resolution: 2736 x 1824 (267 PPI) Aspect ratio: 3:2 Touch: 10-point multi-touch
Battery life2 Up to 9 hours of video playback Up to 13.5 hours video playback
Processor 6th Gen Intel Core m3, i5, or i7 Intel 7th Gen Core m3, i5, i7
Graphics m3: Intel HD graphics 515 i5: Intel HD graphics 520 i7: Intel Iris graphics Intel HD Graphics 615 (m3) Intel HD Graphics 620 (i5) Intel Iris Plus Graphics 640 (i7)
Security TPM chip for enterprise security TPM chip for enterprise security Enterprise-grade protection with Windows Hello face sign-in
Memory 4GB, 8GB, or 16GB RAM 4GB, 8GB, 16GB RAM
Wireless 802.11ac Wi-Fi wireless networking; IEEE 802.11a/b/g/n compatible Bluetooth 4.0 wireless technology Wi-Fi: 802.11ac Wi-Fi wireless networking, IEEE 802.11 a/b/g/n compatible, Bluetooth Wireless 4.0 technology
Ports Full-size USB 3.0 microSD card reader Headset jack Mini DisplayPort Cover port Surface Connect Full-size USB 3.0 microSD card reader Surface Connect Headset jack Mini DisplayPort Cover port
Cameras, video, and audio Windows Hello face-authentication camera (front-facing) 5.0MP front-facing camera with 1080p HD video 8.0MP rear-facing autofocus camera with 1080p HD video Stereo microphones Stereo speakers with Dolby Audio Premium Windows Hello face sign-in camera (front-facing) 5.0MP front-facing camera with 1080p HD video 8.0MP rear-facing autofocus camera with 1080p HD video Stereo microphones Stereo speakers with Dolby Audio Premium
Sensors Ambient light sensor Accelerometer Gyroscope Magnetometer Ambient light sensor Accelerometer Gyroscope
What’s in the box Surface Pro 4 Power Supply Quick Start Guide Safety and warranty documents Surface Pro Power supply Quick Start Guide Safety and warranty documents
Warranty 1-year limited hardware warranty 1-year limited hardware warranty

HiveでStringのArrayから、辞書順に並べて一番[最初|最後]のものを取り出す不細工な方法

辞書順に並べて最初のものを取り出す。

SELECT 
  REGEXP_REPLACE(
    CONCAT_WS('###',
      SORT_ARRAY(ARRAY("ag",
          "aa",
          "ab"))),
    "(.*?)###.*",
    "$1"
  );
aa

辞書順に並べて最後のものを取り出す。

SELECT 
  REGEXP_REPLACE(
    CONCAT_WS('###',
      SORT_ARRAY(ARRAY("ag",
          "aa",
          "ab"))),
    ".*###(.*)",
    "$1"
  );
ag

もっとかっこいい方法があるはず。