Skip to content
Snippets Groups Projects
Commit a01de5e3 authored by Andrew E. Torda's avatar Andrew E. Torda
Browse files

Clean up the first few points of standard error in a rather ad hoc manner.

parent db52f8ae
Branches
No related tags found
No related merge requests found
......@@ -25,15 +25,12 @@ const ( // plot size.. my arbitrary choice
)
// oneplot saves us doing the same point copying, adding three times.
// I also toss out the first two points. They are a bit silly and
// have massive errors.
func oneplot(y []float32) (*plot.Plot, error) {
p := plot.New()
points := make(plotter.XYs, len(y))
for i, piV := range y {
points[i] = plotter.XY{X: float64(i + 1), Y: float64(piV)}
} // Toss out the first two y-values...
points[0].Y, points[1].Y = points[2].Y, points[2].Y
}
if line, err := plotter.NewScatter(points); err != nil {
return nil, err
} else {
......@@ -42,6 +39,22 @@ func oneplot(y []float32) (*plot.Plot, error) {
return p, nil
}
// fixStdErr takes the standard error slice and replaces all the
// initial zero entries with the first non-zero entry. This is a
// question of aesthetics, not numerics. It looks silly to have an
// error value that starts at zero and then jumps up.
func fixStdErr(stdErr []float32) {
n := 0
for n = range stdErr {
if stdErr[n] != 0.0 {
break
}
}
for j := 0; j < n; j++ {
stdErr[j] = stdErr[n]
}
}
// doplot copies the data and calls the plotters and writes a jpg
// file to plotname. If plotname has not been set, we just return.
// It is not an error.
......@@ -52,15 +65,17 @@ func doplot(pi, stdErr []float32, plotName string) error {
const step = "step"
var pPi, pStd, pAbs *plot.Plot
var err error
if pPi, err = oneplot(pi); err != nil { // pi estimate
return err
}
pPi.Title.Text = "π estimate"
pPi.Y.Label.Text = "π"
fixStdErr(stdErr)
if pStd, err = oneplot(stdErr); err != nil { // std error
return err
}
pStd.Title.Text = "standard error"
pStd.Y.Label.Text = "std error"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment