use parameterize instead of setting parameters

This commit is contained in:
Robby Findler 2014-03-21 16:25:41 -05:00
parent d05834afb7
commit bd3aaa0ff7

View File

@ -9,7 +9,6 @@
(provide (all-defined-out)) (provide (all-defined-out))
(define types (make-parameter '())) (define types (make-parameter '()))
(define all-types '(grammar search search-gen search-gen-enum search-gen-ref search-gen-enum-ref enum ordered)) (define all-types '(grammar search search-gen search-gen-enum search-gen-ref search-gen-enum-ref enum ordered))
(define names '("grammar" "search" "backjumping" "backjumping, ordered space" "backjumping, with refresh" (define names '("grammar" "search" "backjumping" "backjumping, ordered space" "backjumping, with refresh"
@ -67,193 +66,187 @@
30 2.042)) 30 2.042))
(define (make-plot filenames) (define (make-plot filenames)
(parameterize ([plot-x-tick-label-angle 75]
(define data [plot-x-tick-label-anchor 'right]
(let ([raw-data [plot-font-size 20]
(apply append [error-bar-line-width 3]
(for/list ([f filenames]) [error-bar-width 12]
(call-with-input-file f [plot-line-width 3]
(λ (in) [plot-y-transform (axis-transform-bound log-transform 0.00001 +inf.0)])
(read in)))))])
(let loop ([fixed-data '()] (define data
[rest raw-data]) (let ([raw-data
(cond (apply append
[(null? rest) fixed-data] (for/list ([f filenames])
[((length rest) . >= . 3) (call-with-input-file f
(loop (cons (take rest 3) fixed-data) (λ (in)
(drop rest 3))] (read in)))))])
[else (let loop ([fixed-data '()]
(error 'data "is the wrong length!")])))) [rest raw-data])
(cond
[(null? rest) fixed-data]
[((length rest) . >= . 3)
(define (error-bar times) (loop (cons (take rest 3) fixed-data)
(define sdev (stddev times #:bias #t)) (drop rest 3))]
(define this-z (if (> (length times) 30) [else
z (error 'data "is the wrong length!")]))))
(hash-ref t-inv-cdf-97.5 (sub1 (length times)))))
(if (confidence-interval) (define (error-bar times)
(/ (* z sdev) (sqrt (length times))) (define sdev (stddev times #:bias #t))
(/ (stddev times #:bias #t) (sqrt (length times))))) (define this-z (if (> (length times) 30)
z
(define name-avgs (make-hash)) (hash-ref t-inv-cdf-97.5 (sub1 (length times)))))
(if (confidence-interval)
(define data-stats (/ (* z sdev) (sqrt (length times)))
(let loop ([d data] (/ (stddev times #:bias #t) (sqrt (length times)))))
[sorted-times (hash)])
(match d (define name-avgs (make-hash))
[(cons (list name type time) rest)
(loop rest (define data-stats
(hash-set sorted-times (cons name type) (let loop ([d data]
(cons (/ time 1000) [sorted-times (hash)])
(hash-ref sorted-times (cons name type) (match d
(λ () '())))))] [(cons (list name type time) rest)
['() (loop rest
(for/list ([(name/type times) (in-hash sorted-times)] (hash-set sorted-times (cons name type)
#:unless (and ((length times) . < . (min-trials)) (cons (/ time 1000)
(not (equal? (cdr name/type) 'ordered)))) (hash-ref sorted-times (cons name type)
(define name (last (regexp-split #rx"/" (car name/type)))) (λ () '())))))]
(cond ['()
[(equal? (cdr name/type) (order-by)) (for/list ([(name/type times) (in-hash sorted-times)]
(hash-set! name-avgs name (mean times))] #:unless (and ((length times) . < . (min-trials))
[(list? (hash-ref name-avgs name '())) (not (equal? (cdr name/type) 'ordered))))
(hash-set! name-avgs (define name (last (regexp-split #rx"/" (car name/type))))
name (cond
(cons (mean times) (hash-ref name-avgs name '())))]) [(equal? (cdr name/type) (order-by))
(list (car name/type) (hash-set! name-avgs name (mean times))]
(cdr name/type) [(list? (hash-ref name-avgs name '()))
(mean times) (hash-set! name-avgs
(if (equal? (cdr name/type) 'ordered) name
0 (cons (mean times) (hash-ref name-avgs name '())))])
(error-bar times))))]))) (list (car name/type)
(cdr name/type)
(mean times)
(plot-x-tick-label-angle 75) (if (equal? (cdr name/type) 'ordered)
(plot-x-tick-label-anchor 'right) 0
(plot-font-size 20) (error-bar times))))])))
(error-bar-line-width 3)
(error-bar-width 12) (define (name-order name)
(plot-line-width 3) (length
(or
(plot-y-transform (axis-transform-bound log-transform 0.00001 +inf.0)) (memf
(λ (n) (equal? n name))
(define (name-order name) (sort (hash-keys name-avgs)
(length >
(or #:key (λ (k)
(memf (define val (hash-ref name-avgs k))
(λ (n) (equal? n name)) (if (number? val)
(sort (hash-keys name-avgs) val
> (mean val)))))
#:key (λ (k) '())))
(define val (hash-ref name-avgs k))
(if (number? val) (define (get-name-num name n)
val (+ (if (offset?)
(mean val))))) (+ (/ n 12)
'()))) (- (/ (sub1 (length (types))) 12)))
0)
(define (get-name-num name n) (name-order name)))
(+ (if (offset?)
(+ (/ n 12) (define (plot-type type n)
(- (/ (sub1 (length (types))) 12))) (define this-type
0) (map (λ (d)
(name-order name))) (define name (last (regexp-split #rx"/" (car d))))
(cons name (cdr d)))
(define (plot-type type n) (filter
(define this-type (λ (l)
(map (λ (d) (and (equal? type (list-ref l 1))
(define name (last (regexp-split #rx"/" (car d)))) (list-ref l 2)))
(cons name (cdr d))) data-stats)))
(filter (list
(λ (l) (points
(and (equal? type (list-ref l 1)) (map
(list-ref l 2))) (λ (l)
data-stats))) (list (get-name-num (list-ref l 0) n) (list-ref l 2)))
(list this-type)
(points #:label (string-append (hash-ref type-names type)
(map (format " (~s successes)" (length this-type)))
(λ (l) #:sym (hash-ref type-symbols type)
(list (get-name-num (list-ref l 0) n) (list-ref l 2))) #:size 20
this-type) #:line-width 2
#:label (string-append (hash-ref type-names type) #:color (add1 n))
(format " (~s successes)" (length this-type))) (error-bars
#:sym (hash-ref type-symbols type) (map (λ (d)
#:size 20 (list (get-name-num (list-ref d 0) n)
#:line-width 2 (list-ref d 2)
#:color (add1 n)) (list-ref d 3)))
(error-bars this-type)
(map (λ (d) #:y-min 0.01
(list (get-name-num (list-ref d 0) n) #:line-width 1
(list-ref d 2) #:color (length (member type all-types)))))
(list-ref d 3)))
this-type) (define (zero->neg n)
#:y-min 0.01 (if (zero? n)
#:line-width 1 (- 500)
#:color (length (member type all-types))))) n))
(define (zero->neg n) (define (tlabel pre-tick)
(if (zero? n) (define v (pre-tick-value pre-tick))
(- 500) (define label-list
n)) (filter
(λ (n) (= (name-order n) v))
(define (tlabel pre-tick) (hash-keys name-avgs)))
(define v (pre-tick-value pre-tick)) (if (empty? label-list)
(define label-list ""
(filter (car label-list)))
(λ (n) (= (name-order n) v))
(hash-keys name-avgs))) (plot-x-ticks (ticks (linear-ticks-layout #:number 30 #:base 10
(if (empty? label-list) #:divisors '(1))
"" (λ (_1 _2 pts) (map tlabel pts))))
(car label-list)))
(define (loggy-ticks _1 _2)
(plot-x-ticks (ticks (linear-ticks-layout #:number 30 #:base 10 (for*/list
#:divisors '(1)) ([f (in-list '(1 10 100 1000 10000))]
(λ (_1 _2 pts) (map tlabel pts)))) [n (in-range 1 10)])
(pre-tick (* f n) (or
(define (loggy-ticks _1 _2) (= n 5)
(for*/list (= n 1)))))
([f (in-list '(1 10 100 1000 10000))]
[n (in-range 1 10)]) (plot-y-ticks
(pre-tick (* f n) (or (log-ticks #:number 20 #:base 10))
(= n 5)
(= n 1))))) (if (output-file)
(plot
(plot-y-ticks (for/list ([t (if (empty? (types)) all-types (types))]
(log-ticks #:number 20 #:base 10)) [n (in-naturals)])
(plot-type t n))
(if (output-file) #:y-label "avg. seconds to find bug"
(plot #:x-label "file"
(for/list ([t (if (empty? (types)) all-types (types))] #:x-min 0
[n (in-naturals)]) #:y-min (min-y)
(plot-type t n)) #:y-max (if (max-t)
#:y-label "avg. seconds to find bug" (* 60 (max-t))
#:x-label "file" (+ 5 (/ (apply max (filter values (map (λ (d) (list-ref d 2)) data))) 1000)))
#:x-min 0 #:x-max (+ 0.5 (length (hash-keys name-avgs)))
#:y-min (min-y) #:legend-anchor 'top-left
#:y-max (if (max-t) #:width 1024
(* 60 (max-t)) #:height 768
(+ 5 (/ (apply max (filter values (map (λ (d) (list-ref d 2)) data))) 1000))) #:out-file (output-file)
#:x-max (+ 0.5 (length (hash-keys name-avgs))) #:out-kind 'jpeg)
#:legend-anchor 'top-left (plot-pict
#:width 1024 (for/list ([t (if (empty? (types)) all-types (types))]
#:height 768 [n (in-naturals)])
#:out-file (output-file) (plot-type t n))
#:out-kind 'jpeg) #:y-label "avg. seconds to find bug"
(plot-pict #:x-label "file"
(for/list ([t (if (empty? (types)) all-types (types))] #:x-min 0
[n (in-naturals)]) #:y-min (min-y)
(plot-type t n)) #:y-max (if (max-t)
#:y-label "avg. seconds to find bug" (* 60 (max-t))
#:x-label "file" (+ 5 (/ (apply max (filter values (map (λ (d) (list-ref d 2)) data))) 1000)))
#:x-min 0 #:x-max (+ 0.5 (length (hash-keys name-avgs)))
#:y-min (min-y) #:legend-anchor 'top-left
#:y-max (if (max-t) #:width 1024
(* 60 (max-t)) #:height 768))))
(+ 5 (/ (apply max (filter values (map (λ (d) (list-ref d 2)) data))) 1000)))
#:x-max (+ 0.5 (length (hash-keys name-avgs)))
#:legend-anchor 'top-left
#:width 1024
#:height 768))
)
(module+ (module+