Inheritance: ReadTags
 /// <summary>
 /// Load an object from XML.
 /// </summary>
 /// <param name="xmlIn">The XML reader.</param>
 /// <param name="target">The object to load.</param>
 public void Load(ReadXML xmlIn, IEncogPersistedObject target)
 {
     this.xmlIn = xmlIn;
     this.mapper.Clear();
     target.Name = xmlIn.LastTag.GetAttributeValue("name");
     target.Description = xmlIn.LastTag.GetAttributeValue("description");
     LoadActualObject(null, target);
     this.mapper.Resolve();
 }
        /// <summary>
        /// Handle an item.
        /// </summary>
        /// <param name="xmlin">The XML input object.</param>
        public void HandleItem(ReadXML xmlin)
        {
            String name = xmlin.LastTag.GetAttributeValue(
                   TrainingContinuationPersistor.ATTRIBUTE_NAME);
            String str = xmlin.ReadTextToTag();
            double[] list = NumberList.FromList(CSVFormat.EG_FORMAT, str);
            this.current[name] = list;

        }
        /// <summary>
        /// Load from the specified node.
        /// </summary>
        /// <param name="xmlIn">The node to load from.</param>
        /// <returns>The EncogPersistedObject that was loaded.</returns>
        public IEncogPersistedObject Load(ReadXML xmlIn)
        {
            IEncogPersistedObject current;

            String c = ReflectionUtil.ResolveEncogClass(clazz.Name);
            current = (IEncogPersistedObject)Assembly.GetExecutingAssembly().CreateInstance(c);
            XML2Object conv = new XML2Object();
            conv.Load(xmlIn, current);
            return current;
        }
 /// <summary>
 /// Load the specified Encog object from an XML reader.
 /// </summary>
 /// <param name="xmlin">The XML reader to use.</param>
 /// <returns>The loaded object.</returns>
 public IEncogPersistedObject Load(ReadXML xmlin)
 {
     String name = xmlin.LastTag.GetAttributeValue("name");
     String description = xmlin.LastTag.GetAttributeValue("description");
     TextData result = new TextData();
     xmlin.ReadToTag();
     String text = xmlin.LastTag.Name;
     result.Name = name;
     result.Description = description;
     result.Text = text;
     xmlin.ReadToTag();
     return result;
 }
