Skip to content

Instantly share code, notes, and snippets.

View alstat's full-sized avatar

Al Asaad alstat

View GitHub Profile
@alstat
alstat / ts-1.jl
Last active February 10, 2020 15:29
using Dates
using Distributions
using HypothesisTests: ADFTest, LjungBoxTest
using Knet
using Measures
using Plots
using PlotThemes
using Random
using StatsBase: autocor, pacf
using Turing
set.seed(1)
x1 <- rnorm(10)
x2 <- rnorm(10)
out <- cbind(x1, x2)
colMeans(out)
# colMeans can be computed as follows as well
apply(out, 2, mean)
# apply - applies a mean function to column (indicated by 2) of out matrix
# Simulating the data
set.seed(73735911)
#set.seed(737377911)
n=100;nu=5;alpha=2;beta=2;sig=1;true=c(alpha,beta,nu)
x=rnorm(n,1,1)
y=alpha+beta*x+sig*rt(n,nu)
par(mfrow=c(1,1))
plot(x,y, col='blue3', pch=19)
@alstat
alstat / code-turing.jl
Created February 4, 2019 16:03
Turing.jl Tutorial on Bayesian Linear Regression
using Turing, Distributions
# Import RDatasets.
using RDatasets
# Import MCMCChain, Plots, and StatPlots for visualizations and diagnostics.
using MCMCChain, Plots, StatPlots
# MLDataUtils provides a sample splitting tool that's very handy.
using MLDataUtils
rz_helper = function() {
y1 = rexp(1, 1) # step 1
y2 = rexp(1, 1) # step 2
# step 3
while (y2 <= ((y1 - 1)^2)/2) {
y1 = rexp(1, 1)
}
# step 4
f, a = subplots(10, 20)
for i in arange(10):
for j in arange(20):
a[i, j].imshow(x_train[j + 20 * i])
a[i, j].axis("off")
a[i, j].set_adjustable('box-forced')
f.savefig("img1.png", bbox_inches='tight', pad_inches = 0)
items <- list(x_train, y_train, x_test, y_test)
dim_formatter <- function (x) {
if (length(dim(x)) > 2)
paste("(", dim(x)[1], ", ", dim(x)[2], " , ", dim(x)[3], " , ", dim(x)[4], ")", sep = "")
else
paste("(", dim(x)[1], ", ", dim(x)[2], ")", sep = "")
}
# training set
items = [x_train, y_train, x_test, y_test]
# training set
[type(item) for item in items[:2]] # [<type 'numpy.ndarray'>, <type 'numpy.ndarray'>]
[item.shape for item in items[:2]] # [(50000, 32, 32, 3), (50000, 1)]
# testing set
[type(item) for item in items[2:]] # [<type 'numpy.ndarray'>, <type 'numpy.ndarray'>]
[item.shape for item in items[2:]] # [(10000, 32, 32, 3), (10000, 1)]
cifar100 <- dataset_cifar100(label_mode = "fine")
x_train <- cifar100$train$x; y_train <- cifar100$train$y
x_test <- cifar100$test$x; y_test <- cifar100$test$y
(x_train, y_train), (x_test, y_test) = cifar100.load_data(label_mode = "fine")