Skip to content

Commit

Permalink
Write a look-up text file for xBin,yBin ranges for each column combo.
Browse files Browse the repository at this point in the history
  • Loading branch information
tigleym committed Nov 29, 2017
1 parent dd9dd99 commit e9b9f6e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Grid.py
Expand Up @@ -18,11 +18,11 @@ def __init__(self, size, xAxis, yAxis):

def buildGrid(self, min_den):
"""Composes a 2-dimensional grid structure."""
for y in range(self.size):
for y in range(len(self.yAxis)):
row = []

for x in range(self.size):
min_y = self.yAxis[(self.size - y) - 1]
for x in range(len(self.xAxis)):
min_y = self.yAxis[(self.size - y)- 1]
max_y = self.yAxis[(self.size - y)]

min_x = self.xAxis[(self.size - x) - 1]
Expand Down
18 changes: 15 additions & 3 deletions main.py
Expand Up @@ -16,15 +16,15 @@
def partitionAttributes(values, partitionSize = 5):
"""Divide values equally according to the specified partition size."""

rangeDistance = (max(values) - min(values)) / partitionSize
rangeDistance = (max(values) - min(values)) / (partitionSize + 1)

ranges = [round(min(values) + ( x * rangeDistance), 2) for x in range(partitionSize)]
ranges.append(max(values))

return ranges

def clusterTwoColumns(columnOneIdentifier, columnTwoIdentifier):
# Build a grid for clustering against "petal_length" vs. "petal_width"
# Build a grid for clustering against columnOneIdentifier vs. columnTwoIdentifier
xAxisRange = partitionAttributes(valuesPerAttr[columnOneIdentifier])
yAxisRange = partitionAttributes(valuesPerAttr[columnTwoIdentifier])

Expand Down Expand Up @@ -64,6 +64,18 @@ def clusterTwoColumns(columnOneIdentifier, columnTwoIdentifier):
dictWriter.writeheader()
dictWriter.writerows(data)

# Write ranges to a text file for look up.
rangeTuples = []

for i in range(len(attributes) + 1):
x = xAxisRange[i]
y = yAxisRange[i]
rangeTuples.append([x, y])

f1 = open(outputFolder + columnOneIdentifier + "_" + columnTwoIdentifier + ".txt", 'w')
f1.write(columnOneIdentifier + ',' + columnTwoIdentifier + '\n')
f1.write(',\n'.join((str(s[0]) + ", " + (str(s[1]))) for s in rangeTuples))

for i in range(len(attributes)-1):
for j in range(i+1, len(attributes)-1):
clusterTwoColumns(attributes[i], attributes[j])
clusterTwoColumns(attributes[i], attributes[j])

0 comments on commit e9b9f6e

Please sign in to comment.