-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmvcd-v2.Rmd
111 lines (100 loc) · 4.2 KB
/
fmvcd-v2.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
title: "NNETCLI - filling in missing values in climate data"
author: "IVA"
date: '23.1.17'
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
### The calculation of all values of the vector by the neural network
```{r compute}
compute_all <- function(net.train, Time){
return(compute(net.train, Time)$net.result)
}
```
### filling the gaps
```{r filling}
fillin_missing_data <- function(vector_cli, nnet_cli, NORM_TEMP){
for(i in (1: length(vector_cli))){
if(is.na(vector_cli[i])){
vector_cli[i] <- as.integer(nnet_cli[i] * NORM_TEMP)
}
}
return(vector_cli)
}
```
### The construction of neural models and the calculation of missing data
```{r nnet_cli}
library(neuralnet)
NORM_TEMP <- 450.0; NORM_TIME <- 370.0; NUM_TRAIN <- 65; HIDDEN <- 11
NUM_TRAIN <- 265; HIDDEN <- 32
nnet_cli <- function(vector_cli, vec_type = "temp"){
if( length(vector_cli) < 365) warning("Your year has fewer than 365 days")
Temp <- vector_cli / NORM_TEMP
Time <- (1:length(Temp)) / NORM_TIME
year_data <- data.frame(Time, Temp)
if(nrow(year_data) - nrow(na.omit(year_data)) == 0){
cat("The vector does not contain missing values\n")
return(vector_cli)
} else {
train <- na.omit(year_data)
train <- train[sample(nrow(train), NUM_TRAIN), ]
net.train <- neuralnet(Temp~Time, train, hidden = HIDDEN, threshold = 0.01, linear.output=TRUE)
cat("Error=", net.train$result.matrix[1],"\n")
nnet_cli <- compute_all(net.train, Time)
fillin_vector_cli <- fillin_missing_data(vector_cli, nnet_cli, NORM_TEMP)
}
return(fillin_vector_cli)
}
```
## Read cliData
```{r read_cli}
#rm(list=ls())
filled_path <- "C:/Users/teipolykom/git/fmvcd/krest/"
#filled_path <- "Z:/home/larisa/Dropbox/git/fmvcd/krest/"
#filled_path <- "/home/larisa/Dropbox/git/fmvcd/krest/"
setwd(filled_path); getwd()
file_list <- list.files(pattern = "\\.cli$"); file_list
cat("**************************************************\n")
for (file in file_list){
temp_cli_dataset <-read.table(file, header=FALSE, sep="")
names(temp_cli_dataset) <- c("day", "month", "year", "prec", "temp");
# print(summary(temp_cli_dataset))
temp_cli_dataset[temp_cli_dataset$prec == -9999, 4] <- NA
temp_cli_dataset[temp_cli_dataset$temp == -9999, 5] <- NA
temp_vector <- temp_cli_dataset[, 5]
prec_vector <- temp_cli_dataset[, 4]
cat("\n Year=", temp_cli_dataset[1, 3], "\n")
print(summary(temp_cli_dataset[, c(4 ,5)]))
# There are missing data for precipitation
prec_vector <- nnet_cli(prec_vector, vec_type = "prec")
# Has missing temperature data
temp_vector <- nnet_cli(temp_vector, vec_type = "temp")
# Collect new dataset
filled_cli <- data.frame(temp_cli_dataset[, c(1, 2, 3)], prec_vector, temp_vector)
names(filled_cli) <- c("day", "month", "year", "prec", "temp")
print(summary(filled_cli[, c(4 ,5)]))
cat("========================================\n")
# http://stackoverflow.com/questions/4216753/check-existence-of-directory-and-create-if-doesnt-exist
# http://stackoverflow.com/questions/14219887/how-to-delete-a-file-with-r
write.table(filled_cli, file=paste(filled_path, "/filled/", file, sep=""), row.names = FALSE)
}
```
##
+ http://abiyug.github.io/2016-04-05-shiny-web-app-hosting-on-github
+ http://shiny.stat.iastate.edu/ajkaplan/gravicom/
+ http://deanattali.com/projects/
```{r libs, echo=FALSE}
# Каллан Р. Основные концепции нейронных сетей
# https://habrahabr.ru/company/paysto/blog/245051/
# http://karpathy.github.io/neuralnets/
# https://www.datascienceweekly.org/data-scientist-interviews/training-deep-learning-models-browser-andrej-karpathy-interview
# http://cs.stanford.edu/people/karpathy/convnetjs/started.html
# http://savepearlharbor.com/?p=246523
# https://tproger.ru/translations/javascript-brain-neural-framework/
# https://tproger.ru/digest/learning-neuroweb-all-for-begin/
# https://tproger.ru/digest/learning-neuroweb-all-for-begin/
# http://statweb.stanford.edu/~tibs/ElemStatLearn/
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.