2012-06-27から1日間の記事一覧

各コンテナ要素の『平均・分散・標準偏差』を計算するコード

たまに必要になるんだけど、毎回書き直しているのでメモっておく。 テストコードの結果はR言語と揃ってるのは確認済。 #include <iostream> #include <cmath> #include <vector> #include <list> #include <numeric> template <template<class T, class Allocator = std::allocator<T> > class Container> double mean(Container<double> & x) { return std::accumula</double></template<class></numeric></list></vector></cmath></iostream>…

確率分布からのサンプリングをヒストグラムで美しく描く

R

この前のエントリーのために作ったグラフが結構気に入ったのでテンプレとして残しておく。例えば対数正規分布するデータを1000個用意して、 x <- exp(rnorm(1000)) これをPLOT。 library(ggplot2) qplot(x, geom="blank") + geom_histogram(aes(y=..density.…