Example #5
0
 public void TestRead()
 {
     var enc = new ASCIIEncoding();
     var bis = new MemoryStream(enc.GetBytes(XML));
     var read = new ReadXML(bis);
     Assert.AreEqual(0, read.Read());
     Assert.IsTrue(read.IsIt("doc", true));
     Assert.AreEqual(0, read.Read());
     Assert.IsTrue(read.IsIt("a", true));
     Assert.AreEqual('a', read.Read());
     Assert.AreEqual(0, read.Read());
     Assert.IsTrue(read.IsIt("a", false));
     bis.Close();
 }
 /// <summary>
 /// Handle loading the items.
 /// </summary>
 /// <param name="xmlin">The XML input object.</param>
 public void HandleItems(ReadXML xmlin)
 {
     while (xmlin.ReadToTag())
     {
         if (xmlin.IsIt(TrainingContinuationPersistor.TAG_ITEM, true))
         {
             HandleItem(xmlin);
         }
         else if (xmlin.IsIt(TrainingContinuationPersistor.TAG_ITEM, false))
         {
             break;
         }
     }
 }
        /// <summary>
        /// Handle the properties tag.
        /// </summary>
        /// <param name="xmlin">The XML reader.</param>
        private void HandleProperties(ReadXML xmlin)
        {
            while (xmlin.ReadToTag())
            {
                if (xmlin.IsIt(PropertyDataPersistor.TAG_PROPERTY, true))
                {
                    HandleProperty(xmlin);
                }
                else if (xmlin.IsIt(PropertyDataPersistor.TAG_PROPERTIES, false))
                {
                    break;
                }

            }

        }
        /// <summary>
        /// Load a RBF layer. 
        /// </summary>
        /// <param name="xmlin">The XML to read from.</param>
        /// <returns>The object that was loaded.</returns>
        public IEncogPersistedObject Load(ReadXML xmlin)
        {
            int neuronCount = 0;
            int x = 0;
            int y = 0;
            int dimensions = 1;
            IRadialBasisFunction[] rbfs = new IRadialBasisFunction[0];

            String end = xmlin.LastTag.Name;

            while (xmlin.ReadToTag())
            {
                if (xmlin.IsIt(BasicLayerPersistor.PROPERTY_NEURONS, true))
                {
                    neuronCount = xmlin.ReadIntToTag();
                }
                else if (xmlin.IsIt(BasicLayerPersistor.PROPERTY_X, true))
                {
                    x = xmlin.ReadIntToTag();
                }
                else if (xmlin.IsIt(BasicLayerPersistor.PROPERTY_Y, true))
                {
                    y = xmlin.ReadIntToTag();
                }
                else if (xmlin.IsIt(RadialBasisFunctionLayerPersistor.PROPERTY_RBF,
                      true))
                {
                    rbfs = LoadAllRBF(xmlin);
                }
                else if (xmlin.IsIt(end, false))
                {
                    break;
                }
            }

            RadialBasisFunctionLayer layer = new RadialBasisFunctionLayer(neuronCount);
            layer.RadialBasisFunction = rbfs;
            layer.X = x;
            layer.Y = y;

            return layer;
        }
        /// <summary>
        /// Load the specified Encog object from an XML reader.
        /// </summary>
        /// <param name="xmlIn">The XML reader to use.</param>
        /// <returns>The loaded object.</returns>
        public IEncogPersistedObject Load(ReadXML xmlIn)
        {
            WeightedSynapse synapse = new WeightedSynapse();

            String end = xmlIn.LastTag.Name;

            while (xmlIn.ReadToTag())
            {

                if (xmlIn.IsIt(WeightedSynapsePersistor.TAG_WEIGHTS, true))
                {
                    xmlIn.ReadToTag();
                    synapse.WeightMatrix = PersistorUtil.LoadMatrix(xmlIn);
                }
                if (xmlIn.IsIt(end, false))
                {
                    break;
                }
            }

            return synapse;
        }
        /// <summary>
        /// Handle reading an item tag.
        /// </summary>
        /// <param name="xmlIn">The XML reader.</param>
        private void HandleItem(ReadXML xmlIn)
        {
            IDictionary<String, String> properties = xmlIn.ReadPropertyBlock();
            INeuralDataPair pair = null;
            INeuralData input = new BasicNeuralData(NumberList
                   .FromList(CSVFormat.EG_FORMAT, properties
                           [BasicNeuralDataSetPersistor.TAG_INPUT]));

            if (properties.ContainsKey(BasicNeuralDataSetPersistor.TAG_IDEAL))
            {
                // supervised
                INeuralData ideal = new BasicNeuralData(NumberList
                       .FromList(CSVFormat.EG_FORMAT, properties
                               [BasicNeuralDataSetPersistor.TAG_IDEAL]));
                pair = new BasicNeuralDataPair(input, ideal);
            }
            else
            {
                // unsupervised
                pair = new BasicNeuralDataPair(input);
            }

            this.currentDataSet.Add(pair);
        }
        private void HandleTags(ReadXML inXML)
        {
            String end = inXML.LastTag.Name;
            while (inXML.ReadToTag())
            {
                if (inXML.IsIt(BasicNetworkPersistor.TAG_TAG, true))
                {
                    String name = inXML.LastTag.GetAttributeValue(
                            BasicNetworkPersistor.ATTRIBUTE_NAME);

                    String layerStr = inXML.LastTag.GetAttributeValue(
                           BasicNetworkPersistor.ATTRIBUTE_LAYER);

                    int layerInt = int.Parse(layerStr);

                    ILayer layer = this.index2layer[layerInt];
                    this.currentNetwork.TagLayer(name, layer);
                    inXML.ReadToTag();
                }
                if (inXML.IsIt(end, false))
                {
                    break;
                }
            }

        }
        /// <summary>
        /// Load the properties.
        /// </summary>
        /// <param name="xmlIn">The XML object.</param>
        private void HandleProperties(ReadXML xmlIn)
        {
            String end = xmlIn.LastTag.Name;
            while (xmlIn.ReadToTag())
            {
                if (xmlIn.IsIt(BasicNetworkPersistor.TAG_PROPERTY, true))
                {
                    String name = xmlIn.LastTag.GetAttributeValue(
                            BasicNetworkPersistor.ATTRIBUTE_NAME);

                    String value = xmlIn.ReadTextToTag();
                    this.currentNetwork.SetProperty(name, value);
                }
                if (xmlIn.IsIt(end, false))
                {
                    break;
                }
            }

        }
 /// <summary>
 /// Load the neural logic object.
 /// </summary>
 /// <param name="xmlIn">The XML object.</param>
 private void HandleLogic(ReadXML xmlIn)
 {
     String value = xmlIn.ReadTextToTag();
     if (value.Equals("ART1Logic"))
     {
         this.currentNetwork.Logic = new ART1Logic();
     }
     else if (value.Equals("BAMLogic"))
     {
         this.currentNetwork.Logic = new BAMLogic();
     }
     else if (value.Equals("BoltzmannLogic"))
     {
         this.currentNetwork.Logic = new BoltzmannLogic();
     }
     else if (value.Equals("FeedforwardLogic"))
     {
         this.currentNetwork.Logic = new FeedforwardLogic();
     }
     else if (value.Equals("HopfieldLogic"))
     {
         this.currentNetwork.Logic = new HopfieldLogic();
     }
     else if (value.Equals("SimpleRecurrentLogic"))
     {
         this.currentNetwork.Logic = new SimpleRecurrentLogic();
     }
     else
     {
         INeuralLogic logic = (INeuralLogic)Assembly.GetExecutingAssembly().CreateInstance(value);
         this.currentNetwork.Logic = logic;
     }
 }
        /// <summary>
        /// Load the specified Encog object from an XML reader.
        /// </summary>
        /// <param name="xmlIn">The XML reader to use.</param>
        /// <returns>The loaded object.</returns>
        public IEncogPersistedObject Load(ReadXML xmlIn)
        {

            String name = xmlIn.LastTag.Attributes[EncogPersistedCollection.ATTRIBUTE_NAME];
            String description = xmlIn.LastTag.Attributes[
                   EncogPersistedCollection.ATTRIBUTE_DESCRIPTION];

            this.currentNetwork = new BasicNetwork();
            this.currentNetwork.Name = name;
            this.currentNetwork.Description = description;

            while (xmlIn.ReadToTag())
            {
                if (xmlIn.IsIt(BasicNetworkPersistor.TAG_LAYERS, true))
                {
                    HandleLayers(xmlIn);
                }
                else if (xmlIn.IsIt(BasicNetworkPersistor.TAG_SYNAPSES, true))
                {
                    HandleSynapses(xmlIn);
                }
                else if (xmlIn.IsIt(BasicNetworkPersistor.TAG_PROPERTIES, true))
                {
                    HandleProperties(xmlIn);
                }
                else if (xmlIn.IsIt(BasicNetworkPersistor.TAG_LOGIC, true))
                {
                    HandleLogic(xmlIn);
                }
                else if (xmlIn.IsIt(BasicNetworkPersistor.TAG_TAGS, true))
                {
                    HandleTags(xmlIn);
                }
                else if (xmlIn.IsIt(EncogPersistedCollection.TYPE_BASIC_NET, false))
                {
                    break;
                }

            }
            this.currentNetwork.Structure.FinalizeStructure();
            return this.currentNetwork;
        }
