Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adaptive activation functions #497

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/networks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
struct AdaptiveActivation{T}
a::T
n::T
end

Flux.@functor AdaptiveActivation

(fn::AdaptiveActivation)(x) = (fn.n * fn.a) .* x # to be worked on (for weight tying)


struct NonlinearActivation{T}
σ::T
end

Flux.@functor NonlinearActivation

(a::NonlinearActivation)(x) = (a.σ).(x)


function AdaptiveActivationFeedForwardNetwork(N::Integer, in::Integer, out::Integer, σ = Identity, n::Integer; nn_param_init = glorot_uniform)
# another parameter would be the type of adaptive fn to be used
# N = no. of hidden layers

a = 1/n # initial a scaled such that n*a=1 ?
function slope_recovery_loss_func(phi, θ, p)
# calculate the slope_recovery loss function here as a function of the θ parameters that are generated for this
# network
for i in 1:1:length(θ):
# the loss
"""
if adaptive_fn_without_slope_recovery
0
elseif with_slope_recovery_layerwise
...
elseif neuronwise
...
else
error
"""

return regularizer_loss
end

layer = Flux.Chain(
Dense(in, out, σ=identity; bias=true, init=nn_param_init),
AdaptiveActivation(n, a),
NonlinearActivation(nonlinearity),
) # to be stacked for as many hidden layers specified (N)
Comment on lines +44 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually needed, or is the AdaptiveActivation enough? I think those 8 lines are all that's really needed right? And that could just be added to Flux's activation function list?


return (network=Flux.Chain(...), loss_func=slope_recovery_loss_func)
end