jenks

package module
v1.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2019 License: MIT Imports: 5 Imported by: 0

README

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).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllNaturalBreaks

func AllNaturalBreaks(data []float64, maxClasses int) [][]float64

AllNaturalBreaks finds all natural breaks in the data, for every set of breaks between 2 breaks and maxClasses. Uses the Jenks natural breaks classification method (http://en.wikipedia.org/wiki/Jenks_natural_breaks_optimization). It tries to maximize the similarity of numbers in groups while maximizing the distance between the groups.

func BestNaturalBreaks added in v1.1.2

func BestNaturalBreaks(data []float64, maxClasses int, minGvf float64) []float64

func NaturalBreaks

func NaturalBreaks(data []float64, nClasses int) []float64

NaturalBreaks returns the best nClasses natural breaks in the data, using the Jenks natural breaks classification method (http://en.wikipedia.org/wiki/Jenks_natural_breaks_optimization). It tries to maximize the similarity of numbers in groups while maximizing the distance between the groups.

func Round

func Round(breaks []float64, data []float64) []float64

Round rounds the values of the given breaks as much as possible without changing the membership of each class. e.g. will attempt to round 111.11 to 111.1, then 111, then 110, then 100, then 0 - ensuring that using the rounded break value doesn't change the membership of any class.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL