Created
May 22, 2017 22:55
-
-
Save longouyang/fa24cdde42bf1945660419df23954f76 to your computer and use it in GitHub Desktop.
gradient ascent in webppl
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
var f = function(theta) { | |
//return 30 * Math.log(theta) + 20 * Math.log(1-theta) | |
return Binomial({p: theta, n: 30}).score(14) | |
} | |
globalStore["x"] = 0.001; | |
repeat(100, | |
function() { | |
var x = globalStore["x"], | |
xL = ad.lift(x); | |
var yL = f(xL); | |
yL.backprop(); | |
var dxL = ad.derivative(xL); | |
console.log(x, ad.value(yL), dxL); | |
var newX = (dxL > 0 ? x + 0.01 : x - 0.01); | |
globalStore["x"] = newX; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment