 |
|
 |
I think there is a bug in line 277 of Histogram.h:
Old code:
template <class T, class TOut>
std::vector<TOut> THistogram<T,TOut>::GetCenterContainers() const
{
std::vector<TOut> vX( m_vCounters.size());
for (UINT i = 0;i<m_vCounters.size(); i++)
vX[i]= m_tMin + (i+0.5)*m_dStep;
return vX;
}
New code:
template <class T, class TOut>
std::vector<TOut> THistogram<T,TOut>::GetCenterContainers() const
{
std::vector<TOut> vX( m_vCounters.size());
for (UINT i = 0;i<m_vCounters.size(); i++)
vX[i]= m_tMin + (i-0.5)*m_dStep;
return vX;
}
I used the following test data:
int nColDataSize = 940;
DWORD pData[940];
DWORD sum = 0;
for (r = 0; r < 10; r++)
{
pData[r] = 11;
sum += pData[r];
}
for (r = 10; r < 30; r++)
{
pData[r] = 12;
sum += pData[r];
}
for (r = 30; r < 70; r++)
{
pData[r] = 13;
sum += pData[r];
}
for (r = 70; r < 150; r++)
{
pData[r] = 14;
sum += pData[r];
}
for (r = 150; r < 310; r++)
{
pData[r] = 15;
sum += pData[r];
}
for (r = 310; r < 630; r++)
{
pData[r] = 16;
sum += pData[r];
}
for (r = 630; r < 790; r++)
{
pData[r] = 17;
sum += pData[r];
}
for (r = 790; r < 870; r++)
{
pData[r] = 18;
sum += pData[r];
}
for (r = 870; r < 910; r++)
{
pData[r] = 19;
sum += pData[r];
}
for (r = 910; r < 930; r++)
{
pData[r] = 20;
sum += pData[r];
}
for (r = 930; r < 940; r++)
{
pData[r] = 21;
sum += pData[r];
}
It generates 11 symmetrical bins around a value of 16 (11 to 21), with each bin doubling its count on its way towards the center value and then dividing its count when exceeding the center value.
Mean value of such distribution is 16.
When you plot the whole thing using code like
THistogram<double, double> histo(11);
std::vector<double> vDataX(nColDataSize);
std::vector<double> vDataY(nColDataSize);
for (r = 0; r < nColDataSize; r++)
{
vDataX[r] = (double)(r);
vDataY[r] = (double)(pData[r]);
}
histo.Compute(vDataY);
CPGLGraph* pGraph = new CPGLGraph;
CPGLLine2D* pLine = new CPGLLine2D;
pLine->SetInterpolationType(PGL_INTERPOLATION_STEP);
pLine->SetLineWidth(2);
std::vector<double> vX(histo.GetCenterContainers());
std::vector<double> vY(histo.GetHistogramD());
pLine->SetDatas(vX, vY);
pGraph->AddObject(pLine);
pGraph->ZoomAll();
CPGLGraphBitDlg graphdlg( ((CMainFrame*)AfxGetMainWnd())->GetActiveFrame()->GetActiveView(), pGraph);
graphdlg.DoModal();
it centers the histogram maximum at an x-value of 17, not 16.
To correct that bug, use the new code.
Apart from that, PGL only plots 10 y-values, although I have a histogram size of 11. This must be due to the interpolation style, I assume, but I am not sure of that. So the right-most bin is always missing in the plot...?
Anyways, PGL is great work, it saves CodeProject community members a lot of time.
Best regards,
Volker
|
|
|
|
 |
|
 |
Hi.
I have downloaded the source code but it does not compile.
|
|
|
|
 |
|
 |
how should i generate d dimensional samples given a Mu and a Covariance matrix?
|
|
|
|
 |
|
 |
Nice piece of work which I'd very much like to use. I don;t need the histograms, just the normal random variable generator.
My first problem was PGL_PI, but I #defined it and all was OK.
It's now giving me lots of errors like
c:\program files\microsoft visual studio\vc98\include\new(35) : error C2061: syntax error : identifier 'THIS_FILE'
which shouldn't be a problem as they're the standard files - do I need to add another library to use this code?
Thanks
Paul.
|
|
|
|
 |
|
 |
