/// <summary> /// Save items. /// </summary> /// <param name="xmlout">The XML output object.</param> public void SaveItems(WriteXML xmlout) { foreach (String key in this.current.Contents.Keys) { xmlout.AddAttribute(TrainingContinuationPersistor.ATTRIBUTE_NAME, key); xmlout.BeginTag(TrainingContinuationPersistor.TAG_ITEM); double[] value = (double[])this.current[key]; StringBuilder result = new StringBuilder(); NumberList.ToList(CSVFormat.EG_FORMAT, result, value); xmlout.AddText(result.ToString()); xmlout.EndTag(); } }
/// <summary> /// Save the specified matrix. /// </summary> /// <param name="matrix">The matrix to save.</param> /// <param name="xmlOut">The XML writer.</param> public static void SaveMatrix(Matrix matrix, WriteXML xmlOut) { xmlOut.AddAttribute(PersistorUtil.ATTRIBUTE_MATRIX_ROWS, "" + matrix.Rows); xmlOut.AddAttribute(PersistorUtil.ATTRIBUTE_MATRIX_COLS, "" + matrix.Cols); xmlOut.BeginTag("Matrix"); CSVFormat format = CSVFormat.EG_FORMAT; for (int row = 0; row < matrix.Rows; row++) { StringBuilder builder = new StringBuilder(); for (int col = 0; col < matrix.Cols; col++) { if (col > 0) { builder.Append(','); } double d = matrix[row, col]; builder.Append(format.Format(d, 20)); } xmlOut.BeginTag(PersistorUtil.ROW); xmlOut.AddText(builder.ToString()); xmlOut.EndTag(); } xmlOut.EndTag(); }
/// <summary> /// Save the neural logic object. /// </summary> /// <param name="xmlOut">The XML object.</param> private void SaveLogic(WriteXML xmlOut) { xmlOut.BeginTag(BasicNetworkPersistor.TAG_LOGIC); INeuralLogic logic = this.currentNetwork.Logic; if (logic is FeedforwardLogic || logic is SimpleRecurrentLogic || logic is BoltzmannLogic || logic is ART1Logic || logic is BAMLogic || logic is HopfieldLogic) { xmlOut.AddText(logic.GetType().Name); } else xmlOut.AddText(logic.GetType().Name); xmlOut.EndTag(); }
/// <summary> /// Save the neural properties. /// </summary> /// <param name="xmlOut">The xml object.</param> private void SaveProperties(WriteXML xmlOut) { // save any properties xmlOut.BeginTag(BasicNetworkPersistor.TAG_PROPERTIES); foreach (String key in this.currentNetwork.Properties.Keys) { String value = this.currentNetwork.Properties[key]; xmlOut.AddAttribute(BasicNetworkPersistor.ATTRIBUTE_NAME, key); xmlOut.BeginTag(BasicNetworkPersistor.TAG_PROPERTY); xmlOut.AddText(value.ToString()); xmlOut.EndTag(); } xmlOut.EndTag(); }
/// <summary> /// Copy an XML object, no need to know what it contains, just /// copy it. This way we will not damage unknown objects during /// a merge. /// </summary> /// <param name="xmlOut">The XML writer.</param> /// <param name="replace"></param> private void CopyXML(WriteXML xmlOut, IDictionary<String, String> replace) { StringBuilder text = new StringBuilder(); int depth = 0; int ch; CopyAttributes(xmlOut, replace); String contain = this.xmlIn.LastTag.Name; xmlOut.BeginTag(contain); while ((ch = this.xmlIn.Read()) != -1) { Tag.Type type = this.xmlIn.LastTag.TagType; if (ch == 0) { if (type == Tag.Type.BEGIN) { if (text.Length > 0) { xmlOut.AddText(text.ToString()); text.Length = 0; } CopyAttributes(xmlOut, null); xmlOut.BeginTag(this.xmlIn.LastTag.Name); depth++; } else if (type == Tag.Type.END) { if (text.Length > 0) { xmlOut.AddText(text.ToString()); text.Length = 0; } if (depth == 0) { break; } else { xmlOut.EndTag(xmlIn.LastTag.Name); } depth--; } } else { text.Append((char)ch); } } xmlOut.EndTag(contain); }