sarnold / medians-1d Goto Github PK
View Code? Open in Web Editor NEWSeveral C median implementations and a simple demo and Python wrapper.
Home Page: https://sarnold.github.io/medians-1D/
License: GNU Lesser General Public License v3.0
Several C median implementations and a simple demo and Python wrapper.
Home Page: https://sarnold.github.io/medians-1D/
License: GNU Lesser General Public License v3.0
Who the heck wrote this thing anyway? Oh, right, I did...
gcc -DHAVE_CONFIG_H -I. -g -Wall -DANSI -fstrength-reduce -fpcc-struct-return -Wstrict-prototypes -I. -g -O2 -MT demo.o -MD -MP -MF .deps/demo.Tpo -c -o demo.o demo.c
demo.c: In function ‘main’:
demo.c:410:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
mv -f .deps/demo.Tpo .deps/demo.Po
gcc -g -Wall -DANSI -fstrength-reduce -fpcc-struct-return -Wstrict-prototypes -I. -g -O2 -lm -o demo demo.o ./libmedians_1d.a -lm
This isn't an "issue", but an "enhancement" that others may find useful. First off, let me express my thanks for your collection of median algorithms. I was in need of a good median algorithm that was non-destructive without requiring a second copy of the data and that didn't require dynamic memory allocation and yet was decently fast for use in an embedded application with limited computing resources. The Torben algorithm you have featured here almost fit the bill.
Where the Torben algorithm, as presented, fell short was for even-sized datasets, where I needed it to be the true median between the center two elements, not a lower median. The fast median search blog mentions this, but says that in order to obtain the true median, the routine must be called twice, doubling the processing time. But at least for the Torben algorithm, this isn't true.
To get the true NIST median, simply change the exit return code from this:
if (less >= half) return maxltguess;
else if (less+equal >= half) return guess;
else return mingtguess;
To this:
if (less >= half) min = maxltguess;
else if (less+equal >= half) min = guess;
else min = mingtguess;
if (n&1) return min; // if n is odd, we are done
if (greater >= half) max = mingtguess;
else if (greater+equal >= half) max = guess;
else max = maxltguess;
return (min+max)/2;
This simply takes the upper median value, which it actually found in the search as well, and averages it with the lower median value that it was previously returning. The short-circuit check for an odd-n is optional and very slightly reduces execution time for the odd case, depending on the compiler and processor.
I don't know if this can be easily applied to the other algorithms or not. And I didn't submit this as a pull request because your repository was more of a comparison between the algorithms than a specific implementation for a single algorithm. But, I thought this should be mentioned somewhere along with the algorithm for others to reference.
Can we use just a python test driver here? Should demo.c include a test/compare option?
Pretty much what it says, as python funcs are not quite in sync yet anyway.
Decide which demo functions to include in shared lib and python interface and refactor as needed. Update doxy tags and config file.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.