1
- using Distributed
2
-
3
1
function compute_single_step_cost (
4
2
model:: Model ,
5
3
y:: Vector{<:Real} ,
@@ -48,7 +46,7 @@ function compute_single_step_gradient(
48
46
end
49
47
50
48
"""
51
- compute_cost(model, X, Y, with_gradients=false, n_workers=1 )
49
+ compute_cost(model, X, Y, with_gradients=false)
52
50
53
51
Compute the cost function (C) based on the model predictions and the true values.
54
52
@@ -67,7 +65,6 @@ function compute_cost(
67
65
X:: Matrix{<:Real} ,
68
66
Y:: Matrix{<:Real} ,
69
67
with_gradients:: Bool = false ,
70
- n_workers:: Int = 1 ,
71
68
)
72
69
73
70
# data size assertions
@@ -96,32 +93,11 @@ function compute_cost(
96
93
# get predictions
97
94
Yhat = model. forecast (X' )' # size=(T, output_size)
98
95
99
- # main loop - sequential
100
- if n_workers == 1
101
- for t = 1 : T
102
- result = _compute_step (Y[t, :], Yhat[t, :])
103
- C += result[1 ] ./ T
104
- dC .+ = result[2 ] ./ T
105
- end
106
-
107
- # main loop - parallel
108
- elseif n_workers > 1
109
-
110
- # add workers and import package on first call
111
- if nprocs () < n_workers
112
- error (
113
- " Please add workers and import the AppDrivenLearning module @everywhere before calling `train!` function." ,
114
- )
115
- end
116
-
117
- # parallel computation
118
- result =
119
- pmap (_compute_step, [Y[t, :] for t = 1 : T], [Yhat[t, :] for t = 1 : T])
120
- C = sum ([r[1 ] for r in result])
121
- dC = sum ([r[2 ] for r in result])
122
-
123
- else
124
- error (" Invalid number of workers" )
96
+ # main loop to compute cost
97
+ for t = 1 : T
98
+ result = _compute_step (Y[t, :], Yhat[t, :])
99
+ C += result[1 ] ./ T
100
+ dC .+ = result[2 ] ./ T
125
101
end
126
102
127
103
if with_gradients
0 commit comments