Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tickets/dm 15203 #388

Merged
merged 2 commits into from Sep 3, 2018
Merged

Tickets/dm 15203 #388

merged 2 commits into from Sep 3, 2018

Conversation

RobertLuptonTheGood
Copy link
Member

No description provided.

Copy link
Contributor

@PaulPrice PaulPrice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bunch of small comments; nothing major.

unsigned long left = 0; // number of values less than naive
unsigned long middle = 0; // number of values equal to naive

for (auto ptr = begin; ptr != end; ++ptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Range-based for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to, but I have begin and end not an STL container.

{
// investigate the cumulative histogram near naive
unsigned long left = 0; // number of values less than naive
unsigned long middle = 0; // number of values equal to naive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have used std::size_t because that's what std::vector uses, but I'm pretty sure it's a typedef for unsigned long.

@@ -495,15 +498,92 @@ double percentile(std::vector<Pixel> &img, double const fraction) {
}
}

namespace {
//
// Helper function to estimate a floating-point quantile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "from integer data"?

}

/**
* @internal A wrapper using the nth_element() built-in to compute percentiles for an image
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this outside the anon namespace if it's @internal?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-existing code. I'll add it to the anon namespace

/**
* @internal A wrapper using the nth_element() built-in to compute percentiles for an image
*
* @param img an afw::Image
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a fake kind of an image, right, because it's a std::vector?

image.set(self.val)
# Note that the mean/median/std may not be quite equal to the requested values
self.images.append((image,
isInt, np.mean(image.array), np.median(image.array), np.std(image.array)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

stats = afwMath.makeStatistics(image, afwMath.MEDIAN)

self.assertEqual(stats.getValue(), stats.getValue(afwMath.MEDIAN))
self.assertEqual(stats.getResult()[
0], stats.getResult(afwMath.MEDIAN)[0])
self.assertEqual(stats.getResult()[0], stats.getResult(afwMath.MEDIAN)[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

stats = afwMath.makeStatistics(image, afwMath.NPOINT | afwMath.STDEV | afwMath.MEAN | afwMath.SUM)

self.assertEqual(stats.getValue(afwMath.NPOINT), image.getWidth()*image.getHeight())
self.assertEqual(stats.getValue(afwMath.NPOINT)*stats.getValue(afwMath.MEAN),
stats.getValue(afwMath.SUM))
self.assertEqual(stats.getValue(afwMath.MEAN), self.val)

self.assertAlmostEqual(stats.getValue(afwMath.MEAN), mean, delta=0.000004)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use delta=0.000004 a lot. Should you put this particular value into a variable so if there's a need to change it later it doesn't need to be changed everywhere? Or did you tune the delta for each test?
And I think scientific notation would be easier to read.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but apparently never did the work. I did check that all the tolerances that could be the same were. I'll fix this.

self.assertEqual(stats.getValue(afwMath.MEDIAN), self.val)
for image, isInt, mean, median, std in self.images:
med = afwMath.makeStatistics(image, afwMath.MEDIAN).getValue()
self.assertAlmostEqual(med, median, delta=0.00022 if isInt else 0.00000075)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the deltas for the integer images always significantly larger than that for the floats? More statistical noise from the quantisation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, but didn't look very hard. I suppose I should; sigh.

stats = afwMath.makeStatistics(img, afwMath.MEANCLIP | afwMath.NCLIPPED)
self.assertEqual(stats.getValue(afwMath.MEANCLIP), 0)
self.assertEqual(stats.getValue(afwMath.NCLIPPED), 0)
for image in self.images:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right thing to do here. The test is checking single-pixel images, so your large images are useless, and indeed aren't used.

The two changes are independent, but both are needed to test the
new code that treats percentiles of integer images correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants