Skip to content

Instantly share code, notes, and snippets.

View mick001's full-sized avatar

Michy mick001

View GitHub Profile
@mick001
mick001 / convolutional_nn_tutorial_2.R
Last active March 13, 2019 08:16
Image recognition tutorial in R using deep convolutional neural networks (MXNet package). Part 2. Full article at https://firsttimeprogrammer.blogspot.com/2016/08/image-recognition-tutorial-in-r-using.html
# This script is used to resize images from 64x64 to 28x28 pixels
# Clear workspace
rm(list=ls())
# Load EBImage library
require(EBImage)
# Load data
X <- read.csv("olivetti_X.csv", header = F)
@mick001
mick001 / convolutional_nn_tutorial_1.py
Last active March 13, 2019 08:16
Image recognition tutorial in R using deep convolutional neural networks (MXNet package). Part 1. Full article at https://firsttimeprogrammer.blogspot.com/2016/08/image-recognition-tutorial-in-r-using.html
# -*- coding: utf-8 -*-
# Imports
from sklearn.datasets import fetch_olivetti_faces
import numpy as np
# Download Olivetti faces dataset
olivetti = fetch_olivetti_faces()
x = olivetti.images
y = olivetti.target
@mick001
mick001 / rnn_example.R
Last active April 17, 2019 12:54
Sine wave prediction with recurrent neural networks in R. Full article at: https://firsttimeprogrammer.blogspot.com/2016/08/plain-vanilla-recurrent-neural-networks.html
# Clear workspace
rm(list=ls())
# Load libraries
require(rnn)
# Set seed for reproducibility purposes
set.seed(10)
# Set frequency
@mick001
mick001 / im_rec_3.R
Last active March 13, 2019 08:16
Image recognition in R using convolutional neural networks with the MXNet package. Part 2. Full article at: https://firsttimeprogrammer.blogspot.com/2016/07/image-recognition-in-r-using.html
rm(list=ls())
# Load MXNet
require(mxnet)
# Train test datasets
train <- read.csv("train_28.csv")
test <- read.csv("test_28.csv")
# Fix train and test datasets
@mick001
mick001 / im_rec_2.R
Last active March 13, 2019 08:15
Image recognition in R using convolutional neural networks with the MXNet package. Part 2. Full article at: https://firsttimeprogrammer.blogspot.com/2016/07/image-recognition-in-r-using.html
# Generate a train-test dataset
# Clean environment and load required packages
rm(list=ls())
require(EBImage)
# Set wd where resized greyscale images are located
setwd("C://dogs_resized")
# Out file
@mick001
mick001 / im_rec_1.R
Last active March 13, 2019 08:15
Image recognition in R using convolutional neural networks with the MXNet package. Part 1. Full article at: https://firsttimeprogrammer.blogspot.com/2016/07/image-recognition-in-r-using.html
# Resize images and convert to grayscale
rm(list=ls())
require(EBImage)
# Set wd where images are located
setwd("C://dogs_images")
# Set d where to save images
save_in <- "C://dogs_images_resized"
# Load images names
@mick001
mick001 / pressure_drop_revised.py
Last active July 23, 2016 23:38
Pressure drop in a circular section pipe simulation. Read the full article at https://firsttimeprogrammer.blogspot.com/2016/07/fluid-dynamics-pressure-drop-modelling.html
# Imports
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from numpy import vectorize
# Let's define the variables
Q = np.linspace(0.01,1,50) # Flow rate m^3/s
@mick001
mick001 / copulas_revised_2_7.R
Created March 27, 2016 21:36
How to fit a copula model in R [heavily revised]. Part 2: fitting the copula. Full article at
# Sample 1000 observations from the distribution
sim <- rmvdc(my_dist, 1000)
# Plot the data for a visual comparison
plot(mydata$x, mydata$y, main = 'Test dataset x and y', col = "blue")
points(sim[,1], sim[,2], col = 'red')
legend('bottomright', c('Observed', 'Simulated'), col = c('blue', 'red'), pch=21)
cor(mydata, method = "kendall")
## x y
@mick001
mick001 / copulas_revised_2_6.R
Created March 27, 2016 21:36
How to fit a copula model in R [heavily revised]. Part 2: fitting the copula. Full article at
# Build the bivariate distribution
my_dist <- mvdc(claytonCopula(param = 1.48, dim = 2), margins = c("gamma","gamma"), paramMargins = list(list(shape = x_shape, rate = x_rate), list(shape = y_shape, rate = y_rate)))
# Generate random sample observations from the multivariate distribution
v <- rMvdc(5000, my_dist)
# Compute the density
pdf_mvd <- dMvdc(v, my_dist)
# Compute the CDF
cdf_mvd <- pMvdc(v, my_dist)
@mick001
mick001 / copulas_revised_2_5.R
Created March 27, 2016 21:36
How to fit a copula model in R [heavily revised]. Part 2: fitting the copula. Full article at
gf <- gofCopula(normalCopula(dim = 2), as.matrix(mydata), N = 50)
gf
## Parametric bootstrap goodness-of-fit test with 'method'="Sn", 'estim.method'="mpl"
##
## data: x
## statistic = 0.29449, parameter = 0.59983, p-value = 0.009804
gfc <- gofCopula(claytonCopula(dim = 2), as.matrix(mydata), N = 50)
gfc