Skip to content

Instantly share code, notes, and snippets.

@bakfoo
bakfoo / yacobianconj.ipynb
Last active July 20, 2026 14:26
A Counterexample to the Jacobian Conjecture
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
from tqdm import tqdm
# --- モデルの微分方程式を定義する関数 ---
def attrition_model_ode(t, y, params, rand_vals):
P1, P2, Q1, Q2, C1, C2, N1, N2 = y
P1, P2, Q1, Q2, N1, N2 = max(0, P1), max(0, P2), max(0, Q1), max(0, Q2), max(0, N1), max(0, N2)
from collections import Counter
import sys
import time
import ray
""" This script is meant to be run from a pod in the same Kubernetes namespace
as your Ray cluster.
"""
@ray.remote
# Job to submit a Ray program from a pod outside a running Ray cluster.
apiVersion: batch/v1
kind: Job
metadata:
name: ray-test-job
spec:
template:
spec:
restartPolicy: Never
containers:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
make examples/bernoulli/bernoulli
cd examples/bernoulli/
./bernoulli sample data file=bernoulli.data.R
./bernoulli variational data file=bernoulli.data.R
> print(rats_fit)
Inference for Stan model: rats.
4 chains, each with iter=1000; warmup=500; thin=1;
post-warmup draws per chain=500, total post-warmup draws=2000.
mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
alpha[1] 239.90 0.07 2.70 234.72 238.03 239.90 241.71 245.11 1595 1.00
alpha[2] 247.89 0.06 2.78 242.43 246.02 247.94 249.74 253.40 2000 1.00
alpha[3] 252.53 0.06 2.76 247.12 250.71 252.57 254.35 257.86 1838 1.00
alpha[4] 232.53 0.06 2.71 227.16 230.69 232.56 234.40 237.75 1797 1.00
@bakfoo
bakfoo / rats_stan_advi.R
Last active November 11, 2020 22:28
Rstan ADVI Test using rats examples.
y <- read.table('https://raw.github.com/wiki/stan-dev/rstan/rats.txt', header = TRUE)
x <- c(8, 15, 22, 29, 36)
xbar <- mean(x)
N <- nrow(y)
T <- ncol(y)
data <- list(y=y, x=x, xbar=xbar, N=N, T=T)
rats_model <- stan_model(file = "https://raw.githubusercontent.com/stan-dev/example-models/master/bugs_examples/vol1/rats/rats.stan")
#NUTS

PyCon Jp 2015「エンジニアのためのベイズ推定入門」要項

0 チュートリアル環境の構築前の注意

確率論的プログラミングはまだ若い分野ですので,計算環境の構築方法が成熟していません.チュートリアルではpymc3やpystanを利用しますが,それらの開発者は基本的にUbuntuにAnaconda Pythonを利用してるので,まともに動作する環境はどうしてもUbuntu + Anacondaが中心になってしまいます.以下に構築前の注意を列挙します.

  • Windowsで確率論的プログラミングを行うことは,pymc3のtheanoのGPUの問題,pystanのプロセス制限の問題等,制約が多すぎて困難な道となります.Windowsを利用する場合,VMWare, VirtualBox, Vagrant等の仮想環境またはDocker等のコンテナ技術を利用してLinuxを用意するほうが精神衛生上望ましいと考えています.
  • Python環境の構築はAnacondaディストリビューションを前提とします.素のPythonから確率論的プログラミングの環境を構築することは,数々の罠に嵌まる可能性が否定できませんので推奨できません.
  • もしも,チュートリアル当日までに環境を構築できなくても問題ありません.チュートリアルはJupyter Notebookで行いますので,Docker Imageを用意するか,JupyterHub等によりWebブラウザからチュートリアルマテリアルにアクセスし実行できるようにします.
  • 皆様には大変申し訳ございませんが,JupyterHubが技術的理由により用意できませんでした.お詫びを申しあげます.代わりに以下のnbviewerで代替させていただきます.