I'm new in go but I found golearn project which has lot of stars on github so I decided to give it a try with simple categorization problem. But with first attempt pointer problem appeared in Train
method and I'm not sure if it's a bug in golearn bindings or is it related with wrong setup.
This is simplified version of code:
package main
import (
_ "github.com/sjwhitworth/golearn/base"
liblinear "github.com/sjwhitworth/golearn/linear_models"
)
func main() {
labels, features := getFeatures()
vocabulary := createVocabulary(features)
words_matrix := countedMatrix(features, vocabulary)
fmt.Println("labels:", labels)
fmt.Println("words matrix:", words_matrix)
solver_type := liblinear.L2R_LR_DUAL
C := 10.0
eps := 0.01
bias := -1.0
parameter := liblinear.NewParameter(solver_type, C, eps)
problem := liblinear.NewProblem(words_matrix, categories, bias)
model := liblinear.Train(problem, parameter)
prediction_vector := countedVector(tokenize("something to predict here"), vocabulary)
fmt.Println("prediction vector:", prediction_vector)
prediction := liblinear.Predict(model, prediction_vector)
fmt.Println("prediction:", prediction)
}
And this is output i get:
labels: [6 8 9 10 11 12 14 15 16 17]
words matrix: [[0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0] [0 1 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0] [0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0] [0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1] [1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0] [0 0 0 1 0 0 0 1 0 0 0 0 0 1 1 1 1 0 0 1 1] [0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 1]]
panic: runtime error: cgo argument has Go pointer to Go pointer
goroutine 1 [running]:
panic(0x83d620, 0xc8200d7510)
/usr/lib/go-1.6/src/runtime/panic.go:481 +0x3e6
github.com/sjwhitworth/golearn/linear_models.Train(0xc820102420, 0xc820015e80, 0xa)
/home/me/gocode/src/github.com/sjwhitworth/golearn/linear_models/liblinear.go:61 +0x11d
main.main()
/home/me/gocode/src/mlservice/main.go:144 +0x62b
exit status 2
Should I report issue or fix code (please help me if fix is possible)