main.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. )
  6. const (
  7. Node int = 2708
  8. Edge int = 5429
  9. )
  10. var (
  11. labelName = []string{
  12. "Case_Based",
  13. "Genetic_Algorithms",
  14. "Neural_Networks",
  15. "Probabilistic_Methods",
  16. "Reinforcement_Learning",
  17. "Rule_Learning",
  18. "Theory",
  19. }
  20. labelCnt = make([]int, len(labelName))
  21. nodeId = make([]int, 0)
  22. )
  23. func main() {
  24. file, err := os.Open("cora/cora.content")
  25. if err != nil {
  26. panic(err)
  27. }
  28. G := MakeGraph()
  29. for i := 0; i < Node; i++ {
  30. if i%1000 == 0 {
  31. fmt.Println("reading node", i)
  32. }
  33. var u int
  34. fmt.Fscan(file, &u)
  35. V := MakeVector(Input)
  36. for j := 0; j < Input; j++ {
  37. fmt.Fscan(file, &V[j])
  38. }
  39. var label string
  40. fmt.Fscan(file, &label)
  41. for j := 0; j < Output; j++ {
  42. if labelName[j] == label {
  43. if labelCnt[j] < 20 {
  44. G.AddNode(u, V, j)
  45. nodeId = append(nodeId, u)
  46. } else {
  47. G.AddNode(u, V, j+Output)
  48. }
  49. labelCnt[j]++
  50. break
  51. }
  52. }
  53. }
  54. file.Close()
  55. fmt.Println(labelCnt)
  56. file, err = os.Open("cora/cora.cites")
  57. if err != nil {
  58. panic(err)
  59. }
  60. for i := 0; i < Edge; i++ {
  61. var u, v int
  62. fmt.Fscan(file, &u, &v)
  63. G.AddEdge(v, u)
  64. }
  65. file.Close()
  66. l := Train(G)
  67. Test(G, l, true)
  68. }