Ejemplo n.º 1
0
        /// <summary>
        /// The generated network.
        /// </summary>
        /// <returns></returns>
        public BasicNetwork Generate()
        {
            BasicNetwork network = new BasicNetwork(new BAMLogic());

            ILayer f1Layer = new BasicLayer(new ActivationBiPolar(), false,
                                            F1Neurons);
            ILayer f2Layer = new BasicLayer(new ActivationBiPolar(), false,
                                            F2Neurons);
            ISynapse synapseInputToOutput = new WeightedSynapse(f1Layer,
                                                                f2Layer);
            ISynapse synapseOutputToInput = new WeightedSynapse(f2Layer,
                                                                f1Layer);

            f1Layer.AddSynapse(synapseInputToOutput);
            f2Layer.AddSynapse(synapseOutputToInput);

            network.TagLayer(BAMPattern.TAG_F1, f1Layer);
            network.TagLayer(BAMPattern.TAG_F2, f2Layer);

            network.Structure.FinalizeStructure();
            network.Structure.FinalizeStructure();

            f1Layer.Y = PatternConst.START_Y;
            f2Layer.Y = PatternConst.START_Y;

            f1Layer.X = PatternConst.START_X;
            f2Layer.X = PatternConst.INDENT_X;

            return(network);
        }
        /// <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)
        {
            PersistorUtil
            .BeginEncogObject(
                EncogPersistedCollection.TYPE_WEIGHTED_SYNAPSE, xmlOut,
                obj, false);
            WeightedSynapse synapse = (WeightedSynapse)obj;

            xmlOut.BeginTag(WeightedSynapsePersistor.TAG_WEIGHTS);
            PersistorUtil.SaveMatrix(synapse.WeightMatrix, xmlOut);
            xmlOut.EndTag();

            xmlOut.EndTag();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add a "next" layer.
        /// </summary>
        /// <param name="next">The next layer to add.</param>
        /// <param name="type">The synapse type to use for this layer.</param>
        public void AddNext(ILayer next, SynapseType type)
        {
            ISynapse synapse = null;

            switch (type)
            {
            case SynapseType.OneToOne:
                synapse = new OneToOneSynapse(this, next);
                break;

            case SynapseType.Weighted:
                synapse = new WeightedSynapse(this, next);
                break;

            case SynapseType.Weightless:
                synapse = new WeightlessSynapse(this, next);
                break;

            case SynapseType.Direct:
                synapse = new DirectSynapse(this, next);
                break;

            case SynapseType.NEAT:
                synapse = new NEATSynapse(this, next);
                break;

            default:
                throw new NeuralNetworkError("Unknown synapse type");
            }

            if (synapse == null)
            {
                String str = "Unknown synapse type.";
#if logging
                if (BasicLayer.logger.IsErrorEnabled)
                {
                    BasicLayer.logger.Error(str);
                }
#endif
                throw new NeuralNetworkError(str);
            }
            else
            {
                this.next.Add(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)
        {
            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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Generate the neural network.
        /// </summary>
        /// <returns>The generated neural network.</returns>
        public BasicNetwork Generate()
        {
            BasicNetwork network = new BasicNetwork(new ART1Logic());

            int y = PatternConst.START_Y;

            ILayer   layerF1       = new BasicLayer(new ActivationLinear(), false, this.InputNeurons);
            ILayer   layerF2       = new BasicLayer(new ActivationLinear(), false, this.OutputNeurons);
            ISynapse synapseF1toF2 = new WeightedSynapse(layerF1, layerF2);
            ISynapse synapseF2toF1 = new WeightedSynapse(layerF2, layerF1);

            layerF1.Next.Add(synapseF1toF2);
            layerF2.Next.Add(synapseF2toF1);

            // apply tags
            network.TagLayer(BasicNetwork.TAG_INPUT, layerF1);
            network.TagLayer(BasicNetwork.TAG_OUTPUT, layerF2);
            network.TagLayer(ART1Pattern.TAG_F1, layerF1);
            network.TagLayer(ART1Pattern.TAG_F2, layerF2);

            layerF1.X = PatternConst.START_X;
            layerF1.Y = y;
            y        += PatternConst.INC_Y;

            layerF2.X = PatternConst.START_X;
            layerF2.Y = y;

            network.SetProperty(ARTLogic.PROPERTY_A1, this.A1);
            network.SetProperty(ARTLogic.PROPERTY_B1, this.B1);
            network.SetProperty(ARTLogic.PROPERTY_C1, this.C1);
            network.SetProperty(ARTLogic.PROPERTY_D1, this.D1);
            network.SetProperty(ARTLogic.PROPERTY_L, this.L);
            network.SetProperty(ARTLogic.PROPERTY_VIGILANCE, this.Vigilance);

            network.Structure.FinalizeStructure();

            return(network);
        }