/
main.go
51 lines (39 loc) · 1.27 KB
/
main.go
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
package main
import (
"os"
"runtime/pprof"
"github.com/eriq-augustine/goml/base"
"github.com/eriq-augustine/goml/classification"
)
const (
LR_CPU_PROFILE_FILENAME = "profile_logisticRegression.prof"
LR_MEM_PROFILE_FILENAME = "profile_logisticRegression.mprof"
)
func main() {
fakeTrainData := base.FakeData(2000, 3, 100, 0, nil, nil, 4);
fakeTestData := base.FakeData(200, 3, 100, 0, nil, nil, 4);
var cpuProfileOutPath string = LR_CPU_PROFILE_FILENAME;
if (len(os.Args) > 1) {
cpuProfileOutPath = os.Args[1];
}
cpuOutFile, err := os.Create(cpuProfileOutPath);
if (err != nil) {
panic("Could not create cpu profile file: " + err.Error());
}
defer cpuOutFile.Close();
var memProfileOutPath string = LR_MEM_PROFILE_FILENAME;
if (len(os.Args) > 2) {
memProfileOutPath = os.Args[2];
}
memOutFile, err := os.Create(memProfileOutPath);
if (err != nil) {
panic("Could not create mem profile file: " + err.Error());
}
defer memOutFile.Close();
pprof.StartCPUProfile(cpuOutFile);
defer pprof.StopCPUProfile();
var lr classification.Classifier = classification.NewLogisticRegression(nil, nil, -1);
lr.Train(fakeTrainData);
pprof.WriteHeapProfile(memOutFile);
lr.Classify(fakeTestData);
}