bind_plans and map transformation - drake-r-package

Is it possible to use a map transformation with a grouping variable that is described in an external plan?
In other words, this works for me:
plan_a = drake_plan(
foo = target(x + 1, transform = map(x = c(4, 5, 6))),
bar = target(y + 5, transform = map(foo))
)
but this doesn't:
plan_a = drake_plan(
foo = target(x + 1, transform = map(x = c(4, 5, 6))),
)
plan_b = drake_plan(
bar = target(y + 5, transform = map(foo))
)
bind_plans(plan_a, plan_b)
Thanks!

I found a solution using the transform_plan function.

Related

plotly joins points in wrong order

I have the following df (part)
"Date"
"2022-09-01" "2022-09-02" "2022-09-05" "2022-09-06" "2022-09-07" "2022-09-08" ....
"LogClose"
8.285728 8.274933 8.274933 8.270830 8.289004 8.295593 ....
"wielkoscDD"
0.00000000 -0.01073648 -0.01073648 -0.01478755 0.00000000 0.00000000 ....
I use:
p <- plot_ly(
df,
x = ~Date,
y = ~LogClose,
name = 'zamknięcie',
type = 'scatter',
mode = 'lines',
text = ~paste("zamknięcie :", Zamkniecie),
width = obrazek_szer,
height = obrazek_wyso)
but the second draw is correct
p <- plot_ly(
df,
x = ~Date,
y = ~wielkoscDD,
name = 'drawdown',
type = 'scatter',
mode = 'lines',
text = ~paste("drawdown : ", wielkoscDD),
width = obrazek_szer,
height = obrazek_wyso)
Additionaly on my Mac it works ok - on Windows there is chaos with the 1st chart.
rgds
Grzegorz

How to update/reload table key values

How can i update a key value using another key value as variable which is inside the same table?
local t = {}
t.playerPosition = {x = 0, y = 0, z = 0}
t.positions = {t.playerPosition.x + 1, t.playerPosition.y + 1, t.playerPosition.z + 1}
Then few lines later i update playerPosition
t.playerPosition = {x = 125, y = 50, z = 7}
And then if i print out...
result
t.positions[1] -- outputs 1
t.positions[2] -- outputs 1
t.positions[3] -- outputs 1
expected result
t.positions[1] -- outputs 126
t.positions[2] -- outputs 51
t.positions[3] -- outputs 8
As you can see key positions isnt updating, what could i do to make it possible?
t.positions = {t.playerPosition.x + 1, t.playerPosition.y + 1, t.playerPosition.z + 1}
In the above line, the expressions are evaluated once, and the resulting values are assigned to fields of the subtable. After this point, changes to the fields of t.playerPosition will not cause a reflected change in t.positions.
Metatables can be used to enable such behaviour, by dynamically calculating results when accessing the fields of t.positions.
local t = {}
t.playerPosition = { x = 0, y = 0, z = 0 }
t.positions = setmetatable({}, {
__newindex = function () return false end,
__index = function (_, index)
local lookup = { 'x', 'y', 'z' }
local value = t.playerPosition[lookup[index]]
if value then
return value + 1
end
end
})
print(t.positions[1], t.positions[2], t.positions[3])
t.playerPosition = {x = 125, y = 50, z = 7}
print(t.positions[1], t.positions[2], t.positions[3])

How to map transform in r-drake

May i ask how to use function GraphLearner$new to transform in r-drake.
The codes following:
learner_plan = drake_plan(
## 1. Choose learner--------------------------------------------------------
polrn_classif = target(fnc_po_learner(list_learners),
transform = map(
list_learners = c(
"classif.ranger",
"classif.lightgbm",
"classif.xgboost",
"classif.log_reg",
"classif.svm"
)
)),
graph_classif = target(
imputer_classif %>>% filter_classif %>>% polrn_classif,
transform = map(polrn_classif)
),
glrn_classif = target({
GraphLearner$new(graph = graph_classif) # get error ---------- it's not transform
transform = map(graph_classif)
})
)
learner_plan
transform = map(graph_classif) should go outside the curly braces.
library(drake)
learner_plan = drake_plan(
polrn_classif = target(
fnc_po_learner(list_learners),
transform = map(
list_learners = c(
"classif.ranger",
"classif.lightgbm",
"classif.xgboost",
"classif.log_reg",
"classif.svm"
)
)
),
graph_classif = target(
imputer_classif %>>% filter_classif %>>% polrn_classif,
transform = map(polrn_classif)
),
glrn_classif = target({
GraphLearner$new(graph = graph_classif)
}, transform = map(graph_classif)) # outside the curly braces
)
plot(learner_plan)
Created on 2021-07-07 by the reprex package (v2.0.0)

