From ed3b7e92b9e04b9d39e75024cbb233bbc0c013d6 Mon Sep 17 00:00:00 2001 From: arnaucode Date: Sat, 17 Jun 2017 03:03:29 +0200 Subject: [PATCH] dist min --- euclideanDistance.go | 12 ++++++------ main.go | 10 ++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/euclideanDistance.go b/euclideanDistance.go index 754d6ff..a0bb4f5 100644 --- a/euclideanDistance.go +++ b/euclideanDistance.go @@ -34,18 +34,18 @@ func calcDistances(in []float64, ds []float64) float64 { } func getShortestDistance(dist [][][]float64) [][]float64 { - min := dist[0][2] + //dist contains: [[datasetLine], [datasetLineResult], [distanceWithInput]] + minDist := dist[0][2] max := dist[0][2] var datasetNearResult [][]float64 for i := 0; i < len(dist); i++ { - //fmt.Println(dist[i][1]) + //fmt.Println(dist[i]) if dist[i][2][0] > max[0] { max = dist[i][0] } - /*fmt.Println(min[0]) - fmt.Println(dist[i][1][0])*/ - if dist[i][2][0] < min[0] { - min = dist[i][0] + //fmt.Println(dist[i][2][0]) + if dist[i][2][0] < minDist[0] { + minDist = dist[i][2] datasetNearResult = dist[i] } //fmt.Println(dist[i][1]) diff --git a/main.go b/main.go index 31942da..0038e64 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,9 @@ package main -import "fmt" +import ( + "fmt" + "strconv" +) func main() { dataset := readDataset("datasets/poker/poker-hand-training-true.data", "\n", ",") @@ -9,11 +12,14 @@ func main() { //fmt.Println(inputs) var datasetDistances [][][]float64 - for _, input := range inputs { + for k, input := range inputs { datasetDistances = euclideanDistance(dataset, input) r := getShortestDistance(datasetDistances) + fmt.Println("iteration " + strconv.Itoa(k)) fmt.Println(input) fmt.Println(r) + fmt.Print("result: ") fmt.Println(r[1]) + fmt.Println("---") } }