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