package main import ( "fmt" "os" ) const ( Node int = 2708 Edge int = 5429 ) var ( labelName = []string{ "Case_Based", "Genetic_Algorithms", "Neural_Networks", "Probabilistic_Methods", "Reinforcement_Learning", "Rule_Learning", "Theory", } labelCnt = make([]int, len(labelName)) nodeId = make([]int, 0) ) func main() { file, err := os.Open("cora/cora.content") if err != nil { panic(err) } G := MakeGraph() for i := 0; i < Node; i++ { if i%1000 == 0 { fmt.Println("reading node", i) } var u int fmt.Fscan(file, &u) V := MakeVector(Input) for j := 0; j < Input; j++ { fmt.Fscan(file, &V[j]) } var label string fmt.Fscan(file, &label) for j := 0; j < Output; j++ { if labelName[j] == label { if labelCnt[j] < 20 { G.AddNode(u, V, j) nodeId = append(nodeId, u) } else { G.AddNode(u, V, j+Output) } labelCnt[j]++ break } } } file.Close() fmt.Println(labelCnt) file, err = os.Open("cora/cora.cites") if err != nil { panic(err) } for i := 0; i < Edge; i++ { var u, v int fmt.Fscan(file, &u, &v) G.AddEdge(v, u) } file.Close() l := Train(G) Test(G, l, true) }