Skip to content

Instantly share code, notes, and snippets.

View doraneko94's full-sized avatar

Shuntaro Ohno doraneko94

View GitHub Profile
@doraneko94
doraneko94 / partial_transposition.py
Created December 5, 2018 01:15
Calculating partial transposition.
import numpy as np
from math import sqrt
def partial_transposition(density_matrix: np.ndarray, basis_num_1: int=0, basis_num_2: int=0):
if basis_num_1 == 0 and basis_num_2 == 0:
basis_num_1 = int(sqrt(density_matrix.shape[0]))
basis_num_2 = basis_num_1
elif basis_num_1 == 0:
basis_num_1 = int((density_matrix.shape[0])/basis_num_2)
elif basis_num_2 == 0:
@doraneko94
doraneko94 / roc_auc_ci.py
Last active January 4, 2025 08:56
Calculating confidence interval of ROC-AUC.
from sklearn.metrics import roc_auc_score
from math import sqrt
def roc_auc_ci(y_true, y_score, positive=1):
AUC = roc_auc_score(y_true, y_score)
N1 = sum(y_true == positive)
N2 = sum(y_true != positive)
Q1 = AUC / (2 - AUC)
Q2 = 2*AUC**2 / (1 + AUC)
SE_AUC = sqrt((AUC*(1 - AUC) + (N1 - 1)*(Q1 - AUC**2) + (N2 - 1)*(Q2 - AUC**2)) / (N1*N2))
@doraneko94
doraneko94 / gamepad.py
Created March 23, 2019 04:11
Controlling a mouse with a gamepad. This code is optimized for "LOGICOOL gamepad F301r".
import pygame
from pygame.locals import *
import time, sys
import pyautogui
def main():
pyautogui.FAILSAFE = False
pygame.init()
while True:
@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;
@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 / 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 / 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 / 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 / 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 / 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.