On 6/15/21, Britt Anderson <britt.uwater...@gmail.com> wrote:
>
> I was starting to explore plot and I am getting a behavior I do not
> understand. plot doesn't seem to be able to figure out the bounds for
> something that seems pretty straight-forward. When I give bounds as an
> optional argument I don't see the line I expect to see. Can anyone provide
> me some pointers? I feel like I am just missing something conceptually and
> would appreciate some guidance. Here is some minimal code to demonstrate
> the problem.  I get a plot square, but no line, and I can demonstrate that
> the function generates reasonable numbers for this range of inputs.
>
>
>
>     #lang racket
>     (require plot)
>     (require math/distributions)
>
>     (define (norm-prior mu)
>       (lambda (sd)
>       (lambda (ind)
>         (* ind (flnormal-pdf mu sd ind #f)))))
>
>     (define d ((norm-prior 0.5) 0.1))
>
>     (plot (function d 0 1 #:y-min 0.0 #:y-max 2.0 #:samples 100))
>
>     (map d (range 0.0 1.0 0.01))
>

This is tricky.

Plot is calling your function `d` with inputs like 0, 1/99, and 1. All
of those give contract errors --- try (d 0) for yourself.

But when a plot function throws an error, the library ignores the
problem & keeps trying to draw a picture.

To fix, I'd change `norm-prior` to make a flonum:

     (define (norm-prior mu)
       (lambda (sd)
       (lambda (ind)
         (* ind (flnormal-pdf mu sd (exact->inexact ind) #f)))))

[[ Maybe plot should check if a function renderer produces no output
and throw an error then. ]]

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAFUu9R649zKbfduwRk57gdCnYbAZ29amvSX1%3D%3D__Zx7hbbop9Q%40mail.gmail.com.

Reply via email to