15 January 2012

Challenge: Random Number order of operation usage

Below is two examples. Each example should do the same thing but it turns out there is a difference in random number usage between the two. The second example differs from the first example in that the call to the linearSampling() function has been moved out of the circle.isInside() function argument list and replaced with the declaration of double X and double Y.

The two example codes do not give the same results on the same problem due to a difference in the order of random number usage. Can you tell why?

1:   //Example 1
2: unsigned accepted = 0;
3: for(unsigned n=0; n<nTests; ++n) {
4: if( circle.isInside( linearSampling(Range[Shape::X].data(), rng) , linearSampling(Range[Shape::Y].data(), rng) ) )
5: ++accepted;
6: }
7:
8: //Example 2
9: unsigned accepted = 0;
10: for(unsigned n=0; n<nTests; ++n) {
11: double PointX=linearSampling(Range[Shape::X].data(), rng);
12: double PointY=linearSampling(Range[Shape::Y].data(), rng);
13: if( circle.isInside( PointX , PointY ) )
14: ++accepted;
15: }
16:
17: double
18: linearSampling(double* pCoord, rng_t& rng) {
19: return pCoord[0] + ( (pCoord[1]-pCoord[0]) * rng() );
20: }
21:

29 December 2011

Using C++11 std::tuple

A snippet of C++ unit test code showing how to use std::tuple. Using enums to help index the std::get function that is used to retrieve tuple values. Note that std::tuple_size class is used to get the value (size) of the typedef Tuple_t.

 #include <UnitTest++.h>  
#include <tuple>
SUITE(TUPLES){
TEST(Tuples) {
enum TupleIndex {MEAN, STDDEV, SIZE};
typedef std::tuple<double,double> Tuple_t;
CHECK_EQUAL( SIZE, std::tuple_size<Tuple_t>::value );

Tuple_t T1( 99.0, 0.5);
CHECK_CLOSE( 99.0, std::get<MEAN >(T1), 1e-09);
CHECK_CLOSE( 0.5, std::get<STDDEV>(T1), 1e-09);
#if 0
//Out of Range ... caught at compile time.
//g++ error message not so helpful.
std::get<SIZE>(T1);
#endif
}
}

27 November 2011

What Did We Do Before Google and Wikipedia






















This one animation explained a lot without words.

Wish Google and Wikipedia were around when I was in school. Recently had to relearn about ellipses. Actually never learned it that well. But with Wikipedia and some references within then I figured them out well enough for my needs.

Wikipedia::Ellipses

25 November 2011

Collaborative Workspace Ideas

When conference rooms are hard to book .... this may be a warning sign that your company may not take collaborative efforts seriously. With age and more work experience, I find that the more time working in close collaboration than not produces better results. Not only do I find this for myself but observe it with many others. Unfortunately, with my aging and growing, I find myself suspicious of those who do not grow more into collaborative efforts and work alone consistently. Suspicious of what, I am unsure but perhaps suspicious something is not healthy somewhere.

Finding articles like this .... about businesses and companies who are finding great value in collaborative space gives me motivation to continue pursuing this behavior and process at work. Ideas and reasons can be found in the following article.

Inventing The Collaborative Workspace