Skip to content

DavidBiddle/weiszfeld-median

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

weiszfeld-median

PHP implementation of Weiszfeld algorithm

This function allows you to get the geometric median of:

  • an arbitrary number of points
  • in an arbitrary number of dimensions
  • over an arbitrary number of iterations
  • to an arbitrary number of decimal places

Usage

To use it you'll need to have your data in the form of an array of points with each set of points represented by an array of coordinates (in however many dimensions you're using).

$dataArray = [
  [ 'x' => 1, 'y' => 2, 'z' => 3 ],
  [ 'x' => 9, 'y' => 5, 'z' => 299792458 ],
  [ 'x' => 50, 'y' => 3.14, 'z' => 3 ]
]

and then call getMedian() on it:

$median = getMedian($dataArray,$iterations,$decimalPlaces);

where $iterations and $decimalPlaces are the respective numbers of iterations and decimal places you want.

You'll get your answer as an array of coordinates.

About

PHP implementation of Weiszfeld algorithm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages