Skip to content

Instantly share code, notes, and snippets.

View doraneko94's full-sized avatar

Shuntaro Ohno doraneko94

View GitHub Profile
@doraneko94
doraneko94 / watchdog.rs
Created August 30, 2023 21:22
RustでRaspberry Pi PicoのWatchdogタイマを使用するデモ
// This code was inspired by https://github.com/rp-rs/rp-hal/blob/main/rp2040-hal/examples/watchdog.rs
#![no_std]
#![no_main]
use panic_halt as _;
use rp2040_hal as hal;
use hal::pac;
use embedded_hal::digital::v2::OutputPin;
@doraneko94
doraneko94 / plot_error_ellipse.py
Last active January 3, 2024 14:39
Demonstration of plotting an error ellipse (probability ellipse) in Python.
from matplotlib import pyplot as plt
from matplotlib.patches import Ellipse
import numpy as np
fig, ax = plt.subplots(1)
ax.set_aspect('equal')
m = np.array([8, 12])
S = np.array([[16, np.sqrt(78)], [np.sqrt(78), 9]])
r = np.random.multivariate_normal(m, S, size=100) # random points to plot
@doraneko94
doraneko94 / TwoWayAnovaRM.py
Created July 5, 2023 07:50
Python Class for repeated measures two-way ANOVA.
import numpy as np
import pandas as pd
from scipy import stats
class TwoWayAnovaRM:
def __init__(self, data: pd.DataFrame, subject, samples: list):
self.data = data
self.subject = subject
@doraneko94
doraneko94 / Kalman_filter_simulator.ipynb
Created June 3, 2023 04:55
Simulator of Kalman filter.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@doraneko94
doraneko94 / polar.py
Last active October 30, 2022 01:46
Method of learning under constraint by converting parameters to polar coordinates.
import numpy as np
class PolarDiff:
def __init__(self, n, r2=1, x=None, clip=None, epsilon=1e-7):
if x is not None:
if n != len(x):
raise ValueError
self.theta = np.zeros(n-1)
@doraneko94
doraneko94 / molecule.py
Last active July 11, 2021 08:20
2種類の気体分子が円形の容器内で動く様子のシミュレーションを行い、その様子をアニメーションとして保存する。詳細は https://ushitora.net/archives/2197 を参照
# 2種類の気体分子が円形の容器内で動く様子のシミュレーションを行い、
# その様子をアニメーションとして保存する。
# 詳細は https://ushitora.net/archives/2197 を参照
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation as animation
""" データの準備 """
# 乱数で2種類の気体の極座標生成
@doraneko94
doraneko94 / bic.py
Created June 18, 2021 03:35
Compare Raw-BIC and BIC based on RSS.
import numpy as np
from matplotlib import pyplot as plt
from scipy.stats import norm
def bic_raw(x, k):
n = len(x)
return -2 * np.sum(np.log(norm.pdf(x))) + k * np.log(n)
def bic_rss(x, k):
n = len(x)
@doraneko94
doraneko94 / 01kendall.py
Created May 29, 2021 12:02
01-Kendall rank correlation coefficient
import numpy as np
def tau_num(X: np.ndarray, Y: np.ndarray):
XpY = X + Y
XmY = X - Y
A = (XpY == 2).sum()
S = (XpY == 0).sum()
dX = (XmY == 1).sum()
dY = (XmY == -1).sum()
return A * S - dX * dY
@doraneko94
doraneko94 / krypto.py
Last active July 12, 2019 05:55
Full search of the game "krypto".
lst = [11, 10, 22, 10, 25]
ans = 1
tolerance = 1e-4
size = len(lst)
def n_merge(N):
ans = N
for i in range(1, N):
ans *= i**2
return ans
@doraneko94
doraneko94 / ARC028D.cpp
Last active May 6, 2019 11:26
answer for ARC028 D
#include <iostream>
using namespace std;
int N, M, Q;
int a[2010];
long long dp[2010][2010] = {0};
long long rdp[2010][2010] = {0};
long long accum[2010];
const long long mod = 1000000007;