-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdistribution.lua
More file actions
163 lines (142 loc) · 4.39 KB
/
Copy pathdistribution.lua
File metadata and controls
163 lines (142 loc) · 4.39 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
require 'torch'
local optParser = require 'opts'
local opt = optParser.parse(arg)
local tnt = require 'torchnet'
local sgfloader = require 'utils.sgf'
local board = require 'board.board'
local common = require 'common.common'
local goutils = require 'utils.goutils'
local function protected_play(b, game)
local x, y, player = sgfloader.parse_move(game:play_current(), false)
if player ~= nil and board.play(b, x, y, player) then
game:play_next()
print("---------------------------------------------------------")
print(player)
print(board.show(b, "all"))
local opt = {}
opt.userank = false
opt.feature_type = "complete"
local feature = goutils.extract_feature(b, player, opt, rank, 'test');
print(feature:size())
print(feature[1])
return true
else
return false
end
end
--from infra/framewor.lua
local function load_dataset(partition)
return tnt.IndexedDataset{
fields = { opt.datasource .. "_" .. partition },
--path = './dataset'
path = opt.path
}
end
--Get the distribution of the number of round for each game
local function print_numOfRound(dataset)
local countRound = torch.Tensor(8):zero()
for i = 1, dataset:size() do
sample = dataset:get(i)
for k, v in pairs(sample) do
sample = v
break
end
content = sample.table.content
filename = sample.table.filename
game = sgfloader.parse(content:storage():string(), filename)
round = game:num_round()
if round == 0 then
countRound[1] = countRound[1] + 1
elseif round <= 50 then
countRound[2] = countRound[2] + 1
elseif round <= 100 then
countRound[3] = countRound[3]+ 1
elseif round <= 150 then
countRound[4] = countRound[4] + 1
elseif round <= 200 then
countRound[5] = countRound[5] + 1
elseif round <= 250 then
countRound[6] = countRound[6] + 1
elseif round <= 300 then
countRound[7] = countRound[7] + 1
else
countRound[8] = countRound[8] + 1
end
end
for i = 1, 8 do
print(countRound[i])
end
end
--Get the distribution of the number of round for each game
local function print_numOfRank(dataset)
local countRank = torch.Tensor(4):zero()
for i = 1, dataset:size() do
sample = dataset:get(i)
for k, v in pairs(sample) do
sample = v
break
end
content = sample.table.content
filename = sample.table.filename
game = sgfloader.parse(content:storage():string(), filename)
br, wr = game:get_ranks('kgs')
if wr == '1d' or wr == '2d' or wr == '3d' or wr == '4d' then
countRank[1] = countRank[1] + 1
elseif wr == '5d' or wr == '6d' or wr == '7d' then
countRank[2] = countRank[2] + 1
elseif wr == '8d' or wr == '9d' then
countRank[3] = countRank[3] + 1
else
countRank[4] = countRank[4] + 1
end
end
for i = 1, 4 do
print(countRank[i])
end
end
local function print_feature(dataset)
sample_idx = math.random(dataset:size())
local sample = dataset:get(sample_idx)
for k, v in pairs(sample) do
sample = v
break
end
local content = sample.table.content
local filename = sample.table.filename
b = board.new()
game = sgfloader.parse(content:storage():string(), filename)
--print(content:storage():string())
--print(sgfloader.show_move(game))
--local br, wr = game:get_ranks('kgs')
--print(br)
--print(wr)
--print(game:num_round())
if game ~= nil and game:has_moves() and game:get_boardsize() == common.board_size and game:play_start() then
board.clear(b)
goutils.apply_handicaps(b, game)
local game_play_through = true
local round = math.random(game:num_round()) - 1
for j = 1, round do
--print(game)
if not protected_play(b, game) then
break
end
end
end
end
-- training/test set
local train_dataset = load_dataset("train")
local test_dataset = load_dataset("test")
print("Training data round distribution:")
print_numOfRound(train_dataset)
print("Testing data round distribution:")
print_numOfRound(test_dataset)
print("Training data rank distribution:")
print_numOfRound(train_dataset)
print("Print feature:")
print_feature(train_dataset)
--print(train_dataset:size())
--print(test_dataset:size())
--print(train_dataset:get(1))
--local sample = train_dataset:get(2)
--print(sample.table)