Example #15
0
    /// <summary>
    /// Perform a deep copy.
    /// Silverlight version.
    /// </summary>
    /// <param name="oldObj">The old object.</param>
    /// <returns>The new object.</returns>
        static public IEncogPersistedObject DeepCopy(IEncogPersistedObject oldObj)
        {
            bool replacedName = false;

            // encog objects won't save without a name
            if (oldObj.Name == null)
            {
                replacedName = true;
                oldObj.Name = "temp";
            }

            // now make the copy
            MemoryStream mstream = new MemoryStream();
            WriteXML xmlOut = new WriteXML(mstream);
            IPersistor persistor = oldObj.CreatePersistor();
            xmlOut.BeginDocument();
            persistor.Save(oldObj, xmlOut);
            xmlOut.EndDocument();
            // now read it back
            mstream.Position = 0;
            ReadXML xmlIn = new ReadXML(mstream);
            xmlIn.ReadToTag();
            IEncogPersistedObject result = persistor.Load(xmlIn);
            mstream.Close();

            // put the name back to null if we changed it
            if (replacedName)
            {
                oldObj.Name = null;
                result.Name = null;
            }
            return result;        }
        /// <summary>
        /// Load the specified Encog object from an XML reader.
        /// </summary>
        /// <param name="xmlIn">The XML reader to use.</param>
        /// <returns>The loaded object.</returns>
        public IEncogPersistedObject Load(ReadXML xmlIn)
        {

            OneToOneSynapse synapse = new OneToOneSynapse();
            return synapse;
        }