Mixing solidguage and column in a graph with highcharter

I have this two dataframes
1) t1 (Var1(numeric), Var2(string), Freq (numeric))
2) pref.media (pref.media (numeric)
I have this separated graphs, but I want to print like two series in the same graph
1) Column chart, ok
column1 <- highchart() %>%
hc_add_series(t1$Freq, type = "column") %>%
hc_xAxis(categories = t1$Var1) %>%
hc_plotOptions(series = list(showInLegend = FALSE,dataLabels = list(enabled = TRUE, color = t1$Var1)))
2) Solid gauge chart (ok)
gauge1 <- highchart(width = 800, height = 600) %>%
hc_chart(type = "solidgauge",backgroundColor = "#F0F0F0",marginTop = 50) %>%
hc_title(text = "Preferencia",style = list(fontSize = "24px")) %>%
hc_tooltip(borderWidth = 0, backgroundColor = 'none',shadow = FALSE,style = list(fontSize = '16px')) %>%
hc_pane(startAngle = -90,endAngle = 90) %>%
hc_yAxis(min = 0,max = 11,lineWidth = 0,tickPositions = list(0,1,2,3,4,5,6,7,8,9,10,11)) %>%
hc_plotOptions(solidgauge = list(borderWidth = '34px',dataLabels = list(enabled = TRUE, style = list(borderWidth = 3,backgroundColor = 'none',shadow = FALSE, fontSize = '16px',color="#888800")),linecap = 'round',stickyTracking = FALSE)) %>%
hc_add_series(name = "Preferencia",borderColor = "#000000",data = list(list(color = "#888800"),radius = "100%",innerRadius = "100%",y = round(pref.media[[1,1]],2)))
3) Mixing the charts (not ok, with errors)
highchart() %>%
hc_add_series(t1, "column", hcaes(x = Var1, y = Freq), name = "Preferencia") %>%
hc_add_series(pref.media, "solidgauge", hcaes(name = "Gauge", y = round(pref.media[[1,1]],2)), name = "Indicador") %>%
hc_plotOptions(
series = list(showInLegend = FALSE,pointFormat = "{point.y}%"),
column = list(colorByPoint = TRUE),
solidgauge = list(borderWidth = '34px',dataLabels = list(enabled = TRUE),linecap = 'round',stickyTracking = FALSE)) %>%
hc_pane(startAngle = -90,endAngle = 90) %>%
hc_yAxis(title = list(text = "Porcentaje de preferencia"),labels = list(format = "{value}%"), max = 100) %>%
hc_xAxis(categories = t1$Var1) %>%
hc_title(text = "Título") %>%
hc_subtitle(text = "Subtítulo")
I don't understand the sequence for mixing two series. I tried it with a J.Kunst's example in http://jkunst.com/highcharter/highcharts.html
Thanks

Torch: partition tensor

I want to partition my dataset (10,000 50x50 RGB images) into two datasets. Something like:
X = torch.rand(10000, 3, 50, 50)
inds = torch.randperm(X:size(1))[{ { 1, nTrain } }]:long()
X_selected = X:index(1, inds)
X_remaining = X:delete(1, inds)
No matter what I google search, I just get Torch's GitHub documentation. How can I do this?
You can try this way
X = torch.rand(10000, 3, 50, 50)
inds = torch.randperm(X:size(1)):long()
train_inds = inds:narrow(1, 1, nTrain)
valid_inds = inds:narrow(1, nTrain + 1, X:size(1) - nTrain)
X_train = X:index(1, train_inds)
X_valid = X:index(1, valid_inds)

Resources