#lang scheme/base
(provide
(all-defined-out))
(require (lib "plot.ss" "plot"))
(require (planet "plot-histogram.ss"
("williams" "science.plt")))
(require (planet "discrete-histogram-with-graphics.ss"
("williams" "science.plt")))
(require (planet "histogram-with-graphics.ss"
("williams" "science.plt")))
(require (planet "statistics.ss" ("williams" "science.plt")))
(require "simulation.ss")
(require scheme/mpair)
(define history-plot
(case-lambda
((history title)
(if (history-time-dependant? history)
(let* ((durations (history-durations history))
(values (history-values history))
(x-vector (make-vector (+ (mlength durations) 1)))
(y-vector (list->vector (mlist->list values))))
(let ((x (history-initial-time history)))
(vector-set! x-vector 0 x)
(do ((i 0 (+ i 1)))
((null? durations) (void))
(set! x (+ x (mcar durations)))
(vector-set! x-vector (+ i 1) x)
(set! durations (mcdr durations))))
(plot (histogram (list y-vector x-vector))
(x-min (vector-ref x-vector 0))
(x-max (vector-ref x-vector (- (vector-length x-vector) 1)))
(x-label "Time")
(y-min (minimum y-vector))
(y-max (maximum y-vector))
(y-label "Value")
(title title)))
(let ((discrete? #t)
(v (list->vector (mlist->list (history-values history)))))
(do ((i 0 (+ i 1)))
((= i (vector-length v)) (void))
(let/ec exit
(when (not (integer? (vector-ref v i)))
(set! discrete? #f)
(exit))))
(if discrete?
(let ((h (make-discrete-histogram)))
(do ((i 0 (+ i 1)))
((= i (vector-length v)) (void))
(discrete-histogram-increment! h (vector-ref v i)))
(discrete-histogram-plot h title))
(let ((h (make-histogram 40)))
(set-histogram-ranges-uniform! h (minimum v) (maximum v))
(do ((i 0 (+ i 1)))
((= i (vector-length v)) (void))
(histogram-increment! h (vector-ref v i)))
(histogram-plot h title))))))
((history)
(history-plot history "History"))))