I have these simple algorithms which i used to create a guaranteed random
number from a normal or exponential distribution:
A. NORMAL DISTRIBUTION
z = inverse_ncdf(random()); // where inverse_ncdf is the function similar
// to 'normsinv()' of Excel (or OOO Calc) and
// random() is the function which generates a
// random number from 0 to 1.
return z * sd + mean; // where sd is your desired standard deviation and
// mean is your desired average.
B. EXPONENTIAL DISTRIBUTION
return -mean * log(1-random()); // where mean is your desired average,
// log is the NATURAL LOGARITHM function
// (similar with LN() function of excel)
// and random() is the function which
// generates a random number from 0 to 1.
I hope this helps!!!
Alex Andrew Mosqueda
I am your friend
|
|
|
|
 |
|
 |
Hello Again,
I found another few catch22 on the Histogram Template...
First, you start with a single sample, ComputeStep() may have a divide error. (the provided vector size is 1)... sounds ridiculous, but sometimes you may want to add samples (via Update()) as you get them....
Calling Compute() with a bComputeMinMax = false, and you get an under/over sized sample in the input vector, the function will return as soon the first under/over sised sample is encontered. I guess it will be better to invert the condition, and instead of returning on the first non-legal value, allow inserting all legal values (also in Update()). Of course, in this case, you need to set the max/min spectrum before calling Compute()...
Today, also if you call Update() before Compute(), without calling first Set max/min spectrum, you also get wrong stuff.
And to finalize, great template. I learned a lot from it. THANKS A LOT as well.
--- Ricky
"Beware of bugs in the above code; I have only proved it correct,
but not tried it." -- Donald Knuth
|
|
|
|
 |
|
 |
Nice work!
One thing is that: application should only have one Random Generator object(one instance of the class), and this object should be global(to be available to every one) ! That is why it is better to implement it as a global function not a class! If you use two objects of random class in your applicaton they will generate correlated sequences and your results will not be trully random. Another good random generator can be taken from www.nr.com
be good
|
|
|
|
 |
|
 |
Just make it a singleton.
Jonathan
|
|
|
|
 |
|
 |
Yes you right it should be singleton! (always)
Btw have you tested your generator? (using DIEHARD for example). I am doing right now monte-carlo simulation, and 90% of execution time I generate random numbers (by nr routine, for which I wrote "singleton" wraper ). So if i can generate them faster it would speed-up simulation process dramatically, but the problem is I need very "Random" numbers (high quality randomness). I am going to try testing your code )
Thank you for the nice class!
Alex-
|
|
|
|
 |
|
 |
>You will need Matlab installed to make the demo application work !
So I find the link to download and read....
"Non-members
• To request a trial, you may complete this form to have a sales representative contact you. "
NO THANKS.
Can't you put an easier demo for us non-members and non PHd's???
Joe
|
|
|
|
 |
|
 |
