Previous topic

Dissolving regions

Next topic

Exogenous number of regions (defined by the user)

This Page

Regionalizing with clusterPy

Layer.cluster(*args, **kargs)

Layer.cluster contains a wide set of algorithms for clustering with spatial contiguity constraints. For literature reviews on constrained clustering, see [Murtagh1985], [Gordon1996], [Duque_Ramos_Surinach2007].

Below you will find links that take you to a detailed description of each algorithm.

The available algorithms are:

Parameters:
  • args (tuple) – Basic parameters.
  • kargs (dictionary) – Optional parameter keywords.

The dataOperations dictionary used by ‘dissolveMap <dissolveMap>’ could be passed in order to specify which data should be calculated for the dissolved layer. The dataOperations dictionary must be:

>>> X = {}
>>> X[variableName1] = [function1, function2,....]
>>> X[variableName2] = [function1, function2,....]

Where functions are strings wich represents the name of the functions to be used on the given variableName. Functions could be,’sum’,’mean’,’min’, ‘max’,’meanDesv’,’stdDesv’,’med’, ‘mode’,’range’,’first’,’last’, ‘numberOfAreas. By deffault just ID variable is added to the dissolved map.

Examples

ARISEL

Arisel description:

Example 1

import clusterpy
instance = clusterpy.createGrid(10, 10)
instance.generateData("SAR", 'rook', 1, 0.9)
instance.exportArcData("testOutput/arisel_1_input")
instance.cluster('arisel', ['SAR1'], 15, dissolve=1)
instance.results[0].exportArcData("testOutput/arisel_1_solution")
../_images/ARISEL1.png

Example 2

import clusterpy
instance = clusterpy.createGrid(10, 10)
instance.generateData("SAR", 'rook', 2, 0.9)
instance.exportArcData("testOutput/arisel_2_input")
instance.cluster('arisel', ['SAR1', 'SAR2'], 15, wType='queen', std=1, inits=3, convTabu=5, tabuLength=5, dissolve=1)
instance.results[0].exportArcData("testOutput/arisel_2_solution")

Example 3

import clusterpy
instance = clusterpy.createGrid(3, 3)
instance.generateData("SAR", 'rook', 2, 0.9)
instance.exportArcData("testOutput/arisel_3_input")
instance.cluster('arisel', ['SAR1', 'SAR2'], 3, wType='queen', std=1, inits=1, initialSolution=[0, 0, 1, 0, 1, 1, 2, 2, 2], convTabu=5, tabuLength=5, dissolve=1)
instance.results[0].exportArcData("testOutput/arisel_3_solution")

Example 4

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.fieldNames
dataOperations = {'POP1970':['sum', 'mean'], 'POP2001':['sum', 'mean']}
calif.exportArcData("testOutput/arisel_4_input")
calif.cluster('arisel', ['POP1970', 'POP2001'], 15, inits= 3, dissolve=1, dataOperations=dataOperations)
calif.results[0].exportArcData("testOutput/arisel_4_solution")

Example 5

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.fieldNames
calif.dataOperation("g70_01 = float(POP2001 - POP1970) / POP1970")
calif.exportArcData("testOutput/arisel_5_input")
calif.cluster('arisel', ['g70_01'], 15, inits= 4, dissolve=1)
calif.results[0].exportArcData("testOutput/arisel_5_solution")
../_images/ARISEL5.png

AZP

AZP description

Example 1

import clusterpy
instance = clusterpy.createGrid(10, 10)
instance.generateData("SAR", 'rook', 2, 0.9)
instance.exportArcData("testOutput/azp_1_input")
instance.cluster('azp', ['SAR1'], 15, dissolve=1)
instance.results[0].exportArcData("testOutput/azp_1_solution")
../_images/AZP1.png

Example 2

import clusterpy
instance = clusterpy.createGrid(10, 10)
instance.generateData("SAR", 'rook', 2, 0.9)
instance.exportArcData("testOutput/azp_2_input")
instance.cluster('azp', ['SAR1', 'SAR2'], 15, wType='queen', std=1, dissolve=1)
instance.results[0].exportArcData("testOutput/azp_2_solution")

Example 3

