-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.Rhistory
331 lines (331 loc) · 9.41 KB
/
.Rhistory
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# load and prepare data
airbnb <- readRDS("/Users/marquach/Desktop/R_Projects/semi-structured_distributional_regression/application/airbnb/munich_clean.RDS")
airbnb$days_since_last_review <- as.numeric(
difftime(airbnb$date, airbnb$last_review)
)
y = log(airbnb$price)
deep_model_tf <- function(x){
x %>%
layer_dense(units = 5, activation = "relu", use_bias = FALSE) %>%
layer_dropout(rate = 0.2) %>%
layer_dense(units = 3, activation = "relu") %>%
layer_dropout(rate = 0.2) %>%
layer_dense(units = 1, activation = "linear")
}
deep_model_torch <- function() nn_sequential(
nn_linear(in_features = 2, out_features = 5, bias = F),
nn_relu(),
nn_dropout(p = 0.2),
nn_linear(in_features = 5, out_features = 3, bias = T),
nn_relu(),
nn_dropout(p = 0.2),
nn_linear(in_features = 3, out_features = 1))
mod_tf <- deepregression(y = y, data = airbnb,
list_of_formulas =
list(
location = ~ 1 + beds +
s(accommodates, bs = "ps") +
s(days_since_last_review, bs = "tp") +
deep(review_scores_rating, reviews_per_month),
scale = ~1),
orthog_options = orthog_options,
list_of_deep_models = list(deep = deep_model_tf),
engine = "tf"
)
devtools::load_all()
devtools::load_all()
warnings()
mod_tf <- deepregression(y = y, data = airbnb,
list_of_formulas =
list(
location = ~ 1 + beds +
s(accommodates, bs = "ps") +
s(days_since_last_review, bs = "tp") +
deep(review_scores_rating, reviews_per_month),
scale = ~1),
orthog_options = orthog_options,
list_of_deep_models = list(deep = deep_model_tf),
engine = "tf"
)
orthog_options = orthog_control(orthogonalize = F)
# load and prepare data
airbnb <- readRDS("/Users/marquach/Desktop/R_Projects/semi-structured_distributional_regression/application/airbnb/munich_clean.RDS")
airbnb$days_since_last_review <- as.numeric(
difftime(airbnb$date, airbnb$last_review)
)
y = log(airbnb$price)
deep_model_tf <- function(x){
x %>%
layer_dense(units = 5, activation = "relu", use_bias = FALSE) %>%
layer_dropout(rate = 0.2) %>%
layer_dense(units = 3, activation = "relu") %>%
layer_dropout(rate = 0.2) %>%
layer_dense(units = 1, activation = "linear")
}
deep_model_torch <- function() nn_sequential(
nn_linear(in_features = 2, out_features = 5, bias = F),
nn_relu(),
nn_dropout(p = 0.2),
nn_linear(in_features = 5, out_features = 3, bias = T),
nn_relu(),
nn_dropout(p = 0.2),
nn_linear(in_features = 3, out_features = 1))
mod_tf <- deepregression(y = y, data = airbnb,
list_of_formulas =
list(
location = ~ 1 + beds +
s(accommodates, bs = "ps") +
s(days_since_last_review, bs = "tp") +
deep(review_scores_rating, reviews_per_month),
scale = ~1),
orthog_options = orthog_options,
list_of_deep_models = list(deep = deep_model_tf),
engine = "tf"
)
mod_torch <- deepregression(y = y, data = airbnb,
list_of_formulas =
list(
location = ~ 1 + beds +
s(accommodates, bs = "ps") +
s(days_since_last_review, bs = "tp") +
deep(review_scores_rating, reviews_per_month),
scale = ~1), orthog_options = orthog_options,
list_of_deep_models = list(deep = deep_model_torch),
engine = "torch"
)
# Cross validation
res_cv_tf <- mod_tf %>% cv(plot = F, cv_folds = 3, epochs = 10)
res_cv_torch <- mod_torch %>% cv(plot = F, cv_folds = 3, epochs = 10)
devtools::load_all()
# Cross validation
res_cv_tf <- mod_tf %>% cv(plot = F, cv_folds = 3, epochs = 10)
debugonce(cv)
# Cross validation
res_cv_tf <- mod_tf %>% cv(plot = F, cv_folds = 3, epochs = 10)
x_train
str(x_train)
lapply(x_train, function(x)
subset_array(x, train_ind))
subset_array
x
train_ind
na_handler
mod_tf %>% fit(epochs = 10, validation_split = 0.2, verbose = T)
mod_torch %>% fit(epochs = 10, validation_split = 0.2)
debugonce(fit)
mod_torch %>% fit(epochs = 10, validation_split = 0.2)
input_x
debugonce(prepare_data)
prepare_data(object$init_params$parsed_formulas_content,
gamdata = object$init_params$gamdata$data_trafos,
engine = object$engine)
na_handler
na_handler(ret_list)
?na_omit_list
deepregression:::na_omit_list
debugonce(na_handler)
ret_list
loop_through_pfc_and_call_trafo
datalist
mod_torch
debugonce(fit)
mod_torch %>% fit(epochs = 10, validation_split = 0.2)
object$init_params$parsed_formulas_content
object$init_params$gamdata$data_trafos
prepare_data(object$init_params$parsed_formulas_content,
gamdata = object$init_params$gamdata$data_trafos,
engine = object$engine)
str(input_x)
object
input_x
str(input_x)
debugonce(prepare_data)
prepare_data(object$init_params$parsed_formulas_content,
gamdata = object$init_params$gamdata$data_trafos,
engine = object$engine)
pfc
pfc
pfc[[1]]
length(pfc)
pfc[[i]]
length(pfc[[i]])
!is.null(pfc[[i]][[j]]$gamdata_nr
)
!is.null(pfc[[i]][[j]]$gamdata_nr) & engine == 'tf'
pfc[[i]][[j]]
devtools::load_all()
mod_torch %>% fit(epochs = 10, validation_split = 0.2)
debugonce(fit)
mod_torch %>% fit(epochs = 10, validation_split = 0.2)
input_x
str(input_x,1)
debugonce(prepare_data)
prepare_data(object$init_params$parsed_formulas_content,
gamdata = object$init_params$gamdata$data_trafos,
engine = object$engine)
data_list
devtools::load_all()
mod_torch %>% fit(epochs = 10, validation_split = 0.2)
mod_tf %>% fit(epochs = 10, validation_split = 0.2, verbose = T)
fitted_vals_tf <- mod_tf %>% fitted()
fitted_vals_torch <- mod_torch %>% fitted()
cor(data.frame(fitted_vals_tf, fitted_vals_torch, y))
orthog_options = orthog_control(orthogonalize = F)
# load and prepare data
airbnb <- readRDS("/Users/marquach/Desktop/R_Projects/semi-structured_distributional_regression/application/airbnb/munich_clean.RDS")
airbnb$days_since_last_review <- as.numeric(
difftime(airbnb$date, airbnb$last_review)
)
y = log(airbnb$price)
deep_model_tf <- function(x){
x %>%
layer_dense(units = 5, activation = "relu", use_bias = FALSE) %>%
layer_dropout(rate = 0.2) %>%
layer_dense(units = 3, activation = "relu") %>%
layer_dropout(rate = 0.2) %>%
layer_dense(units = 1, activation = "linear")
}
deep_model_torch <- function() nn_sequential(
nn_linear(in_features = 2, out_features = 5, bias = F),
nn_relu(),
nn_dropout(p = 0.2),
nn_linear(in_features = 5, out_features = 3, bias = T),
nn_relu(),
nn_dropout(p = 0.2),
nn_linear(in_features = 3, out_features = 1))
mod_tf <- deepregression(y = y, data = airbnb,
list_of_formulas =
list(
location = ~ 1 + beds +
s(accommodates, bs = "ps") +
s(days_since_last_review, bs = "tp") +
deep(review_scores_rating, reviews_per_month),
scale = ~1),
orthog_options = orthog_options,
list_of_deep_models = list(deep = deep_model_tf),
engine = "tf"
)
mod_torch <- deepregression(y = y, data = airbnb,
list_of_formulas =
list(
location = ~ 1 + beds +
s(accommodates, bs = "ps") +
s(days_since_last_review, bs = "tp") +
deep(review_scores_rating, reviews_per_month),
scale = ~1), orthog_options = orthog_options,
list_of_deep_models = list(deep = deep_model_torch),
engine = "torch"
)
mod_tf %>% fit(epochs = 100, validation_split = 0.2, verbose = T)
mod_torch %>% fit(epochs = 100, validation_split = 0.2)
fitted_vals_tf <- mod_tf %>% fitted()
fitted_vals_torch <- mod_torch %>% fitted()
cor(data.frame(fitted_vals_tf, fitted_vals_torch, y))
plot(fitted_vals_tf, fitted_vals_torch)
abline(a = 0,b = 1)
coef(mod_tf)
coef(mod_torch)
cbind(unlist(coef(mod_tf, type="linear")),
unlist(coef(mod_torch, type="linear")))
coef(mod_tf, type="smooth")
coef(mod_torch, type="smooth")
cbind(coef(mod_tf, type="smooth")[[1]],
coef(mod_torch, type="smooth")[[1]])
cbind(coef(mod_tf, type="smooth")[[2]],
coef(mod_torch, type="smooth")[[2]])
coef(mod_tf, which_param = 1)
coef(mod_torch, which_param = 1)
coef(mod_tf, which_param = 2)
coef(mod_torch, which_param = 2)
plot(mod_tf, which = 2)
mod_torch_data <- plot(mod_torch, which = 2, only_data = T)
points(mod_torch_data[[1]]$value, mod_torch_data[[1]]$partial_effect,
col = "green")
# Cross validation
res_cv_tf <- mod_tf %>% cv(plot = F, cv_folds = 3, epochs = 10)
res_cv_torch <- mod_torch %>% cv(plot = F, cv_folds = 3, epochs = 10)
res_cv_torch
plot(res_cv_torch)
plot_cv(res_cv_tf, engine = "tf")
plot_cv(res_cv_torch, engine = "torch")
plot_cv(res_cv_torch, engine = "torch")
res
str(res)
str(res1)
str(res,1)
res[[1]]
res[[1]]$records
res[[1]]$ctx
res[[1]]$model
plot_cv(res_cv_tf, engine = "tf")
res
lapply(res, "[[", "weighthistory")
weightshist
# Cross validation
res_cv_tf <- mod_tf %>% cv(plot = F, cv_folds = 3, epochs = 10, save_weights = T)
plot_cv(res_cv_tf, engine = "tf")
weightshist
plot_cv(res_cv_tf, engine = "tf")
debugonce(plot_cv)
plot_cv(res_cv_tf, engine = "tf")
debugonce(cv)
# Cross validation
res_cv_tf <- mod_tf %>% cv(plot = F, cv_folds = 3, epochs = 10, save_weights = T)
save_weights
WeightHistory$new()
WeightHistory
args
input_list_model[!names(input_list_model) %in%
names(args)]
args
str(args,1)
str(args$callbacks,1)
ret
weighthistory
weighthistory$weights_last_layer
args$epochs
weighthistory
weighthistory$weights_last_layer
x
x$model$weights
weighthistory$weights_last_layer
x$model$weights
weighthistory$weights_last_layer
x$model$weights
weighthistory$weights_last_layer
ret
ret
weighthistory
ret$weighthistory
str(ret)
str(ret,1)
attributes(ret)
debugonce(cv)
res_cv_torch <- mod_torch %>% cv(plot = F, cv_folds = 3, epochs = 10)
ret
str(ret,1)
str(ret$ctx,1)
str(ret$records,1)
str(ret$records$profile,1)
str(ret$records$profile$fit,1)
str(ret$records$profile$train,1)
str(ret$ctx,1)
ret %>% get_weights_torch()
ret$model() %>% get_weights_torch()
ret$model %>% get_weights_torch()
x
ret$model
ret$model$distr_parameters
ret$model$parameters
length(ret$model$parameters)
get_weights_torch
get_weights_torch(ret)
debugonce(get_weights_torch)
get_weights_torch(ret)
model
str(model,1)
model$model$amount_distr_parameters
model$model$state_dict
model$model$state_dict()
model$model$state_dict()
model$model$metrics