Skip to content

Instantly share code, notes, and snippets.

@gfredericks
Created June 19, 2011 03:29
Show Gist options
  • Save gfredericks/1033727 to your computer and use it in GitHub Desktop.
Save gfredericks/1033727 to your computer and use it in GitHub Desktop.
(defn probability-of-taking-this-transition
[tid incoming-variations transitions payment-rule]
(let [this-trans
(first
(filter #(= tid (:id %)) transitions)),
this-variations (this-trans :variations),
this-feasibility (this-trans payment-rule),
change-points
(distinct
(for [feas (map payment-rule transitions),
:when #(or (nil? this-feasibility) (<= feas this-feasibility))]
(or feas :infinity)))]
(prn "CHANGE POINTS" change-points)
(zipmap
change-points
(for [change-point change-points]
(let [feasibles
(filter
(fn [tran]
(let [its-feasibility (tran payment-rule)]
(if (= :infinity change-point)
(nil? its-feasibility)
(or
(nil? its-feasibility)
(>= its-feasibility change-point)))))
transitions)]
(prn "FEASIBLES" change-point feasibles)
(if (some #{tid} (map :id feasibles))
; This line is the crux of the bug I think
; maybe we should multiply by the incoming variations??
; (/ this-variations (apply + (map :variations feasibles))))))))
; (/ 1 (apply + (map :variations feasibles))))))))
(/ incoming-variations (apply + (map :variations feasibles)))
0))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment