fork download
  1. type Node =
  2. val DF : double
  3. val Branch : (int * double) []
  4.  
  5. new (df, branch) = {
  6. DF = df
  7. Branch = branch
  8. }
  9.  
  10. let induceBackward (nodes : Node []) (values : double []) : double [] =
  11. let n = values.Length / 2
  12. let folder acc (k, p) = acc + p * values.[n + k]
  13. let mapping (node : Node) = node.DF * Array.fold folder 0.0 node.Branch
  14. Array.map mapping nodes
  15.  
  16. let ITERATION = 1000
  17.  
  18. let lastValues i = Array.create 201 (double i)
  19. let testTree =
  20. [| for i in 0..99 ->
  21. [| for j in -i..i ->
  22. Node(1.0, [|(j-1, 1.0/6.0); (j, 2.0/3.0); (j+1, 1.0/6.0)|]) |] |]
  23. let value i = (Array.foldBack induceBackward testTree (lastValues i)).[0]
  24. stdout.WriteLine (Array.max (Array.init ITERATION value))
Success #stdin #stdout 1.3s 14296KB
stdin
Standard input is empty
stdout
999