Skip to content

Latest commit

 

History

History
57 lines (39 loc) · 1.89 KB

README.md

File metadata and controls

57 lines (39 loc) · 1.89 KB

Jenks Natural Breaks

A Golang implementation of the Jenks natural breaks optimization algorithm. It is a data clustering algorithm designed to determine the best arrangement of values into different classes, seeking to reduce the variance within classes and maximize the variance between classes.

This is a fork of ThinkingLogic/jenks which adds new features, bug fixes, and performance improvements.

Ported from a javascript version - itself ported from Fortran and described here by Tom MacWright.

Build Status Coverage Status

Usage

import 	"github.com/ThinkingLogic/jenks"

//...

data := []float64{1.1, 2.1, 3.1,  12.1, 13.1, 14.1,  21.1, 22.1, 23.1,  27.1, 28.1, 29.1}

breaks := jenks.NaturalBreaks(data, 4)
// [1.1, 12.1, 21.1, 27.1]

rounded := jenks.Round(breaks, data)
// [0, 10, 20, 27]

allBreaks := jenks.AllNaturalBreaks(data, 4)
// [ [1.1, 21.1]
//   [1.1, 12.1, 21.1]
//   [1.1, 12.1, 21.1, 27.1] ]

License

This software is Licenced under the MIT License.

Changes from the original JS version

Please note that the javascript version this was ported from is broken, specifically this line:

kclass[countNum - 1] = data[lower_class_limits[k][countNum] - 2];

should be:

kclass[countNum - 1] = data[lower_class_limits[k][countNum] - 1];

- it has been fixed here, along with a number of minor improvements (such as not returning the upper bound so that the length of the returned slice matches the requested number of classes).