Skip to content

Instantly share code, notes, and snippets.

View ytarazona's full-sized avatar

Yonatan Tarazona Coronel ytarazona

View GitHub Profile
@ytarazona
ytarazona / Change detection.R
Last active August 23, 2017 14:49
Change detection with time series and machine learning
#' @author Yonatan Tarazona Coronel
#'
# DETECCION DE CAMBIOS CON SERIES TEMPORALES Y MACHINE LEARNING - TELEDETECCION
## 1. APRENDIZAJE SUPERVISADO
### PASOS
#### i. Imágenes y librerías en R
#### ii. Datos de entrenamiento
#### iii. Training-Testing y aprendizaje del modelo
#### iv. Evaluamos el modelo y Aplicar el modelo a individuos nuevos
# Simulamos una matriz de un raster con filas y columnas
M <- matrix(c(11:14,9:12,21:24,1:4),4,4) # Raster convertido a matriz
i <- ncol(M); j <- nrow(M) # número de columnas y filas
# Crear las medias para cada columna
M_mean <- matrix(data=1, nrow=i) %*% cbind(mean(M[,1]),mean(M[,2]),mean(M[,3]),mean(M[,4]))
# Creamos una diferencia de Matriz
DIF <- M - M_mean
# Obtenemos la matriz de covarianza
COV <- (i-1)^-1*t(DIF) %*% DIF
COV