/// <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 synapses to the specified XML writer. /// </summary> /// <param name="xmlOut">The XML writer.</param> private void SaveSynapses(WriteXML xmlOut) { foreach (ISynapse synapse in this.currentNetwork.Structure.Synapses) { xmlOut.AddAttribute(BasicNetworkPersistor.ATTRIBUTE_FROM, "" + this.layer2index[synapse.FromLayer]); xmlOut.AddAttribute(BasicNetworkPersistor.ATTRIBUTE_TO, "" + this.layer2index[synapse.ToLayer]); xmlOut.BeginTag(BasicNetworkPersistor.TAG_SYNAPSE); IPersistor persistor = synapse.CreatePersistor(); persistor.Save(synapse, xmlOut); xmlOut.EndTag(); } }
private void SaveTags(WriteXML outXML) { // save any properties outXML.BeginTag(BasicNetworkPersistor.TAG_TAGS); foreach (String key in this.currentNetwork.LayerTags.Keys) { ILayer value = this.currentNetwork.LayerTags[key]; outXML.AddAttribute(BasicNetworkPersistor.ATTRIBUTE_NAME, key); outXML.AddAttribute(BasicNetworkPersistor.ATTRIBUTE_LAYER, "" + layer2index[value]); outXML.BeginTag(BasicNetworkPersistor.TAG_TAG); outXML.EndTag(); } outXML.EndTag(); }
/// <summary> /// Save the specified Encog object to an XML writer. /// </summary> /// <param name="obj">The object to save.</param> /// <param name="xmlout">The XML writer to save to.</param> public void Save(IEncogPersistedObject obj, WriteXML xmlout) { PropertyData pData = (PropertyData)obj; PersistorUtil.BeginEncogObject(EncogPersistedCollection.TYPE_PROPERTY, xmlout, obj, true); xmlout.BeginTag(PropertyDataPersistor.TAG_PROPERTIES); foreach (String key in pData.Data.Keys) { xmlout.AddAttribute(PropertyDataPersistor.ATTRIBUTE_NAME, key); xmlout.AddAttribute(PropertyDataPersistor.ATTRIBUTE_VALUE, pData [key]); xmlout.BeginTag(PropertyDataPersistor.TAG_PROPERTY); xmlout.EndTag(); } xmlout.EndTag(); xmlout.EndTag(); }
/// <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> /// Copy all of the attributes to the writer. /// </summary> /// <param name="xmlOut">The XML writer.</param> /// <param name="replace">A map of attributes to replace. This allows /// new values to be specified for select attributes.</param> private void CopyAttributes(WriteXML xmlOut, IDictionary <String, String> replace) { foreach (String key in this.xmlIn.LastTag.Attributes.Keys) { String value = this.xmlIn.LastTag.GetAttributeValue(key); if ((replace != null) && replace.ContainsKey(key)) { value = replace[key]; } xmlOut.AddAttribute(key, value); } }
/// <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> /// Write the beginning XML for an Encog object. /// </summary> /// <param name="objectType">The object type to persist.</param> /// <param name="xmlOut">The object that is being persisted.</param> /// <param name="obj">The XML writer.</param> /// <param name="top">Is this a top-level object, that needs a name /// and description?</param> public static void BeginEncogObject(String objectType, WriteXML xmlOut, IEncogPersistedObject obj, bool top) { if (top) { if (obj.Name != null) { xmlOut.AddAttribute("name", obj.Name); } if (obj.Description != null) { xmlOut.AddAttribute("description", obj.Description); } else { xmlOut.AddAttribute("description", ""); } } xmlOut.AddAttribute("native", obj.GetType().Name); xmlOut.AddAttribute("id", "1"); xmlOut.BeginTag(objectType); }
/// <summary> /// Save the layers to the specified XML writer. /// </summary> /// <param name="xmlOut">The XML writer.</param> private void SaveLayers(WriteXML xmlOut) { int current = 1; foreach (ILayer layer in this.currentNetwork.Structure.Layers) { xmlOut.AddAttribute(BasicNetworkPersistor.ATTRIBUTE_ID, "" + current); xmlOut.BeginTag(BasicNetworkPersistor.TAG_LAYER); IPersistor persistor = layer.CreatePersistor(); persistor.Save(layer, xmlOut); xmlOut.EndTag(); this.layer2index[layer] = current; current++; } }
/// <summary> /// Save the activation function. /// </summary> /// <param name="activationFunction">The activation function.</param> /// <param name="xmlOut">The XML.</param> public static void SaveActivationFunction( IActivationFunction activationFunction, WriteXML xmlOut) { if (activationFunction != null) { xmlOut.BeginTag(BasicLayerPersistor.TAG_ACTIVATION); xmlOut.BeginTag(activationFunction.GetType().Name); String[] names = activationFunction.ParamNames; for (int i = 0; i < names.Length; i++) { String str = names[i]; double d = activationFunction.Params[i]; xmlOut.AddAttribute(str, "" + CSVFormat.EG_FORMAT.Format(d, 10)); } xmlOut.EndTag(); xmlOut.EndTag(); } }