Example #17
0
        /// <summary>
        /// Handle the cloud response. 
        /// </summary>
        /// <param name="contents">The contents.</param>
        private void HandleResponse(String contents)
        {
            byte[] bin = System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(contents);
            MemoryStream istream = new MemoryStream(bin);
            ReadXML xml = new ReadXML(istream);
            int ch;

            while ((ch = xml.Read()) != -1)
            {
                if (ch == 0)
                {
                    if (xml.LastTag.Name.Equals("EncogCloud"))
                    {
                        ProcessCloud(xml);
                    }
                }
            }

            if ((Status == null) || Status.Equals("failed"))
            {
                throw new EncogCloudError(Message);
            }
        }
 /// <summary>
 /// Handle a model. 
 /// </summary>
 /// <param name="xmlin">Where to read the model from.</param>
 /// <param name="model">Where to load the model into.</param>
 private void HandleModel(ReadXML xmlin, svm_model model)
 {
     while (xmlin.ReadToTag())
     {
         if (xmlin.IsIt(SVMNetworkPersistor.TAG_TYPE_SVM, true))
         {
             int i = EngineArray.FindStringInArray(
                     SVMNetworkPersistor.svm_type_table, xmlin.ReadTextToTag());
             model.param.svm_type = i;
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_DEGREE, true))
         {
             model.param.degree = int.Parse(xmlin.ReadTextToTag());
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_GAMMA, true))
         {
             model.param.gamma = double.Parse(xmlin.ReadTextToTag());
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_COEF0, true))
         {
             model.param.coef0 = double.Parse(xmlin.ReadTextToTag());
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_NUMCLASS, true))
         {
             model.nr_class = int.Parse(xmlin.ReadTextToTag());
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_TOTALSV, true))
         {
             model.l = int.Parse(xmlin.ReadTextToTag());
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_RHO, true))
         {
             int n = model.nr_class * (model.nr_class - 1) / 2;
             model.rho = new double[n];
             String[] st = xmlin.ReadTextToTag().Split(',');
             for (int i = 0; i < n; i++)
                 model.rho[i] = double.Parse(st[i]);
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_LABEL, true))
         {
             int n = model.nr_class;
             model.label = new int[n];
             String[] st = xmlin.ReadTextToTag().Split(',');
             for (int i = 0; i < n; i++)
                 model.label[i] = int.Parse(st[i]);
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_PROB_A, true))
         {
             int n = model.nr_class * (model.nr_class - 1) / 2;
             model.probA = new double[n];
             String[] st = xmlin.ReadTextToTag().Split(',');
             for (int i = 0; i < n; i++)
                 model.probA[i] = Double.Parse(st[i]);
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_PROB_B, true))
         {
             int n = model.nr_class * (model.nr_class - 1) / 2;
             model.probB = new double[n];
             String[] st = xmlin.ReadTextToTag().Split(',');
             for (int i = 0; i < n; i++)
                 model.probB[i] = Double.Parse(st[i]);
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_NSV, true))
         {
             int n = model.nr_class;
             model.nSV = new int[n];
             String[] st = xmlin.ReadTextToTag().Split(',');
             for (int i = 0; i < n; i++)
                 model.nSV[i] = int.Parse(st[i]);
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_TYPE_KERNEL, true))
         {
             int i = EngineArray.FindStringInArray(
                     SVMNetworkPersistor.kernel_type_table, xmlin
                             .ReadTextToTag());
             model.param.kernel_type = i;
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_DATA, true))
         {
             HandleData(xmlin, model);
         }
         else if (xmlin.IsIt(SVMNetworkPersistor.TAG_MODEL, false))
         {
             break;
         }
     }
 }