import clusterpy
instance = clusterpy.createGrid(3, 3)
instance.generateData("SAR", 'rook', 2, 0.9)
instance.exportArcData("testOutput/azp_3_input")
instance.cluster('azp', ['SAR1', 'SAR2'], 3, wType='queen', std=1, initialSolution=[0, 0, 1, 0, 1, 1, 2, 2, 2], dissolve=1)
instance.results[0].exportArcData("testOutput/azp_3_solution")

Example 4

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.fieldNames
dataOperations = {'POP1970':['sum', 'mean'], 'POP2001':['sum', 'mean']}
calif.exportArcData("testOutput/azp_4_input")
calif.cluster('azp', ['POP1970', 'POP2001'], 15, dissolve=1, dataOperations=dataOperations)
calif.results[0].exportArcData("testOutput/azp_4_solution")

Example 5

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.fieldNames
calif.dataOperation("g70_01 = float(POP2001 - POP1970) / POP1970")
calif.exportArcData("testOutput/azp_5_input")
calif.cluster('azp', ['g70_01'], 15, dissolve=1)
calif.results[0].exportArcData("testOutput/azp_5_solution")
../_images/AZP5.png

AZP Simulated Annealing

AZP Simulated Annealing description

Example 1

import clusterpy
instance = clusterpy.createGrid(10, 10)
instance.generateData("SAR", 'rook', 2, 0.9)
instance.exportArcData("testOutput/azpSA_1_input")
instance.cluster('azpSa', ['SAR1'], 15, dissolve=1)
instance.results[0].exportArcData("testOutput/azpSA_1_solution")
../_images/AZPSA1.png

Example 2

import clusterpy
instance = clusterpy.createGrid(10, 10)
instance.generateData("SAR", 'rook', 2, 0.9)
instance.exportArcData("testOutput/azpSA_2_input")
instance.cluster('azpSa', ['SAR1', 'SAR2'], 15, wType='queen', std=1, maxit=2, dissolve=1)
instance.results[0].exportArcData("testOutput/azpSA_2_solution")

Example 3

import clusterpy
instance = clusterpy.createGrid(3, 3)
instance.generateData("SAR", 'rook', 2, 0.9)
instance.exportArcData("testOutput/azpSA_3_input")
instance.cluster('azpSa', ['SAR1', 'SAR2'], 3, wType='queen', std=1, initialSolution=[0, 0, 1, 0, 1, 1, 2, 2, 2], maxit=2, dissolve=1)
instance.results[0].exportArcData("testOutput/azpSA_3_solution")

Example 4

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.fieldNames
dataOperations = {'POP1970':['sum', 'mean'], 'POP2001':['sum', 'mean']}
calif.exportArcData("testOutput/azpSA_4_input")
calif.cluster('azpSa', ['POP1970', 'POP2001'], 15, dissolve=1, dataOperations=dataOperations)
calif.results[0].exportArcData("testOutput/azpSA_4_solution")

Example 5

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.fieldNames
calif.dataOperation("g70_01 = float(POP2001 - POP1970) / POP1970")
calif.exportArcData("testOutput/azpSA_5_input")
calif.cluster('azpSa', ['g70_01'], 15, dissolve=1)
calif.results[0].exportArcData("testOutput/azpSA_5_solution")
../_images/AZPSA5.png

AZP Tabu

AZP tabu description

Example 1

import clusterpy
instance = clusterpy.createGrid(10, 10)
instance.generateData("SAR", 'rook', 1, 0.9)
instance.exportArcData("testOutput/azpTabu_1_input")
instance.cluster('azpTabu', ['SAR1'], 15, dissolve=1)
instance.results[0].exportArcData("testOutput/azpTabu_1_solution")
../_images/AZPT1.png

Example 2

import clusterpy
instance = clusterpy.createGrid(10, 10)
instance.generateData("SAR", 'rook', 2, 0.9)
instance.exportArcData("testOutput/azpTabu_2_input")
instance.cluster('azpTabu', ['SAR1', 'SAR2'], 15, wType='queen', std=1, convTabu=5, tabuLength=5, dissolve=1)
instance.results[0].exportArcData("testOutput/azpTabu_2_solution")

Example 3

