Coder Social home page Coder Social logo

sarnold / medians-1d Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 2.0 224 KB

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

C 76.41% Shell 2.77% Makefile 10.82% M4 2.54% Python 7.46%
c median-finding performance cython

medians-1d's People

Contributors

sarnold avatar sjlc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

medians-1d's Issues

Fix non-void function return

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 

Torben algorithm enhancement

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.

Needs tests

Can we use just a python test driver here? Should demo.c include a test/compare option?

refactor library defs

Decide which demo functions to include in shared lib and python interface and refactor as needed. Update doxy tags and config file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.