-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileUtils.go
More file actions
62 lines (52 loc) · 1.37 KB
/
FileUtils.go
File metadata and controls
62 lines (52 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"strconv"
"strings"
"io/ioutil"
)
func getData(file string) [][]float64 {
allData := make([][]float64, 0)
r, _ := ioutil.ReadFile(file)
re := string(r)
record := strings.Split(re, "\n")
for i := 0; i < len(record); i++ {
dataLine := make([]float64, 0)
dataPoint := strings.Split(record[i], ",")
for j := 0; j < len(dataPoint); j++ {
val, _ := strconv.ParseFloat(dataPoint[j], 64)
if val != 0 {
dataLine = append(dataLine, val)
}
}
if i < len(record) - 1 {
startIndex := strings.LastIndexByte(record[i], ',')
classString := record[i][startIndex + 1 : startIndex+ 2]
classString = strings.Trim(classString, " ")
classFloat, _ := strconv.ParseFloat(classString, 64)
if classFloat == 2 {
classFloat = 0
}
dataLine = append(dataLine, classFloat)
}
if len(dataLine) != 0 {
allData = append(allData, dataLine)
}
}
return allData
}
func prepareData(data [][]float64) [][]float64 {
maxValues := make([]float64, len(data[0]) - 1)
for i := 0; i < len(data); i++ {
for j := 0; j < len(data[i]) - 1; j++ {
if data[i][j] > maxValues[j] {
maxValues[j] = data[i][j]
}
}
}
for i := 0; i < len(data); i++ {
for j := 0; j < len(data[i]) - 1; j++ {
data[i][j] = data[i][j] / maxValues[j]
}
}
return data
}