JoeSox wrote:
Can't you put an easier demo for us non-members and non PHd's???
If you take the time to read the line above this, you see:
There are two projects in the demo application:
HistogramDemo uses the Plot Graphic Library for visualization. There is another article on the PGL here. You will need the GDI+ binaries to make the demo application work ! (gdiplus.dll)
As far as I know, GDI+ has nothing to do with Matlab (sorry I'm being sarcastic, ).
If you try HistogramDemo, you do not need Matlab.
Jonathan de Halleux.
|
|
|
|
 |
|
 |
Nice job!
But the demo project does not compile: Cannot open include file: 'gdiplus.h': No such file or directory
Where is 'gdiplus.h' then?
Thanks
Shen
|
|
|
|
 |
|
 |
See GDI+ section ( look at the message board of "Starting GDI+" article)
Jonathan de Halleux.
|
|
|
|
 |
|
 |
"Starting with GDI+" or (http://www.codeproject.com/vcpp/gdiplus/startinggdiplus.asp), sorry, I tried to search "Starting GDI+" with no good results. Just thought I would post for others.
"You can't throw yourself a parade every time you win, and you can't bury yourselves when you lose."-Levon Kirkland Philadelphia Eagles
|
|
|
|
 |
|
 |
I though I had read there a nice post about installing GDI+. Anyway, it's christmas so:
GDI+ is part of the Microsoft Core SDK. You can download it at microsoft download site but you better have a gooood connection, as it is a lengthy download (you can also order a CD). Anyway, once the SDK is installed, that's it ! You're ready to rummmble.
One last thing, make sure gdiplus.dll is in your path.
Jonathan de Halleux.
|
|
|
|
 |
|
 |
I get this too. Where is gdiplus.h?
Thanks
|
|
|
|
 |
|
 |
Read the post above
Jonathan de Halleux.
|
|
|
|
 |
|
 |
The demo package is missing a necessary DLL, PGL(d).dll
|
|
|
|
 |
|
 |
Yes, indeed, it's missing.
I've sent a fix to CP so the article should be updated in a few days. If you don't want to wait that long, build the DLL yourself by download the Plot Graphic Library (also on CP).
Cheers
Jonathan de Halleux.
|
|
|
|
 |
|
 |
You article seems very interesting... but I can't download the sources... Where can I find it ?
|
|
|
|
 |
|
 |
Looks like there has been a problem when moving the article, the files are not there anymore...
CodeProject will fix soon I hope.
Note that there is a "Broken links?" feature on the left menu for those problems.
Cheers
Jonathan de Halleux, Belgium.
|
|
|
|
 |
|
 |
--------------------Configuration: HistogramDemo - Win32 Debug--------------------
Compiling...
StdAfx.cpp
f:\ÏÂÔØÄÚÈÝ\zigurat_demo\gdiplus\gdiplusinit.h(32) : error C2065: 'ULONG_PTR' : undeclared identifier
f:\ÏÂÔØÄÚÈÝ\zigurat_demo\gdiplus\gdiplusinit.h(32) : error C2065: 'token' : undeclared identifier
f:\ÏÂÔØÄÚÈÝ\zigurat_demo\gdiplus\gdiplusinit.h(32) : error C2165: 'left-side modifier' : cannot modify pointers to data
f:\ÏÂÔØÄÚÈÝ\zigurat_demo\gdiplus\gdiplusinit.h(32) : error C2071: 'NotificationHookProc' : illegal storage class
f:\ÏÂÔØÄÚÈÝ\zigurat_demo\gdiplus\gdiplusinit.h(33) : error C2146: syntax error : missing ')' before identifier 'token'
f:\ÏÂÔØÄÚÈÝ\zigurat_demo\gdiplus\gdiplusinit.h(33) : error C2165: 'left-side modifier' : cannot modify pointers to data
f:\ÏÂÔØÄÚÈÝ\zigurat_demo\gdiplus\gdiplusinit.h(33) : error C2071: 'NotificationUnhookProc' : illegal storage class
f:\ÏÂÔØÄÚÈÝ\zigurat_demo\gdiplus\gdiplusinit.h(33) : error C2059: syntax error : ')'
f:\ÏÂÔØÄÚÈÝ\zigurat_demo\gdiplus\gdiplusinit.h(86) : error C2059: syntax error : 'const'
f:\ÏÂÔØÄÚÈÝ\zigurat_demo\gdiplus\gdiplusinit.h(95) : error C2146: syntax error : missing ')' before identifier 'token'
f:\ÏÂÔØÄÚÈÝ\zigurat_demo\gdiplus\gdiplusinit.h(95) : warning C4229: anachronism used : modifiers on data are ignored
f:\ÏÂÔØÄÚÈÝ\zigurat_demo\gdiplus\gdiplusinit.h(95) : error C2182: 'GdiplusShutdown' : illegal use of type 'void'
f:\ÏÂÔØÄÚÈÝ\zigurat_demo\gdiplus\gdiplusinit.h(95) : error C2059: syntax error : ')'
Error executing cl.exe.
HistogramDemo.exe - 12 error(s), 1 warning(s)
1234
|
|
|
|
 |
|
 |
The demo won't compile under VC7 however, the CHistogram and CZigurat classes work under VC6, VC7
Jonathan de Halleux, Belgium.
|
|
|
|
 |
|
 |
Just what my Genetic Algorithm wanted. Thanks!
|
|
|
|
 |
|
 |
The demo zip is missing at least one file: ImageHistogram.cpp (and .h).
Would be nice if the demo archive contained the executable, too.
|
|
|
|
 |