Skip to content

Instantly share code, notes, and snippets.

@matsueushi
matsueushi / gaussianrandomwalk.jl
Created April 4, 2019 03:39
GaussianRandomWalk for Mamba
# GaussianRandomWalk for Mamba
# \begin{align*}
# Y_0 &= D,\\
# Y_{i+1} &= Y_i+\mu_i+\epsilon_i,\ \epsilon_i \sim \mbox{Normal}(0, \sigma)\\
# \end{align*}
# Reference:
# Create User-Defined Multivariate Distribution
# https://mambajl.readthedocs.io/en/latest/mcmc/distributions.html#user-defined-univariate-distributions
function rolling(fun::Function, x::AbstractArray{T}, window::Int) where {T <: Real}
[fun(view(x, i:i + window - 1)) for i = 1:length(x) - window + 1]
end
println(rolling(sum, [1, 2, 3, 4, 5], 2)) # [3, 5, 7, 9]
println(rolling(sum, [1, 2, 3, 4, 5], 3)) # [6, 9, 12]
println(rolling(prod, [1, 2, 3, 4, 5], 3)) # [6, 24, 60]
@matsueushi
matsueushi / adapt.jl
Last active January 9, 2020 04:32
gpu, similar, cpu, adapt
using Adapt
using CuArrays
using Flux
using InteractiveUtils
function f1(x)
fill(1f0, size(x)) |> gpu
end
function f2(x)
@matsueushi
matsueushi / bce.ipynb
Last active January 26, 2020 16:55
(logit)binarycrossentropy
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@matsueushi
matsueushi / Dockerfile
Last active March 31, 2020 01:37
Julia GPU
ARG CUDA=10.0
ARG UBUNTU_VERSION=18.04
FROM nvidia/cuda:${CUDA}-cudnn7-devel-ubuntu${UBUNTU_VERSION}
ENV JULIA_PATH=/usr/local/julia
ENV PATH=$JULIA_PATH/bin:$PATH
ENV JULIA_TAR_ARCH=x86_64
ENV JULIA_DIR_ARCH=x64
using CuArrays, NNlib, Test

ACTIVATION_FUNCTIONS = [σ, logσ, hardσ, hardtanh, relu, leakyrelu, relu6, rrelu, 
                          elu, gelu, celu, swish, lisht, selu, trelu, softplus, 
                          softsign, logcosh, mish, tanhshrink, softshrink];

x = randn(Float32, (5, 5))
for f in filter(x -> x != rrelu, ACTIVATION_FUNCTIONS)
 @testset "$(f)" begin
└ @ Pkg.Operations /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/Pkg/src/Operations.jl:1365
ERROR: Unsatisfiable requirements detected for package Polynomials [f27b6e38]:
Polynomials [f27b6e38] log:
├─possible versions are: [0.5.0-0.5.3, 0.6.0-0.6.1, 0.7.0] or uninstalled
├─restricted to versions 0.6 by an explicit requirement, leaving only versions 0.6.0-0.6.1
└─restricted by compatibility requirements with RecipesBase [3cdcf5f2] to versions: [0.5.0-0.5.3, 0.7.0] or uninstalled — no versions left
└─RecipesBase [3cdcf5f2] log:
├─possible versions are: [0.4.0, 0.5.0, 0.6.0, 0.7.0, 0.8.0, 1.0.0] or uninstalled
└─restricted to versions 1 by IntervalArithmetic [d1acc4aa], leaving only versions 1.0.0
└─IntervalArithmetic [d1acc4aa] log:
function solve(n, m, ts, xss, ss)
mat = BitArray(undef, n, m)
for i in 1:n
for j in 1:ts[i]
mat[i, xss[i][j]] = 1
end
end
println(mat)
s = BitArray(ss)
c = 1
@matsueushi
matsueushi / sadservers.md
Last active November 23, 2022 13:36
sadserver解き方
  1. "Saint John": what is writing to this log file?

ファイルをオープンしているコマンドは lsof コマンドで調べられる。

ubuntu@ip-172-31-32-108:/$ lsof /var/log/bad.log
COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF  NODE NAME
badlog.py 637 ubuntu    3w   REG  259,1    25744 67701 /var/log/bad.log

kill でコマンドを止める。