==================================================
Exporting a TD-agent in textual format
==================================================
It is possible to import/export the plain weights of a TD-agent into text files by selecting the corresponding option in the menu:
TD-Agents > Agent X > [ Import | Export ] Agent Weights


The format of the text-files is based on Simon Lucas' n-tuple network format, which is described here:
http://algoval.essex.ac.uk:8080/othello/html/NTuple.html

Since two value functions are learnt in Connect-4 (one for Yellow and one for Red), also two text files have to be created ("p0.txt" and "p1.txt"). The first txt-file (p0.txt) contains the weights for positions where player Yellow is to move.

The format of the files is chosen as follows:

{ 
T
P
{
N_1
M_1
{ Sample Set 1 of size N_1 }
{ Mirrored Sample Set 1 of size N_1 }
{ w_{1,1} w_{1,2} ...  w_{1,P^N_1} }
}

{
N_2
M_2
{ Sample Set 2 of size N_2 }
{ Mirrored Sample Set 2 of size N_2 }
{ w_{2,1} w_{2,2} ...  w_{2,P^N_2} }
}

	.	.	.
	.	.	.
	.	.	.

{
N_T
M_T
{ Sample Set 2 of size N_T }
{ Mirrored Sample Set 2 of size N_T }
{ w_{T,1} w_{T,2} ...  w_{T,P^N_T} }
}

}

where T describes the number of N-tuples (typically 80), N_i defines the number of sample points for n-tuple i, and M_i defines the number of different sample sets for n-tuple i. For Connect-4 we always have M_i=2, since every sample set has one  equivalent set: the set obtained by mirroring along the central column of the board. 

P defines the number of possible states per board cell. Typically, we choose the encoding (P=4), which has the following four states:
0=empty and not reachable, 1=Yellow,
2=Red, 3=empty and reachable.

Each sample set contains N_i integers, all representing a certain board-cell. The following representation is used for the Connect-4 board:

	5 11 17 23 29 35 41
	4 10 16 22 28 34 40
	3  9 15 21 27 33 39
	2  8 14 20 26 32 38
	1  7 13 19 25 31 37
	0  6 12 18 24 30 36

w_{i,j} is the j-th weight in the i-th LUT. Every LUT contains P^N_i weights.


===========================================================
A sample file could look like this (for three 4-tuples):
===========================================================

{
3
4
{
4
2
{ 0 1 2 9 }
{ 36 37 38 33 }
{ 0.0 0.0 0.0 0.45481062 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 -0.048334014 -0.18117405 0.0 0.0 0.0 0.0 0.0 
0.0 0.64851576 -0.26601765 0.0 0.0 -0.37962988 0.2405898 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.0871342 0.19416483 0.0 
0.0 0.4629617 -1.6267575 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.052138302 -0.102141276 0.0 0.0 0.043511793 -0.25889954 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.21374607 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.6008915 0.06398015 0.0 
0.0 0.0 0.0 0.0 0.0 0.7801036 0.06499184 0.0 0.0 -0.269017 
0.428005 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 -0.123489 0.4139371 0.0 0.0 0.38049805 -0.8940161 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.20185086 0.26828077 0.0 
0.0 0.26095107 0.04422329 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 -0.40540722 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.00848572 -0.27233884 0.0 0.0 0.0 0.0 0.0 0.0 0.14204042 
-0.33742088 0.0 0.0 -0.2946839 0.005605723 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 -0.2056659 0.029228376 0.0 0.0 -0.038658507 
0.04160109 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 -0.12979686 -0.100735694 0.0 0.0 -0.24792512 0.003955674 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 -0.25231475 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 -0.20378001 -0.2970262 0.0 0.0 0.0 
0.0 0.0 0.0 -0.85514873 -0.4157317 0.0 0.0 -0.2329118 0.17601608 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.19207746 
0.09042649 0.0 0.0 0.25207788 -0.9779849 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 -0.7725659 -0.20140874 0.0 0.0 0.061833125 
-0.13992208 0.0 0.0 0.0 0.0 0.0 } 
}
{
4
2
{ 0 1 6 7 }
{ 36 37 30 31 }
{ 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.11534482 0.0 -0.026316376 0.1334448 0.0 0.0 -0.07825944 0.089624055 0.0 
0.0 0.3345309 0.7815314 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 -0.03215574 0.0 -0.30046892 -0.2680078 0.0 0.0 -0.29302728 
-0.46287918 0.0 0.0 -0.21348234 0.05991409 0.0 0.0 0.0 0.0 0.13649064 
0.0 -0.16245852 0.3173619 0.0 0.0 -0.17354423 0.14336519 0.0 0.0 -0.38633126 
0.25700304 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.18849133 0.0 -0.24722861 
-0.13620713 0.0 0.0 0.029260617 -0.29074505 0.0 0.0 0.23912498 0.08313575 0.0 
0.0 0.0 0.0 0.16407062 0.0 0.045743458 0.16489358 0.0 0.0 0.072805524 
-0.012958329 0.0 0.0 -0.1146225 0.25312176 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.2225737 0.0 -0.21857238 -0.10276689 0.0 0.0 0.508372 0.0052806893 0.0 
0.0 -0.12163309 0.29628423 0.0 0.0 0.0 0.0 0.3092024 0.0 0.5792774 
0.36598927 0.0 0.0 -0.3362188 0.3227307 0.0 0.0 -0.1590561 0.25218952 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 } 
}
{
4
2
{ 31 32 37 38 }
{ 7 8 1 2 }
{ 0.11534482 0.0 0.0 -0.19633204 0.0 -0.047409415 0.013359914 0.0 0.0 -0.08918325 
-0.077534884 0.0 0.0 -0.4446905 -0.2014732 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.36398113 0.0 
0.0 0.05611671 0.0 -0.21776168 0.12761444 0.0 0.0 -0.10218467 -0.20422171 0.0 
0.0 0.029566428 0.12478232 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.21902347 0.0 0.0 -0.32187247 0.0 -0.037362456 -0.03232547 0.0 0.0 -0.17057453 
-0.39330807 0.0 0.0 0.23796314 0.24659681 0.0 0.46683878 0.0 0.0 0.14077775 
0.0 0.11617037 0.40470973 0.0 0.0 -0.19207823 -0.1889835 0.0 0.0 0.24249844 
0.12936163 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 -0.09433891 0.0 0.0 0.19113019 0.0 0.10900957 
0.33846587 0.0 0.0 -0.09554132 -0.22373664 0.0 0.0 -0.0051472303 -0.14479557 0.0 
-0.5042974 0.0 0.0 -0.06624055 0.0 -0.32288432 -0.14837757 0.0 0.0 -0.38498458 
-0.39712882 0.0 0.0 -0.39666137 -0.19669627 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.008662093 0.0 
0.0 -0.039321456 0.0 -0.093862765 -0.08710469 0.0 0.0 -0.21963483 -0.23309287 0.0 
0.0 -0.03271955 -0.11243725 0.0 -0.031874433 0.0 0.0 -0.04873295 0.0 -0.15334989 
0.0060218107 0.0 0.0 0.07966826 0.0118749365 0.0 0.0 -0.17338887 0.08700038 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 } 
}
}
