本記事では、Windows版CmdStanR動作するCmdStanRでGPU(OpenCL)を使う方法を紹介します。「CmdStanRってナニソレオイシイノ?」って人は、清水先生の資料を参照してください。 先日、WindowsのWSL2(Ubuntu)上のCmdStanRで、GPUを使う方法を紹介されている記事を見かけ、これならWindows上で動作するRやRStudio上でも行けそうだなと思い、試してみることにしました(WSL2がGPUを認識してくれなかったので)。 基本的には公式サイトとvignettesを参考にしています。ただ、筆者の環境ではつまづきポイントがあったので、解決方法もまとめて紹介します。ちなみに、NVIDIA GPUでの動作紹介になります、AMDのものを使用する場合は、AMD用のドライバーを入れる必要があり、CmdStanのインストールで別途設定が不要かもしれません。
図1: Monte-Carlo, from Neugebauer (2018) イントロダクション モンテカルロ法とは どこを見て収束を確認するか トレースプロット GR統計量 を確認する. 多重連鎖はいくつ必要か 自己相関関数 (ACF, コレログラム) 有効サンプルサイズ 事後診断ツール bayesplot こういう時どうすればいい? GR統計量の値が大きい アルゴリズムを変える 有効サンプルサイズ の値が小さい 低速混合 間引き そもそもプログラムが間違っている場合 まとめ 参考文献 イントロダクションこの投稿は, 第78回R勉強会@東京(#TokyoR) - connpass での LT の内容を加筆修正したものである. 以下は当時のスライドである. bayesplot を使ったモンテカルロ法の実践ガイド from 智志 片桐 以前, Tokyo.R かどこかの懇親会で, マルコフ
dat <- read.csv("gp_test.csv") N1 <- nrow(dat) x1 <- dat$x y1 <- dat$y N2 <- 59 x2 <- seq(1, 30, length.out = N2) data.gp <- list( N1 = N1, N2 = N2, x1 = x1, x2 = x2, y1 = y1 ) model.gp <- stan_model("GP_reg.stan") fit.gp <- sampling( model.gp, data = data.gp, iter = 5000, chains = 4, cores = 4 ) print(fit.gp, pars = "y2") print(fit.gp, pars = "theta") # plot ext.fit <- rstan::extract(fit.gp) y2.m
Sam WatsonDecember 7, 2016July 13, 201815 CommentsHealth Statistics and EconometricsGeostatistical modelling with R and Stan One of the advantages of writing blogs is that it can help to refresh and consolidate you thoughts on a topic. And when you spend a lot of time writing stats code, other people’s blogs that discuss how to code specific statistical models can be invaluable. I have recently fo
まずはTwitterでこの記事をシェアする author: Unadon (見習い飯炊き兵) 動作環境:Mac OS Sierra 10.12.1; R version3.3.1; rstan 2.10.1 はじめに Rを使う時、私はわざわざ表など使わず、”head(data)”なんかでデータの確認を済ませてしまったりすることが多いです。 でも、他人と共有するとなると、見せ方を考えなければならない。それで、面倒だけどエクセルにコピペして…とやっていました。 また、Rのコンソールに収まりきれないデータを確認したいときなども、何らかの手立てを考える必要があるとおもいます。 今回は、そんなデータの確認に使える”表の出力”についてまとめていきます。 本稿のお品書き package{DT}: dataframeをHTMLの表に一発変換(データが大きい場合有用) package{knitr}: dat
RからStanやJAGSを実行して得られるMCMCサンプルは、一般的に iterationの数×chainの数×パラメータの次元 のようなオブジェクトとなっており、凝った操作をしようとするとかなりややこしいです。 『StanとRでベイズ統計モデリング (Wonderful R)』のなかでは、複雑なデータ加工部分は場合によりけりなので深入りしないで、GitHub上でソースコードを提供しています。そこでは、ユーザが新しく覚えることをなるべく少なくするため、Rの標準的な関数であるapply関数群を使っていろいろ算出しています。しかし、apply関数群は慣れていない人には習得しづらい欠点があります。 一方で、Rのデータ加工パッケージとして、%>%によるパイプ処理・{dplyr}パッケージ・{tidyr}パッケージがここ最近よく使われており、僕も重い腰を上げてやっと使い始めたのですが、これが凄く使い
僕が筆者なので、この記事は書評ではなく紹介になります。まずこの本はRのシリーズの一冊にもかかわらずStanという統計モデリングのためのプログラミング言語の方がメインです。このようなわがままを許してくれた、ゆるいふところの深い石田先生と共立出版には感謝しかありません。 StanとRでベイズ統計モデリング (Wonderful R) 作者:健太郎, 松浦発売日: 2016/10/25メディア: 単行本 目次と概要 共立出版のページを見てください。GitHubのリポジトリもあります。 前提とする知識 「はじめに」の部分で触れていますが、確率と統計の基本的な知識はある方、R(やPython)で簡単なデータ加工や作図が一通りできる方を想定しています。そのため、確率分布なんて聞いたことがない、プログラミングがはじめて、Rがはじめて、という方が読み進めるのは厳しいかもしれません。なお、Rの基本的な関数し
この記事では階層ベイズモデルの場合のWAICとは何か、またその場合のWAICの高速な算出方法について書きます。 背景 以下の2つの資料を参照してください。[1]に二種類の実装が載っています。[2]に明快な理論的補足が載っています。 [1] 階層ベイズとWAIC (清水先生の資料です、slideshare) [2] 階層ベイズ法とWAIC (渡辺先生の資料です、pdf, html) モデル1 資料[1]にあるモデルを扱います。すなわち、 ここでは人数、は人のインデックスです。は個人差を表す値になります。このモデルにおいてはを解析的に積分消去することができて、負の二項分布を使う以下のモデル式と等価になります。 ここでは予測として(WAICとして)2通り考えてみましょう。 以降では事後分布による平均を、分散をと書くことにします。 (1) を持つが、追加で新しく1つのサンプルを得る場合 この場合に
このページをご覧いただき、ありがとうございます。 ここでは、情報量規準 WAIC を紹介しています。 ベイズ推測のための情報量規準(WAIC)が導出されました。 WAIC は(真の分布、確率モデル、事前分布)がどのような場合でも使う ことができます。他の規準と異なり理論的な基盤を持っています。 (0) モデル選択やハイパーパラメータの最適化に使えます。 (1) 漸近的に汎化損失と同じ平均値と同じ分散を持ちます。 (2) WAIC は簡単に計算できます。 (3) 真の分布が確率モデルで実現可能でなくても使えます。事前分布が真の事前分布でなくても使えます。 (4) 平均対数損失を最小にするパラメータがユニークでなくても使えます。 平均対数損失を最小にするパラメータが特異点を含む解析的集合であっても 使えます(注1)。 (5) フィッシャー情報行列が正則でなくても使えます。 (6) 事後分布が正
時系列データにt 検定を行うことに関して、すごいもにょっていたのだが、そもそもstan 神が既にモデル化してくれていた。 リンクでは2階差分と、変化点検出のコーシー分布の合わせ技を用いている。 そのままパクってやってみる。 diの95%ベイズ信頼区間が0を含んでいない期間が差がある期間と言えるでしょう。さらに、どこから差がありそうなのか、どれほど差がありそうなのかも確率付きで述べることができます。 ということが、stan による柔軟なモデリングで述べることができます。 話は飛ぶけど、読んだ。 はじめての 統計データ分析 ―ベイズ的〈ポストp値時代〉の統計学― 作者: 豊田秀樹出版社/メーカー: 朝倉書店発売日: 2016/06/02メディア: 単行本(ソフトカバー)この商品を含むブログ (11件) を見る 書評はまた書くけれども、この時系列データと同じように、この本では、例えば分散分析や分
RStan2.9.0がリリースされました。今まで{rstan}パッケージのsampling関数を使っていたところを、vb関数に変更するだけでサンプリングのアルゴリズムをNUTSからADVI(Automatic Differentiation Variational Inference)に変更することができます。ADVIはユーザーが変分下限の導出や近似分布qを用意をすることなしに、自動的に変分ベイズしてくれます。得られるアウトプットはNUTSとほぼ同様で近似事後分布からの乱数サンプルです。ウリはスピードです。NUTSもADVIもデフォルトのオプションのまま実行して、NUTSと比べて50倍ぐらいスピードが出ることもあります。 NUTSと同様にADVIは効率的な探索のため偏微分を使っているので、離散値をとるパラメータは使えませんが、やはり同様に離散パラメータを消去すれば実行できます。そして、微分
ggmcmc is an R package aimed at providing tools for assessing and diagnosing convergence of Markov Chain Monte Carlo simulations, as well as for graphically display results from full MCMC analysis. The package also facilitates the graphical interpretation of models by providing flexible functions to plot the results against observed variables. Development ggmcmc is developed in github and has attr
この記事では統計的問題を回避するためのデータ解析のプロトコル (Zuur et al. 2010)で扱われているゼロ過剰問題を取り扱っている。 uribo.hatenablog.com 離散値の整数かならるカウントデータの多くはポアソン分布に従うことが一般的である。しかし、ある生息地における生物の観察数やスポーツにおける試合の得点など、0を多く含むデータが存在する。 そうしたデータについて統計モデルを適用する場合、ポアソン分布や負の二項分布を仮定した一般化線形モデル GLMなどを行うと、ポアソン分布で期待されるよりも過剰(あるいは過少)にデータが観測されることがあり推定がうまくいかないことがある。そのデータのように0の割合が多いデータに対して有効なモデルがゼロ過剰なポアソン分布モデル Zero-inflated Poisson Distribution: ZIPモデルである。 📉 カウン
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く