Browse Source

dist min

master
arnaucode 7 years ago
parent
commit
ed3b7e92b9
2 changed files with 14 additions and 8 deletions
  1. +6
    -6
      euclideanDistance.go
  2. +8
    -2
      main.go

+ 6
- 6
euclideanDistance.go

@ -34,18 +34,18 @@ func calcDistances(in []float64, ds []float64) float64 {
} }
func getShortestDistance(dist [][][]float64) [][]float64 { func getShortestDistance(dist [][][]float64) [][]float64 {
min := dist[0][2]
//dist contains: [[datasetLine], [datasetLineResult], [distanceWithInput]]
minDist := dist[0][2]
max := dist[0][2] max := dist[0][2]
var datasetNearResult [][]float64 var datasetNearResult [][]float64
for i := 0; i < len(dist); i++ { for i := 0; i < len(dist); i++ {
//fmt.Println(dist[i][1])
//fmt.Println(dist[i])
if dist[i][2][0] > max[0] { if dist[i][2][0] > max[0] {
max = dist[i][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] datasetNearResult = dist[i]
} }
//fmt.Println(dist[i][1]) //fmt.Println(dist[i][1])

+ 8
- 2
main.go

@ -1,6 +1,9 @@
package main package main
import "fmt"
import (
"fmt"
"strconv"
)
func main() { func main() {
dataset := readDataset("datasets/poker/poker-hand-training-true.data", "\n", ",") dataset := readDataset("datasets/poker/poker-hand-training-true.data", "\n", ",")
@ -9,11 +12,14 @@ func main() {
//fmt.Println(inputs) //fmt.Println(inputs)
var datasetDistances [][][]float64 var datasetDistances [][][]float64
for _, input := range inputs {
for k, input := range inputs {
datasetDistances = euclideanDistance(dataset, input) datasetDistances = euclideanDistance(dataset, input)
r := getShortestDistance(datasetDistances) r := getShortestDistance(datasetDistances)
fmt.Println("iteration " + strconv.Itoa(k))
fmt.Println(input) fmt.Println(input)
fmt.Println(r) fmt.Println(r)
fmt.Print("result: ")
fmt.Println(r[1]) fmt.Println(r[1])
fmt.Println("---")
} }
} }

Loading…
Cancel
Save