import clusterpy
instance = clusterpy.createGrid(3, 3)
instance.generateData("SAR", 'rook', 2, 0.9)
instance.exportArcData("testOutput/azpTabu_3_input")
instance.cluster('azpTabu', ['SAR1', 'SAR2'], 3, wType='queen', std=1, initialSolution=[0, 0, 1, 0, 1, 1, 2, 2, 2], convTabu=5, tabuLength=5, dissolve=1)
instance.results[0].exportArcData("testOutput/azpTabu_3_solution")

Example 4

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.fieldNames
dataOperations = {'POP1970':['sum', 'mean'], 'POP2001':['sum', 'mean']}
calif.exportArcData("testOutput/azpTabu_4_input")
calif.cluster('azpTabu', ['POP1970', 'POP2001'], 15, dissolve=1, dataOperations=dataOperations)
calif.results[0].exportArcData("testOutput/azpTabu_4_solution")

Example 5

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.fieldNames
calif.dataOperation("g70_01 = float(POP2001 - POP1970) / POP1970")
calif.exportArcData("testOutput/azpTabu_5_input")
calif.cluster('azpTabu', ['g70_01'], 15, dissolve=1)
calif.results[0].exportArcData("testOutput/azpTabu_5_solution")
../_images/AZPT5.png

AZP Reactive Tabu

AZP reactive tabu description

Example 1

import clusterpy
instance = clusterpy.createGrid(10, 10)
instance.generateData("SAR", 'rook', 1, 0.9)
instance.exportArcData("testOutput/azpRTabu_1_input")
instance.cluster('azpRTabu', ['SAR1'], 15, dissolve=1)
instance.results[0].exportArcData("testOutput/azpRTabu_1_solution")
../_images/AZPR1.png

Example 2

import clusterpy
instance = clusterpy.createGrid(10, 10)
instance.generateData("SAR", 'rook', 2, 0.9)
instance.exportArcData("testOutput/azpRTabu_2_input")
instance.cluster('azpRTabu', ['SAR1', 'SAR2'], 15, wType='queen', std=1, convTabu=5, dissolve=1)
instance.results[0].exportArcData("testOutput/azpRTabu_2_solution")

Example 3

import clusterpy
instance = clusterpy.createGrid(3, 3)
instance.generateData("SAR", 'rook', 2, 0.9)
instance.exportArcData("testOutput/azpRTabu_3_input")
instance.cluster('azpRTabu', ['SAR1', 'SAR2'], 3, wType='queen', std=1, initialSolution=[0, 0, 1, 0, 1, 1, 2, 2, 2], convTabu=5, dissolve=1)
instance.results[0].exportArcData("testOutput/azpRTabu_3_solution")

Example 4

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.fieldNames
dataOperations = {'POP1970':['sum', 'mean'], 'POP2001':['sum', 'mean']}
calif.exportArcData("testOutput/azpRTabu_4_input")
calif.cluster('azpRTabu', ['POP1970', 'POP2001'], 15, dissolve=1, dataOperations=dataOperations)
calif.results[0].exportArcData("testOutput/azpRTabu_4_solution")

Example 5

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.fieldNames
calif.dataOperation("g70_01 = float(POP2001 - POP1970) / POP1970")
calif.exportArcData("testOutput/azpRTabu_5_input")
calif.cluster('azpRTabu', ['g70_01'], 15, dissolve=1)
calif.results[0].exportArcData("testOutput/azpRTabu_5_solution")
../_images/AZPR5.png

MAX-P

Max-p region description

Example 1

import clusterpy
instance = clusterpy.createGrid(10, 10)
instance.generateData("SAR", 'rook', 1, 0.9)
instance.generateData('Uniform', 'rook', 1, 10, 15)
instance.exportArcData("testOutput/maxpTabu_1_input")
instance.cluster('maxpTabu', ['SAR1', 'Uniform2'], threshold=130, dissolve=1)
instance.results[0].exportArcData("testOutput/maxpTabu_1_solution")
../_images/Maxp1.png

Example 2

