Beispiel #1
0
        public void EncodeNormalFeatureH5(string fileName)
        {
            dynamic      h5py = Py.Import("h5py");
            StreamReader file = new StreamReader(fileName);
            string       line = null;

            PyList[] features = new PyList[9];
            for (int i = 0; i < 9; i++)
            {
                features[i] = new PyList();
            }
            PyList resultList = new PyList();
            int    count      = 0;

            string[] featureNames = null;
            while ((line = file.ReadLine()) != null)
            {
                GameRecord          gameRecord = JsonConvert.DeserializeObject <GameRecord>(line);
                List <StateKeyInfo> playSec    = new List <StateKeyInfo>();
                foreach (StateKeyInfo stKeyInfo in gameRecord.playSec)
                {
                    int          result          = (stKeyInfo.attackPlayer.turn == gameRecord.result) ? 1 : 0;
                    StateFeature normalFeature   = Featurization.normalFeaturization(stKeyInfo);
                    Feature      playableFeature = normalFeature.featrueArray[5];
                    PyList[]     featureList     = normalFeature.getPyFeatureData();
                    if (featureNames == null)
                    {
                        featureNames = normalFeature.getFeatureNames();
                    }
                    for (int i = 0; i < 9; i++)
                    {
                        PythonUtils.AppendRecycle(features[i], featureList[i]);
                    }
                    PythonUtils.AppendRecycle(resultList, FeatureConst.Instance.pyIntMap[result]);
                }
            }
            string  outFileName = fileName + "norm.hdf5";
            dynamic outFile     = h5py.File(outFileName, "w");

            for (int i = 0; i < 9; i++)
            {
                outFile.create_dataset(featureNames[i], Py.kw("data", features[i]));
            }
            outFile.close();
        }