Skip to content

Instantly share code, notes, and snippets.

@gleenn
Created September 27, 2017 07:21
Show Gist options
  • Save gleenn/872bd9ef1fd766cd3f07afa2e361cd27 to your computer and use it in GitHub Desktop.
Save gleenn/872bd9ef1fd766cd3f07afa2e361cd27 to your computer and use it in GitHub Desktop.
In Progress finding the value for sigmoid'(x) = 1
; This doesn't work yet ;)
(defn sigmoid [x] (/ 1 (- 1 (Math/exp (- x)))))
(defn sigmoid' [x] (let [sigmoidx (sigmoid x)] (* sigmoidx (- 1 sigmoidx))))
(defn bs [f ^double val ^double delta]
(loop [bottom -100.0 top 100.0 countdown 1000]
(let [middle ^double (+ bottom (/ (- top bottom) 2))
f-mid ^double (f middle)]
(if (= 0 countdown)
(prn "aborting - f-mid was " f-mid)
(do
(prn bottom middle f-mid top)
(cond (<= (Math/abs (- f-mid val)) delta) middle
(< val f-mid) (recur bottom middle (dec countdown))
:else (recur middle top (dec countdown))))))))
(bs sigmoid 1.0 0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment