-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimarkov-io.jl
72 lines (53 loc) · 1.97 KB
/
imarkov-io.jl
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
### SMALL DATASET: model-based learning
using RDatasets, DataFrames
using CSV
### INPUT: dataset
function getDataset(input_filename::String)
dataset = readtable(input_filename, header=true)
return dataset
end
function getNumInputRows(input_dataset::DataFrames.DataFrame)
columnNames = names(input_dataset)
aColumn = columnNames[1]
numInputRows = length(input_dataset[aColumn])
end
function input(input_filename::String)
input_dataset = getDataset(input_filename)
# input_dataset = dataset("datasets",input_filename)
columnNames = names(input_dataset)
for rowNum in 1:getNumInputRows(input_dataset) # first row is header
row = input_dataset[rowNum:rowNum,:] # just the one row, every column
for columnName in columnNames
## PROCESS ROW: reinforced learning
# print("(", columnName, ",", row, ")")
end
end
end
### OUTPUT: policy
function output(input_filename::String)
output_filename = input_filename * ".policy"
try
rm(output_filename)
except
println("could not delete inexistent file: " * input_filename)
end
out_file = open(output_filename, "w")
input_dataset = getDataset(input_filename)
columnNames = names(input_dataset)
#aColumn = columnNames[1]
#numOutputRows = length(input_dataset[aColumn]) # TODO
for rowNum in 1:getNumInputRows(input_dataset)
row = input_dataset[rowNum:rowNum,:] # just the one row, every column
## PROCESS: output policy, no header row
println(out_file, rowNum)
#println(out_file, row)
end
close(out_file)
end
### CHECK: policy vs dataset
# check policy file length == number of states
function check(output_filename::String, expected_length::Int64)
output_readback = getDataset(output_filename)
numPolicyRows = getNumInputRows(output_readback)
@printf("\n**** EOL policy rows vs expected **** %s: \t %d vs\t %d \n", output_filename, numPolicyRows, expected_length)
end