Skip to content

Instantly share code, notes, and snippets.

@cocomoff
Created May 7, 2020 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocomoff/4f5ed03e5adb380ab2bdc1fec9546770 to your computer and use it in GitHub Desktop.
Save cocomoff/4f5ed03e5adb380ab2bdc1fec9546770 to your computer and use it in GitHub Desktop.
softmin, softmax, softcramp in Julia
using Plots
gr()
function softmax(x, y)
maxxy = max.(x, y)
minxy = min.(x, y)
maxxy .+ log.(1.0 .+ exp.(minxy .- maxxy))
end
softmin(x, y) = -log.(exp.(-x) .+ exp.(-y))
softcramp(x, min, max) = softmax(softmin(x, max), min) # . がいるかも
x_seq = -10:0.1:10
y1 = -3
y2 = 5
z1 = softmax(x_seq, y1);
z11 = max.(x_seq, y1);
z2 = softmin(x_seq, y2);
z22 = min.(x_seq, y2);
z3 = softcramp(x_seq, y1, y2);
pp = plot(size=(300, 300))
plot!(pp, x_seq, z1, lw=2, color=:blue, label="softmax")
plot!(pp, x_seq, z11, lw=0.5, color=:blue, label="")
plot!(pp, x_seq, z2, lw=2, color=:red, label="softmin")
plot!(pp, x_seq, z22, lw=0.5, color=:red, label="")
plot!(pp, x_seq, z3, lw=2, color=:purple, label="softcramp")
pp
@cocomoff
Copy link
Author

cocomoff commented May 7, 2020

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment