|
From: Daniel J S. <dan...@ie...> - 2006-06-06 21:58:26
|
James R. Van Zandt wrote:
> Daniel J Sebald <dan...@ie...> wrote:
>
>> why shouldn't a plotting program be able to leave out the line
>> connecting the left and right limits of a discontinuity?
>
>
> We could implement an optional threshold on the maximum slope of the
> line. For example:
>
> set maxstepy {<fraction>}
>
> If the difference between successive y values exceeds <fraction> of
> the graph height, then that line segment is omitted. <fraction> is
> a number between 0 and 1. For "set maxstepy" with no number,
> <fraction> defaults to 1/3.
>
> set maxstepx {<fraction>}
>
> If the difference between successive x values exceeds <fraction> of
> the graph width, then that line segment is omitted. <fraction> is a
> number between 0 and 1. For "set maxstepx" with no number,
> <fraction> defaults to 1/3.
>
> unset maxstepy
> unset maxstepx
>
> Return to the default condition, in which all line segments are
> drawn, regardless of the change in y (resp. x) values.
It's an idea that makes sense, but I wonder if it wouldn't cause unexpected problems. It's difficult to pick a value of 1/3 for the slope because taking into consideration the scale of x compared to y a slope of 1/3 could be just fine; as could 3e5 depending upon circumstances.
Checking for successive samples where the slope changes drastically probably isn't a solution either because if one plots noise from the random number generator, that will have sets of three points where the slope changes drastically from one pair of points to the next.
I think the only way to deal with a discontinuity in a general way is for a point in the data set to be 1/0. That would require picking data points right on the discontinuity to ensure it is treated correctly. But then that requires some form of non-uniform sampling, and so on. Hans pointed out some problems with defining discontinuities.
...
I've put together a patch on SourceForge cleaning up the probability density and distribution demos. The functions are properly defined for all of the real line or set of integers. Parameters are range checked.
This should give a variety of examples of discontinuities and how to deal with them:
o Choosing sampling so that the discontinuity is part of the plotted points.
o Plotting two different ranges, one on each side of the discontinuity, very near the discontinuity if not on the discontinuity.
o Casting float values to integers when appropriate.
o Using the histeps (steps, fsteps) style when appropriate.
For example, below are plots for just one of the many CDFs. In this case a discrete random variable. (Technically, the discrete r.v. should be either a probability mass function or delta functions, but I figured I'd leave the histograms as is for prob2.dem.) In the first plot (before patch) the idea is to use a high enough sampling to make the discrete steps look marginally good. But gnuplot has a histeps feature, so rather than do that, histeps are used in the second plot and all the points of the sample range are cast to an int because now the pdf for a binomial random variable requires the input value be an int. All those points in between the integers are simply extraneous.
Of course, it would be nice to not have those points in between, but it isn't possible to have multiple plotting ranges and samplings. I personally think that would be a nice gnuplot feature, e.g.,
plot [0:1-eps] funcwithdiscontinuity(x) lt 1, [1:5] funcwithdiscontinuity(x) lt 1
plot [-2:1:12] binom(x,1,0.5), [-2:12] normal(x,0,1)
so that one can plot multiple portions of functions, or individual functions. As for the syntax, I don't know how one would specify what the number of samples should be, as opposed to the sampling interval. The examples I've given in the revamped demo work, but it isn't the most convenient. Anyway...
People will have preference to whether a line should be connecting a discontinuity, but if one desires the line be present I think the preference is for the line connecting the right and left limits of a discontinuity to be vertical as opposed to the slightly sloped line that comes about from uniform sampling. "with steps" gives us that, but in many cases the steps appearance isn't always appropriate where parts of the function are continuous.
Regarding this, it might be nice for steps to have a version where the vertical lines are not plotted, just the horizontal lines. Mathematically that is more appropriate, and an analog oscilloscope trace often looks to have no vertical lines with unfiltered reconstructed signals.
Also note in this example plots that after the patch, the definition for the distribution is correct for all of x. So the negative values of the PDF, after the patch, look correct.
Dan
PS: fsteps/histeps/steps might have worked syntactically better as lsteps/csteps/rsteps. (I'm guessing "fsteps" means forward steps or front steps.)
|