import clusterpy
instance = clusterpy.createGrid(10, 10)
instance.generateData("SAR", 'rook', 1, 0.9)
instance.generateData('Uniform', 'rook', 1, 10, 15)
instance.exportArcData("testOutput/maxpTabu_2_input")
instance.cluster('maxpTabu', ['SAR1', 'Uniform2'], threshold=130, wType='queen', maxit=3, tabuLength=5, dissolve=1)
instance.results[0].exportArcData("testOutput/maxpTabu_2_solution")

Example 3

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.fieldNames
dataOperations = {'POP1970':['sum', 'mean'], 'POP2001':['sum', 'mean']}
calif.exportArcData("testOutput/maxpTabu_3_input")
calif.cluster('maxpTabu', ['POP1970', 'POP2001'], threshold=100000, dissolve=1, dataOperations=dataOperations)
calif.results[0].exportArcData("testOutput/maxpTabu_3_solution")

Example 4

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.fieldNames
calif.dataOperation("g70_01 = float(POP2001 - POP1970) / POP1970")
calif.exportArcData("testOutput/maxpTabu_4_input")
calif.cluster('maxpTabu', ['g70_01', 'POP2001'], threshold=100000, dissolve=1,std=1)
calif.results[0].exportArcData("testOutput/maxpTabu_4_solution")
../_images/Maxp4.png

AMOEBA

AMOEBA description

Example 1

import clusterpy
instance = clusterpy.createGrid(33, 33)
instance.generateData("Spots", 'rook', 1, 2, 0.7, 0.99)
instance.cluster('amoeba', ['Spots1'],significance=0.01)
instance.exportArcData("testOutput/amoeba_1_solution")
../_images/AMOEBA1.png

Example 2:

import clusterpy
instance = clusterpy.createGrid(25, 25)
instance.generateData("Spots", 'rook', 1, 2, 0.7, 0.99)
instance.cluster('amoeba', ['Spots1'],wType="queen",significance=0.01)
instance.exportArcData("testOutput/amoeba_2_solution")

Example 3

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.dataOperation("g70_01 = float(POP2001 - POP1970) / POP1970")
calif.cluster('amoeba', ['g70_01'],significance=0.01)
calif.exportArcData("testOutput/amoeba_3_solution")
../_images/AMOEBA3.png

Self Organizing Maps (SOM)

SOM description

Example 1

import clusterpy
instance = clusterpy.createGrid(33, 33)
instance.generateData("SAR", "rook", 1, 0.9)
instance.cluster("som", ["SAR1"], nRows=2,nCols=2)
instance.exportArcData("testOutput/som_1_dataLayer")
../_images/som1.png

Example 2

import clusterpy
instance = clusterpy.createGrid(33,33)
instance.generateData("SAR",'rook',1,0.9)
instance.generateData("SAR",'rook',1,0.9)
instance.cluster('som',['SAR1','SAR2'],nRows=2,nCols=2,alphaType='quadratic', fileName="testOutput/NeuronsLayer")
instance.exportArcData("testOutput/som_2_dataLayer")

Example 3

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.dataOperation("g70_01 = float(POP2001 - POP1970) / POP1970")
calif.cluster('som',['g70_01'],nRows=2,nCols=2,alphaType='linear')
calif.exportArcData("testOutput/som_3_solution")
../_images/som3.png

Geo Self Organizing Maps (geoSOM)

GeoSOM description

Example 1

import clusterpy
instance = clusterpy.createGrid(33, 33)
instance.generateData("SAR", "rook", 1, 0.9)
instance.cluster("geoSom", ["SAR1"], nRows=3,nCols=3)
instance.exportArcData("testOutput/geoSom_1_dataLayer")
../_images/geosom1.png

Example 2

import clusterpy
instance = clusterpy.createGrid(33,33)
instance.generateData("SAR",'rook',1,0.9)
instance.generateData("SAR",'rook',1,0.9)
instance.cluster('geoSom',['SAR1','SAR2'],nRows=3,nCols=3,alphaType='quadratic', fileName="testOutput/NeuronsLayer")
instance.exportArcData("testOutput/geoSom_2_dataLayer")

Example 3

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.dataOperation("g70_01 = float(POP2001 - POP1970) / POP1970")
calif.cluster('geoSom',['g70_01'],nRows=3,nCols=3,alphaType='linear')
calif.exportArcData("testOutput/geoSom_3_solution")
../_images/geosom3.png