2012-11-10

ニューラルネットの活性化関数 その1

ニューラルネットの活性化関数 (activation function) としては次のようなものがある。
  1. 標準シグモイド関数 (standard sigmoid function):   y = 1 / (1 + exp(-x))   【グラフ】
  2. 双曲線正接関数:   y = tanh(x)   【グラフ】
  3. abs を使った関数:   y = x / (1 + abs(x))   【グラフ】
それぞれの導関数 (derivative) は次のとおり。
  1. y * (1 - y)
  2. 1 - y * y
  3. 1 / pow(1 + abs(x), 2) または pow(1 - abs(y), 2)
上記の活性化関数とその導関数は次の論文から引用した。
A Better Activation Function for Artificial Neural Networks, David Elliott, 1993
http://drum.lib.umd.edu/handle/1903/5355
次のサイトによると、活性化関数の計算の速さは (3) の abs を使った関数の方が (1) の標準シグモイド関数よりも2倍以上速いらしい。
※ 2004年の結果なので、最近の CPU では異なるかも知れない。
Neural Network Code Optimizations
http://sharpneat.sourceforge.net/network_optimization.html
その他、参考にしたサイト。
Backpropagator's Review
http://www.dontveter.com/bpr/activate.html

[追記]

[関連記事]

2012-11-06

C++ のサイト

いつの間にか C++ のサイトができていた。
Standard C++
http://isocpp.org/
以下、関連など。
Twitter @isocpp
https://twitter.com/isocpp

Bjarne Stroustrup's Homepage
http://www.stroustrup.com/

2012-11-05

ByteBuffer.allocateDirect で確保したメモリを解放する方法

ByteBuffer.allocateDirect で確保したヒープ外のメモリを解放するには、オブジェクトの参照を全て外してから GC をする必要がある。別の方法としては、下記のページのように sun.misc.Cleaner を呼び出せば解放することができるようだ。
java - Examples of forcing freeing of native memory direct ByteBuffer has allocated, using sun.misc.Unsafe? - Stack Overflow
http://stackoverflow.com/questions/8462200/examples-of-forcing-freeing-of-native-memory-direct-bytebuffer-has-allocated-us
おそらく、Oracle (Sun) の Java のみ有効。

ググってたら、次のようなユーティリティのソースを見つけた。
ByteBufferUtil xref
http://static.netty.io/3.5/xref/org/jboss/netty/util/internal/ByteBufferUtil.html

2012-10-22

Visual Studio の NuGet が便利

Visual Studio Express 2012 for Windows Desktop で遊んでいるのですが、NuGet でライブラリが組み込めるようになっていて、いつの間にか便利になっていました。Java で言うと Maven みたいなものです。

CodePlex から圧縮書庫の操作ライブラリを探してきて、NuGet でそのパッケージを追加すれば、簡単に解凍プログラムが作れます。

2012-10-17

3次ベジェ曲線を高速に計算して描画する方法

ずっと昔に読んだ、3次ベジェ曲線 (Cubic Bezier curve) を前進差分で高速に計算する方法を解説した記事が復活していたので、メモ。
Forward Difference Calculation of Bezier Curves | Dr Dobb's
http://www.drdobbs.com/forward-difference-calculation-of-bezier/184403417
Figure とか Listing とかのリンクが切れているが、ページ下の方の「1 2 3 4 5 Next」から見ることができる。

2013-08-17 追記
リンク先の生存を確認。http://www.drdobbs.com/ はしばしばアクセスできなくなるが、その場合は時間をおいて再度アクセスするとよい。

2013-10-25 追記
下記のページにも Dr Dobb's と同じ記事が存在する。http://www.drdobbs.com/ のサイトが見られない場合はこちらを参照。
November 1997/Forward Difference Calculation of Bezier Curves
http://collaboration.cmc.ec.gc.ca/science/rpn/biblio/ddj/Website/articles/CUJ/1997/9711/bartley/bartley.htm

2012-09-14

Java のシャットダウンフックの書き方

ここの回答がわかりやすかったので、メモ。
Useful example of a shutdown hook in Java? - Stack Overflow
http://stackoverflow.com/questions/2921945/useful-example-of-a-shutdown-hook-in-java

2012-09-09

Population count

先日の「Long.bitCount(long) の速度」の記事で比較した it.unimi.dsi.bits.Fast.count(long) だが、Wikipedia にも同様のコードが載っていてショック。
Hamming weight - Wikipedia, the free encyclopedia
http://en.wikipedia.org/wiki/Hamming_weight
そのコードを一般化したものが次のページに載っている。
Counting bits set, in parallel - Bit Twiddling Hacks
http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel

JDK のソースにある「HD, Section 2-1」というコメント

Java API の Integer.lowestOneBit(int) のソースには、
// HD, Section 2-1
というコメントがある。ググると、「Hacker's Delight」という書籍の Section 2-1 を指しているらしい。
java - cryptic comment in jdk source: // HD, Section 2-1 - Stack Overflow
http://stackoverflow.com/questions/1006626/cryptic-comment-in-jdk-source-hd-section-2-1
さらにググると、その書籍の公式サイトらしきものがあった。
Hacker's Delight
http://www.hackersdelight.org/
そのサイトにある書籍のサンプル「Chapter 2, Basics」から、さきほどの「HD, Section 2-1」の箇所を読むことができる。

2012-09-06

Windows 7 & Java 7 & Maven & wagon-ftp でFTPアップロードが失敗する現象

よく忘れるので、メモ。
Java 7 prevents FTP transfers on Windows Vista and 7 if firewall is on. Any ideas? - Stack Overflow
http://stackoverflow.com/questions/6990663/java-7-prevents-ftp-transfers-on-windows-vista-and-7-if-firewall-is-on-any-idea
回避するには、コマンドプロンプトで
netsh advfirewall set global StatefulFTP disable
を実行する。

2012-09-01

Java 7 で String クラスがリファクタリングされているらしい

Java7 Update6 で String クラスがさらにリファクタリングされていました
http://d.hatena.ne.jp/chiheisen/20120827
とのことなので確認してみると、Java 7u6 と Java 6u34 で確かにコードが違ってた。