public void ExportGradients() { /*FilteredValue<int[], int[]>*/ ContextSwitchValue <int[], int[]> av = (ContextSwitchValue <int[], int[]>)agent._actionValue; for (int mapNum = 0; mapNum < av.models.Count; mapNum++) { System.IO.StreamWriter valWriter = new System.IO.StreamWriter("C:\\Users\\Eric\\Desktop\\gradientsVal" + mapNum + ".csv"); for (int i = 0; i < map.GetLength(0); i++) { double[] thisXLine = new double[map.GetLength(1)]; double[] thisYLine = new double[map.GetLength(1)]; double[] thisValLine = new double[map.GetLength(1)]; for (int j = 0; j < map.GetLength(1); j++) { double[] actionVals = av.models[mapNum].models[0].value(new int[2] { i, j }, availableActions); thisXLine[j] = actionVals[2] - actionVals[0]; thisYLine[j] = actionVals[3] - actionVals[1]; thisValLine[j] = actionVals.Max(); } valWriter.WriteLine(string.Join(",", thisValLine)); } valWriter.Flush(); valWriter.Close(); } }
private void saveButton_Click(object sender, EventArgs e) { ContextSwitchValue <int[], int[]> mdl = (ContextSwitchValue <int[], int[]>)((Agent <int[], int[]>)agent)._actionValue; IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("savedModel.mdl", FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, mdl); stream.Close(); }