Created
May 7, 2020 01:48
-
-
Save cocomoff/4f5ed03e5adb380ab2bdc1fec9546770 to your computer and use it in GitHub Desktop.
softmin, softmax, softcramp in Julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Author
cocomoff
commented
May 7, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment