API レファレンス
| stan.build() | スタンプログラムをコンパイルする。 |
| class stan.model.Model() | Stanモデルへのプロキシ呼び出しに関連するデータを保存する。 |
| fixed_param | モデルからサンプルを書き出す |
| grad_log_prob | 対数事後評価のグラジェントを計算する。 |
| hmc_nuts_diag_e_adapt() | モデルからサンプルを書き出す。 |
| log_prob() | 非制約変数のセットの対数確率を計算する。 |
| sample() | モデルからサンプルを書き出す。 |
| unconstraint_pairs() | 特定のコンテキストから制約パラメータを読み込んで、非制約パラメータのシーケンスを戻す。 |
| class stan.fit.fit | 一つ以上のチェインの出力を保存する。 |
| class stan.plugins.PluginBase() | pyStanプラグインのベースクラス |
| on_post_sample() | サンプリング終了時にfitインスタンスを呼び出す。 |
stan.build
stanプログラムをコンパイルする。
stan.build(program_code: str, data: Dict[str, Union[int, float, Sequence[Union[int, float]]]] = {}, random_seed: Optional[int] = None)| 変数 | |
| Program_code | Stanモデルを記述したStanプログラム |
| data | モデルに渡すPython dict型データ。デフォルト値は空のdict |
| random_seed | ランダムシード。乱数を生成する正の整数。 |
stan.model.Model
Stanモデルへのプロキシ呼び出しに関連したデータを保存する。
class stan.model.Model(model_name: str, program_code: str, data: Dict[str, Union[int, float, Sequence[Union[int, float]]]], param_names: Tuple[str, ...], constrained_param_names: Tuple[str, ...], dims: Tuple[Tuple[int, ...]], random_seed: Optional[int])| 変数 | |
| unconstrained_parameters | 非制約パラメータのシーケンス |
| include_tparams | 変換パラメータを含めるかどうかの操作フラグ(真偽値) |
| include_gqs | 生成量を含めるかどうかの操作フラグ(真偽値) |
fixed_param
stanのstan::services::sample::fixed_param を使ってモデルからサンプルを出力する。
fixed_param(*, num_chains=4, **kwargs)grad_log_prob
対数事後評価のグラジェントを計算する。
grad_log_prob(unconstrained_parameters: Sequence[float])| 変数 | |
| unconstrained_parameters | 非制約パラメータのシーケンス |
hmc_nuts_diag_e_adapt
stanのstan::services::sample::hmc_nuts_diag_e_adaptを使ってモデルからサンプルを出力する。
hmc_nuts_diag_e_adapt(*, num_chains=4, **kwargs)log_prob
非制約パラメータセットの対数確率を計算する。
log_prob(unconstrained_parameters: Sequence[float], adjust_transform: bool = True)| 変数 | |
| unconstrained_parameters | 非制約パラメータのシーケンス |
| adjust_transform | ヤコビアン適合変換を適用する |
sample
モデルからサンプルを出力する
sample(*, num_chains=4, **kwargs)サンプルコード
まず、チェインにパラメータの初期値を与えます。
>>> program_code = "parameters {real y;} model {y ~ normal(0,1);}"
>>> posterior = stan.build(program_code)
>>> fit = posterior.sample(num_chains=2, init=[{"y": 3}, {"y": 3}])unconstrain_pairs
特定のコンテキストから制約パラメータを読み込み、非制約パラメータのシーケンスを戻す。
unconstrain_pars(constrained_parameters: Sequence[float])| 変数 | |
| unconstrained_parameters | 制約パラメータのシーケンス |
stan.fit.Fit
一つ以上のチェインからの出力を保存する。Pandasデータフレームに出力したデータを返す。
class stan.fit.Fit(stan_outputs: Tuple[bytes, ...], num_chains: int, param_names: Tuple[str, ...], constrained_param_names: Tuple[str, ...], dims: Tuple[Tuple[int, ...]], num_warmup: int, num_samples: int, num_thin: int, save_warmup: bool)stan.plugins.PluginBase
プラグイン開発者はこのクラスPluginBaseのサブクラスを生成します。このクラスはパッケージのエントリーポイントとして参照されます。
class stan.plugins.PluginBase