File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change 1
1
name = " ApplicationDrivenLearning"
2
2
uuid = " 0856f1c8-ef17-4e14-9230-2773e47a789e"
3
3
authors = [" Giovanni Amorim" , " Joaquim Garcia" ]
4
- version = " 0.1.1 "
4
+ version = " 0.1.2 "
5
5
6
6
[deps ]
7
7
BilevelJuMP = " 485130c0-026e-11ea-0f1a-6992cd14145c"
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ function compute_cost(
83
83
X:: Matrix{<:Real} ,
84
84
Y:: Matrix{<:Real} ,
85
85
with_gradients:: Bool = false ,
86
+ aggregate:: Bool = true ,
86
87
)
87
88
88
89
# data size assertions
@@ -93,9 +94,9 @@ function compute_cost(
93
94
build (model)
94
95
95
96
# init parameters
96
- C = 0
97
97
T = size (Y)[1 ]
98
- dC = zeros (model. forecast. output_size)
98
+ C = zeros (T)
99
+ dC = zeros ((T, model. forecast. output_size))
99
100
dCdz = Vector {Float32} (undef, size (model. policy_vars, 1 ))
100
101
dCdy = Vector {Float32} (undef, model. forecast. output_size)
101
102
@@ -114,8 +115,14 @@ function compute_cost(
114
115
# main loop to compute cost
115
116
for t = 1 : T
116
117
result = _compute_step (Y[t, :], Yhat[t, :])
117
- C += result[1 ] ./ T
118
- dC .+ = result[2 ] ./ T
118
+ C[t] += result[1 ]
119
+ dC[t, :] .+ = result[2 ]
120
+ end
121
+
122
+ # aggregate cost if requested
123
+ if aggregate
124
+ C = sum (C) / T
125
+ dC = sum (dC, dims = 1 )[1 , :] / T
119
126
end
120
127
121
128
if with_gradients
You can’t perform that action at this time.
0 commit comments