Example #19
0
        /// <summary>
        /// Process the cloud request. 
        /// </summary>
        /// <param name="xml">The XML to parse.</param>
        private void ProcessCloud(ReadXML xml)
        {
            int ch;

            while ((ch = xml.Read()) != -1)
            {
                if (ch == 0)
                {
                    if (xml.LastTag.Name.Equals("Header"))
                    {
                        this.headerProperties = xml.ReadPropertyBlock();
                    }
                    else if (xml.LastTag.Name.Equals("Session"))
                    {
                        this.sessionProperties = xml.ReadPropertyBlock();
                    }
                    else if (xml.LastTag.Name.Equals("Response"))
                    {
                        this.responseProperties = xml.ReadPropertyBlock();
                    }
                }
            }
        }
        /// <summary>
        /// Load the SVM network. 
        /// </summary>
        /// <param name="xmlin">Where to read it from.</param>
        /// <returns>The loaded object.</returns>
        public IEncogPersistedObject Load(ReadXML xmlin)
        {
            SVMNetwork result = null;
            int input = -1, output = -1;

            String name = xmlin.LastTag.Attributes[
                    EncogPersistedCollection.ATTRIBUTE_NAME];
            String description = xmlin.LastTag.Attributes[
                    EncogPersistedCollection.ATTRIBUTE_DESCRIPTION];

            while (xmlin.ReadToTag())
            {
                if (xmlin.IsIt(SVMNetworkPersistor.TAG_INPUT, true))
                {
                    input = int.Parse(xmlin.ReadTextToTag());
                }
                else if (xmlin.IsIt(SVMNetworkPersistor.TAG_OUTPUT, true))
                {
                    output = int.Parse(xmlin.ReadTextToTag());
                }
                else if (xmlin.IsIt(SVMNetworkPersistor.TAG_MODELS, true))
                {
                    result = new SVMNetwork(input, output, false);
                    HandleModels(xmlin, result);
                }
                else if (xmlin.IsIt(EncogPersistedCollection.TYPE_SVM, false))
                {
                    break;
                }
            }

            result.Name = name;
            result.Description = description;
            return result;
        }
 /// <summary>
 /// Load the specified Encog object from an XML reader.
 /// </summary>
 /// <param name="xmlIn">The XML reader to use.</param>
 /// <returns>The loaded object.</returns>
 public IEncogPersistedObject Load(ReadXML xmlIn)
 {
     DirectSynapse synapse = new DirectSynapse();
     return synapse;
 }
        /// <summary>
        /// Load the specified Encog object from an XML reader.
        /// </summary>
        /// <param name="xmlIn">The XML reader to use.</param>
        /// <returns>The loaded object.</returns>
        public IEncogPersistedObject Load(ReadXML xmlIn)
        {

            String name = xmlIn.LastTag.Attributes[
                   EncogPersistedCollection.ATTRIBUTE_NAME];
            String description = xmlIn.LastTag.GetAttributeValue(
                   EncogPersistedCollection.ATTRIBUTE_DESCRIPTION);

            this.currentDataSet = new BasicNeuralDataSet();
            this.currentDataSet.Name = name;
            this.currentDataSet.Description = description;

            while (xmlIn.ReadToTag())
            {
                if (xmlIn.IsIt(BasicNeuralDataSetPersistor.TAG_ITEM, true))
                {
                    HandleItem(xmlIn);
                }
                else if (xmlIn.IsIt(EncogPersistedCollection.TYPE_TRAINING, false))
                {
                    break;
                }

            }

            return this.currentDataSet;
        }
        /// <summary>
        /// Load a matrix from the reader.
        /// </summary>
        /// <param name="xmlIn">The XML reader.</param>
        /// <returns>The loaded matrix.</returns>
        public static Matrix LoadMatrix(ReadXML xmlIn)
        {
            int rows = xmlIn.LastTag.GetAttributeInt(
                   PersistorUtil.ATTRIBUTE_MATRIX_ROWS);
            int cols = xmlIn.LastTag.GetAttributeInt(
                   PersistorUtil.ATTRIBUTE_MATRIX_COLS);
            Matrix matrix = new Matrix(rows, cols);

            int row = 0;

            String end = xmlIn.LastTag.Name;
            while (xmlIn.ReadToTag())
            {
                if (xmlIn.IsIt(end, false))
                {
                    break;
                }
                if (xmlIn.IsIt(PersistorUtil.ROW, true))
                {
                    String str = xmlIn.ReadTextToTag();
                    double[] d = NumberList.FromList(CSVFormat.EG_FORMAT, str);
                    for (int col = 0; col < d.Length; col++)
                    {
                        matrix[row, col] = d[col];
                    }
                    row++;
                }
            }

            return matrix;
        }
        /// <summary>
        /// Load the data from a model.
        /// </summary>
        /// <param name="xmlin">Where to read the data from.</param>
        /// <param name="model">The model to load data into.</param>
        private void HandleData(ReadXML xmlin, svm_model model)
        {
            int i = 0;
            int m = model.nr_class - 1;
            int l = model.l;

            model.sv_coef = EngineArray.AllocateDouble2D(m, l);
            model.SV = new svm_node[l][];

            while (xmlin.ReadToTag())
            {
                if (xmlin.IsIt(SVMNetworkPersistor.TAG_ROW, true))
                {
                    String line = xmlin.ReadTextToTag();

                    String[] st = xmlin.ReadTextToTag().Split(',');

                    for (int k = 0; k < m; k++)
                        model.sv_coef[k][i] = Double.Parse(st[i]);
                    int n = st.Length / 2;
                    model.SV[i] = new svm_node[n];
                    int idx = 0;
                    for (int j = 0; j < n; j++)
                    {
                        model.SV[i][j] = new svm_node();
                        model.SV[i][j].index = int.Parse(st[idx++]);
                        model.SV[i][j].value_Renamed = Double.Parse(st[idx++]);
                    }
                    i++;
                }
                else if (xmlin.IsIt(SVMNetworkPersistor.TAG_DATA, false))
                {
                    break;
                }
            }
        }
        /// <summary>
        /// Load the specified Encog object from an XML reader.
        /// </summary>
        /// <param name="xmlIn">The XML reader to use.</param>
        /// <returns>The loaded object.</returns>
        public IEncogPersistedObject Load(ReadXML xmlIn)
        {
            int neuronCount = 0;
            int x = 0;
            int y = 0;
            double biasActivation = 1;
            String threshold = null;
            IActivationFunction activation = null;
            String end = xmlIn.LastTag.Name;
            String context = null;

            while (xmlIn.ReadToTag())
            {
                if (xmlIn.IsIt(BasicLayerPersistor.TAG_ACTIVATION, true))
                {
                    xmlIn.ReadToTag();
                    String type = xmlIn.LastTag.Name;
                    activation = BasicLayerPersistor.LoadActivation(type, xmlIn);
                }
                else if (xmlIn.IsIt(BasicLayerPersistor.PROPERTY_NEURONS, true))
                {
                    neuronCount = xmlIn.ReadIntToTag();
                }
                else if (xmlIn.IsIt(BasicLayerPersistor.PROPERTY_X, true))
                {
                    x = xmlIn.ReadIntToTag();
                }
                else if (xmlIn.IsIt(BasicLayerPersistor.PROPERTY_Y, true))
                {
                    y = xmlIn.ReadIntToTag();
                }
                else if (xmlIn.IsIt(BasicLayerPersistor.PROPERTY_THRESHOLD, true))
                {
                    threshold = xmlIn.ReadTextToTag();
                }
                else if (xmlIn.IsIt(PROPERTY_CONTEXT, true))
                {
                    context = xmlIn.ReadTextToTag();
                }
                else if (xmlIn.IsIt(BasicLayerPersistor.PROPERTY_BIAS_ACTIVATION, true))
                {
                    biasActivation = double.Parse(xmlIn.ReadTextToTag());
                }
                else if (xmlIn.IsIt(end, false))
                {
                    break;
                }
            }

            if (neuronCount > 0)
            {
                ContextLayer layer;

                if (threshold == null)
                {
                    layer = new ContextLayer(activation, false, neuronCount);
                }
                else
                {
                    double[] t = NumberList.FromList(CSVFormat.EG_FORMAT, threshold);
                    layer = new ContextLayer(activation, true, neuronCount);
                    for (int i = 0; i < t.Length; i++)
                    {
                        layer.BiasWeights[i] = t[i];
                    }
                }

                if (context != null)
                {
                    double[] c = NumberList.FromList(CSVFormat.EG_FORMAT, context);

                    for (int i = 0; i < c.Length; i++)
                    {
                        layer.Context[i] = c[i];
                    }
                }

                layer.X = x;
                layer.Y = y;
                layer.BiasActivation = biasActivation;

                return layer;
            }
            return null;
        }
        /// <summary>
        /// Handle any layers that should be loaded.
        /// </summary>
        /// <param name="xmlIn">The XML reader.</param>
        private void HandleLayers(ReadXML xmlIn)
        {
            String end = xmlIn.LastTag.Name;
            while (xmlIn.ReadToTag())
            {
                if (xmlIn.IsIt(BasicNetworkPersistor.TAG_LAYER, true))
                {
                    int num = xmlIn.LastTag.GetAttributeInt(
                           BasicNetworkPersistor.ATTRIBUTE_ID);
                    String type = xmlIn.LastTag.GetAttributeValue(
                           BasicNetworkPersistor.ATTRIBUTE_TYPE);
                    xmlIn.ReadToTag();
                    IPersistor persistor = PersistorUtil.CreatePersistor(xmlIn
                           .LastTag.Name);
                    ILayer layer = (ILayer)persistor.Load(xmlIn);
                    this.index2layer[num] = layer;

                    // the type attribute is actually "legacy", but if its there
                    // then use it!
                    if (type != null)
                    {
                        if (type.Equals(BasicNetworkPersistor.ATTRIBUTE_TYPE_INPUT))
                        {
                            this.currentNetwork.TagLayer(BasicNetwork.TAG_INPUT,
                                    layer);
                        }
                        else if (type
                                .Equals(BasicNetworkPersistor.ATTRIBUTE_TYPE_OUTPUT))
                        {
                            this.currentNetwork.TagLayer(BasicNetwork.TAG_OUTPUT,
                                    layer);
                        }
                        else if (type
                              .Equals(BasicNetworkPersistor.ATTRIBUTE_TYPE_BOTH))
                        {
                            this.currentNetwork.TagLayer(BasicNetwork.TAG_INPUT,
                                    layer);
                            this.currentNetwork.TagLayer(BasicNetwork.TAG_OUTPUT,
                                    layer);
                        }
                    }
                    // end of legacy processing
                }
                if (xmlIn.IsIt(end, false))
                {
                    break;
                }
            }
        }
        /// <summary>
        /// Load the object.
        /// </summary>
        /// <param name="xmlin">The XML object to load from.</param>
        /// <returns>The loaded object.</returns>
        public IEncogPersistedObject Load(ReadXML xmlin)
        {
            this.current = new TrainingContinuation();

            String name = xmlin.LastTag.Attributes[
                    EncogPersistedCollection.ATTRIBUTE_NAME];
            String description = xmlin.LastTag.Attributes[
                    EncogPersistedCollection.ATTRIBUTE_DESCRIPTION];

            this.current.Name = name;
            this.current.Description = description;

            while (xmlin.ReadToTag())
            {
                if (xmlin.IsIt(TrainingContinuationPersistor.TAG_ITEMS, true))
                {
                    HandleItems(xmlin);
                }
                else if (xmlin.IsIt(
                    EncogPersistedCollection.TYPE_TRAINING_CONTINUATION, false))
                {
                    break;
                }
            }

            return this.current;
        }
 /// <summary>
 /// Process any synapses that should be loaded.
 /// </summary>
 /// <param name="xmlIn">The XML reader.</param>
 private void HandleSynapses(ReadXML xmlIn)
 {
     String end = xmlIn.LastTag.Name;
     while (xmlIn.ReadToTag())
     {
         if (xmlIn.IsIt(BasicNetworkPersistor.TAG_SYNAPSE, true))
         {
             int from = xmlIn.LastTag.GetAttributeInt(
                    BasicNetworkPersistor.ATTRIBUTE_FROM);
             int to = xmlIn.LastTag.GetAttributeInt(
                    BasicNetworkPersistor.ATTRIBUTE_TO);
             xmlIn.ReadToTag();
             IPersistor persistor = PersistorUtil.CreatePersistor(xmlIn
                    .LastTag.Name);
             ISynapse synapse = (ISynapse)persistor.Load(xmlIn);
             synapse.FromLayer = this.index2layer[from];
             synapse.ToLayer = this.index2layer[to];
             synapse.FromLayer.AddSynapse(synapse);
         }
         if (xmlIn.IsIt(end, false))
         {
             break;
         }
     }
 }
        /// <summary>
        /// Load the models. 
        /// </summary>
        /// <param name="xmlin">Where to read the models from.</param>
        /// <param name="network">Where the models are read into.</param>
        private void HandleModels(ReadXML xmlin, SVMNetwork network)
        {

            int index = 0;
            while (xmlin.ReadToTag())
            {
                if (xmlin.IsIt(SVMNetworkPersistor.TAG_MODEL, true))
                {
                    svm_parameter param = new svm_parameter();
                    svm_model model = new svm_model();
                    model.param = param;
                    network.Models[index] = model;
                    HandleModel(xmlin, network.Models[index]);
                    index++;
                }
                else if (xmlin.IsIt(SVMNetworkPersistor.TAG_MODELS, false))
                {
                    break;
                }
            }

        }
        /// <summary>
        /// Load the specified activation function.
        /// </summary>
        /// <param name="type">The type of activation function.</param>
        /// <param name="xmlIn">The XML.</param>
        /// <returns>The activation function.</returns>
        public static IActivationFunction LoadActivation(String type, ReadXML xmlIn)
        {

            try
            {
                String clazz = ReflectionUtil.ResolveEncogClass(type);

                if (clazz == null)
                {
                    throw new NeuralNetworkError("Unknown activation function: " + type);
                }

                IActivationFunction result = (IActivationFunction)ReflectionUtil.LoadObject(clazz);

                foreach (String key in xmlIn.LastTag.Attributes.Keys)
                {
                    int index = -1;

                    for (int i = 0; i < result.ParamNames.Length; i++)
                    {
                        if ( key.ToUpper().Equals(result.ParamNames[i].ToUpper()) )
                        {
                            index = i;
                            break;
                        }

                        if (index != -1)
                        {
                            String str = xmlIn.LastTag.GetAttributeValue(key);
                            double d = CSVFormat.EG_FORMAT.Parse(str);
                            result.SetParam(index, d);
                        }
                    }
                }

                return result;
            }
            catch (Exception e)
            {
                throw new EncogError(e);
            }
        }