@@ -220,7 +220,7 @@ of a n-dimensional array.
220
220
different dimensions. If `weights=nothing` all dimensions are weighted equally.
221
221
- `step=1`: A integer indicating the step width for the array indexing
222
222
- `mode="forward"`: Either `"central"` or `"forward"` accounting for different
223
- modes of the spatial gradient. Default is "central ".
223
+ modes of the spatial gradient. Default is "forward ".
224
224
- `ϵ=1f-8` is a smoothness variable, to make it differentiable
225
225
226
226
# Examples
@@ -234,22 +234,28 @@ julia> reg([1 2 3; 4 5 6; 7 8 9])
234
234
```
235
235
"""
236
236
function GR (; num_dims= 2 , sum_dims= 1 : num_dims, weights= [1 , 1 ], step= 1 ,
237
- mode= " central " , ϵ= 1f-8 )
237
+ mode= " forward " , ϵ= 1f-8 )
238
238
if weights == nothing
239
239
weights = ones (Int, num_dims)
240
240
end
241
241
if mode == " central"
242
- GRf = @eval arr -> ($ (generate_GR (num_dims, sum_dims, weights,
243
- step, (- 1 ) * step)... ))
242
+ GRf = @eval arr2 -> begin
243
+ arr = sqrt .(arr2 .+ $ ϵ)
244
+ $ (generate_GR (num_dims, sum_dims, weights,
245
+ step, (- 1 ) * step)... )
246
+ end
244
247
elseif mode == " forward"
245
- GRf = @eval arr -> ($ (generate_GR (num_dims, sum_dims, weights,
248
+ GRf = @eval arr2 -> begin
249
+ arr = sqrt .(arr2 .+ $ ϵ)
250
+ ($ (generate_GR (num_dims, sum_dims, weights,
246
251
step, 0 )... ))
252
+ end
247
253
else
248
254
throw (ArgumentError (" The provided mode is not valid." ))
249
255
end
250
256
251
257
# we need to add a ϵ to prevent NaN in the derivative of it
252
- return arr -> GRf ( sqrt .(arr .+ ϵ))
258
+ return GRf # arr -> begin
253
259
end
254
260
255
261
@@ -292,8 +298,8 @@ of a n-dimensional array.
292
298
- `weights=nothing`: A array containing weights to weight the contribution of
293
299
different dimensions. If `weights=nothing` all dimensions are weighted equally.
294
300
- `step=1`: A integer indicating the step width for the array indexing
295
- - `mode="central "`: Either `"central"` or `"forward"` accounting for different
296
- modes of the spatial gradient. Default is "central ".
301
+ - `mode="forward "`: Either `"central"` or `"forward"` accounting for different
302
+ modes of the spatial gradient. Default is "forward ".
297
303
- `ϵ=1f-8` is a smoothness variable, to make it differentiable
298
304
299
305
# Examples
@@ -306,7 +312,7 @@ julia> reg([1 2 3; 4 5 6; 7 8 9])
306
312
12.649111f0
307
313
```
308
314
"""
309
- function TV (; num_dims= 2 , sum_dims= 1 : num_dims, weights= nothing , step= 1 , mode= " central " , ϵ= 1f-8 )
315
+ function TV (; num_dims= 2 , sum_dims= 1 : num_dims, weights= nothing , step= 1 , mode= " forward " , ϵ= 1f-8 )
310
316
311
317
if weights == nothing
312
318
weights = ones (Int, num_dims)
0 commit comments