Skip to content

Instantly share code, notes, and snippets.

@abikoushi
abikoushi / CanonicalFormNormal.R
Created December 29, 2025 10:18
Canonical form parametrized normal distribution
rcfnorm <- function(n, shape=0, inv_scale=1){
rnorm(n, shape/inv_scale, 1/sqrt(inv_scale))
}
dcfnorm <- function(n, shape=0, inv_scale=1, ...){
dnorm(n, shape/inv_scale, 1/sqrt(inv_scale), ...)
}
pcfnorm <- function(n, shape=0, inv_scale=1, ...){
pnorm(n, shape/inv_scale, 1/sqrt(inv_scale), ...)
@abikoushi
abikoushi / readmtxfiles_asALTO.R
Last active December 26, 2025 00:51
read MM file as ALTO format
size_mtx <- function(file_path){
con <- file(file_path, open = "r") #Open for reading in text mode
size <- scan(con, what=integer(), comment.char = "%", nlines = 1, skip = 1, quiet = TRUE)
close(con)
names(size) <- c("row","column","nonzero")
return(size)
}
take_last <- function(x){
x[length(x)]
@abikoushi
abikoushi / spread.tex
Created December 24, 2025 04:45
A TikZ picture of ALTO spread
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{matrix,positioning,quotes}
\begin{document}
\tikzset{
table/.style={
matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={
@abikoushi
abikoushi / HairEye2.tex
Created December 24, 2025 03:45
A TikZ picture of HairEyeColor data as ALTO format
%ref:
%https://tex.stackexchange.com/questions/516073/how-to-draw-3d-matrix-using-tikz
%https://tikz.net/tikz-table/
%https://tikz.net/conv2d/
%
\documentclass[tikz,border=10pt]{standalone}
\usepackage[dvipsnames]{xcolor}
\usetikzlibrary{matrix,positioning}
\begin{document}
@abikoushi
abikoushi / HairEye.tex
Created December 22, 2025 11:02
A TikZ picture of HairEyeColor data as ALTO format
%ref:
%https://tex.stackexchange.com/questions/516073/how-to-draw-3d-matrix-using-tikz
%https://tikz.net/tikz-table/
%https://tikz.net/conv2d/
%
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{matrix,positioning}
\begin{document}
\tikzset{
@abikoushi
abikoushi / HairEye.tex
Created December 22, 2025 04:51
A TikZ picture of HairEyeColor data
%ref:
%https://tex.stackexchange.com/questions/516073/how-to-draw-3d-matrix-using-tikz
%https://tikz.net/tikz-table/
%
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{matrix,positioning}
\begin{document}
\tikzset{
table/.style={
@abikoushi
abikoushi / ALTO_bitmask.R
Created December 21, 2025 13:02
gather & spread of ALTO (adaptive linearized tensor operation)
#ref:
#Jan Laukemann et al. (2025) Accelerating Sparse Tensor Decomposition Using Adaptive Linearized Representation
#https://arxiv.org/abs/2403.06348
ALTO_indexing <- function(object, data = environment(object), ...) {
mf <- model.frame(object, data, ...)
t <- if (missing(data)) terms(object) else terms(object, data = data)
labs <- attr(t, "term.labels")
mf <- lapply(labs, function(x) {
@abikoushi
abikoushi / overparametrize.R
Created December 21, 2025 10:09
冗長性のあるワンホットエンコーディングによるパラメータ化の係数をフルランクの計画行列の係数に変換する
library(moltenNMF)
library(Matrix)
df = expand.grid(letters[1:2], LETTERS[1:2])
X = sparse_onehot(~., data = df)
A = matrix(
c(0.5, 0.5, 0.5, 0.5, 0, 1, 0, 0, 0, 0, 0, 1),
nrow = 4,
ncol = 3
@abikoushi
abikoushi / ALTO_indexing.R
Last active December 20, 2025 11:31
ALTO (adaptive linearized tensor operation) indexing
#ref:
#Jan Laukemann et al. (2025) Accelerating Sparse Tensor Decomposition Using Adaptive Linearized Representation
#https://arxiv.org/abs/2403.06348
library(dplyr)
ALTO_indexing <- function(object, data = environment(object), ...) {
mf <- model.frame(object, data, ...)
t <- if (missing(data)) terms(object) else terms(object, data = data)
labs <- attr(t, "term.labels")
@abikoushi
abikoushi / get_MERS_table.R
Last active December 19, 2025 01:51
get MERS-2025 data using rvest
library(ggplot2)
library(dplyr)
library(tidyr)
library(rvest)
library(readr)
url = "https://ja.wikipedia.org/wiki/2015年韓国におけるMERSの流行"
taball <- read_html(url) |>
html_table()