コード例 #1
0
ファイル: Outstar.cs プロジェクト: starhash/Neuroph.NET
        /// <summary>
        /// Creates Outstar architecture with specified number of neurons in
        /// output layer
        /// </summary>
        /// <param name="outputNeuronsCount">
        ///            number of neurons in output layer </param>
        private void createNetwork(int outputNeuronsCount)
        {
            // set network type
            this.NetworkType = NeuralNetworkType.OUTSTAR;

            // init neuron settings for this type of network
            NeuronProperties neuronProperties = new NeuronProperties();

            neuronProperties.setProperty("transferFunction", TransferFunctionType.Step.ToString());

            // create input layer
            Layer inputLayer = LayerFactory.createLayer(1, neuronProperties);

            this.addLayer(inputLayer);

            // createLayer output layer
            neuronProperties.setProperty("transferFunction", TransferFunctionType.Ramp.ToString());
            Layer outputLayer = LayerFactory.createLayer(outputNeuronsCount, neuronProperties);

            this.addLayer(outputLayer);

            // create full conectivity between input and output layer
            ConnectionFactory.fullConnect(inputLayer, outputLayer);

            // set input and output cells for this network
            NeuralNetworkFactory.DefaultIO = this;

            // set outstar learning rule for this network
            this.LearningRule = new OutstarLearning();
        }
コード例 #2
0
        /// <summary>
        /// Creates BAM network architecture
        /// </summary>
        /// <param name="inputNeuronsCount">
        ///            number of neurons in input layer </param>
        /// <param name="outputNeuronsCount">
        ///            number of neurons in output layer </param>
        /// <param name="neuronProperties">
        ///            neuron properties </param>
        private void createNetwork(int inputNeuronsCount, int outputNeuronsCount, NeuronProperties neuronProperties)
        {
            // set network type
            this.NetworkType = NeuralNetworkType.BAM;

            // create input layer
            Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, neuronProperties);

            // add input layer to network
            this.addLayer(inputLayer);

            // create output layer
            Layer outputLayer = LayerFactory.createLayer(outputNeuronsCount, neuronProperties);

            // add output layer to network
            this.addLayer(outputLayer);

            // create full connectivity from in to out layer
            ConnectionFactory.fullConnect(inputLayer, outputLayer);
            // create full connectivity from out to in layer
            ConnectionFactory.fullConnect(outputLayer, inputLayer);

            // set input and output cells for this network
            NeuralNetworkFactory.DefaultIO = this;

            // set Hebbian learning rule for this network
            this.LearningRule = new BinaryHebbianLearning();
        }
コード例 #3
0
        /// <summary>
        /// Creates an instance of Unsuervised Hebian net with specified number
        /// of neurons in input layer and output layer, and transfer function
        /// </summary>
        /// <param name="inputNeuronsNum">
        ///            number of neurons in input layer </param>
        /// <param name="outputNeuronsNum">
        ///            number of neurons in output layer </param>
        /// <param name="transferFunctionType">
        ///            transfer function type </param>
        private void createNetwork(int inputNeuronsNum, int outputNeuronsNum, TransferFunctionType transferFunctionType)
        {
            // init neuron properties
            NeuronProperties neuronProperties = new NeuronProperties();

            //		neuronProperties.setProperty("bias", new Double(-Math
            //				.abs(Math.random() - 0.5))); // Hebbian network cann not work
            // without bias
            neuronProperties.setProperty("transferFunction", transferFunctionType.ToString());
            neuronProperties.setProperty("transferFunction.slope", 1);

            // set network type code
            this.NetworkType = NeuralNetworkType.UNSUPERVISED_HEBBIAN_NET;

            // createLayer input layer
            Layer inputLayer = LayerFactory.createLayer(inputNeuronsNum, neuronProperties);

            this.addLayer(inputLayer);

            // createLayer output layer
            Layer outputLayer = LayerFactory.createLayer(outputNeuronsNum, neuronProperties);

            this.addLayer(outputLayer);

            // createLayer full conectivity between input and output layer
            ConnectionFactory.fullConnect(inputLayer, outputLayer);

            // set input and output cells for this network
            NeuralNetworkFactory.DefaultIO = this;

            // set appropriate learning rule for this network
            this.LearningRule = new UnsupervisedHebbianLearning();
            //this.setLearningRule(new OjaLearning(this));
        }
コード例 #4
0
        /// <summary>
        /// Creates MaxNet network architecture
        /// </summary>
        /// <param name="neuronNum">
        ///            neuron number in network </param>
        /// <param name="neuronProperties">
        ///            neuron properties </param>
        private void createNetwork(int neuronsCount)
        {
            // set network type
            this.NetworkType = NeuralNetworkType.MAXNET;

            // createLayer input layer in layer
            Layer inputLayer = LayerFactory.createLayer(neuronsCount, new NeuronProperties());

            this.addLayer(inputLayer);

            // createLayer properties for neurons in output layer
            NeuronProperties neuronProperties = new NeuronProperties();

            neuronProperties.setProperty("neuronType", typeof(CompetitiveNeuron));
            neuronProperties.setProperty("transferFunction", TransferFunctionType.Ramp.ToString());

            // createLayer full connectivity in competitive layer
            CompetitiveLayer competitiveLayer = new CompetitiveLayer(neuronsCount, neuronProperties);

            // add competitive layer to network
            this.addLayer(competitiveLayer);

            double competitiveWeight = -(1 / (double)neuronsCount);

            // createLayer full connectivity within competitive layer
            ConnectionFactory.fullConnect(competitiveLayer, competitiveWeight, 1);

            // createLayer forward connectivity from input to competitive layer
            ConnectionFactory.forwardConnect(inputLayer, competitiveLayer, 1);

            // set input and output cells for this network
            NeuralNetworkFactory.DefaultIO = this;
        }
コード例 #5
0
        /// <summary>
        /// Creates an instance of Supervised Hebbian Network with specified number
        /// of neurons in input layer, output layer and transfer function
        /// </summary>
        /// <param name="inputNeuronsNum">
        ///            number of neurons in input layer </param>
        /// <param name="outputNeuronsNum">
        ///            number of neurons in output layer </param>
        /// <param name="transferFunctionType">
        ///            transfer function type </param>
        private void createNetwork(int inputNeuronsNum, int outputNeuronsNum, TransferFunctionType transferFunctionType)
        {
            // init neuron properties
            NeuronProperties neuronProperties = new NeuronProperties();

            neuronProperties.setProperty("transferFunction", transferFunctionType.ToString());
            neuronProperties.setProperty("transferFunction.slope", 1);
            neuronProperties.setProperty("transferFunction.yHigh", 1);
            neuronProperties.setProperty("transferFunction.xHigh", 1);
            neuronProperties.setProperty("transferFunction.yLow", -1);
            neuronProperties.setProperty("transferFunction.xLow", -1);

            // set network type code
            this.NetworkType = NeuralNetworkType.SUPERVISED_HEBBIAN_NET;

            // createLayer input layer
            Layer inputLayer = LayerFactory.createLayer(inputNeuronsNum, neuronProperties);

            this.addLayer(inputLayer);

            // createLayer output layer
            Layer outputLayer = LayerFactory.createLayer(outputNeuronsNum, neuronProperties);

            this.addLayer(outputLayer);

            // createLayer full conectivity between input and output layer
            ConnectionFactory.fullConnect(inputLayer, outputLayer);

            // set input and output cells for this network
            NeuralNetworkFactory.DefaultIO = this;

            // set appropriate learning rule for this network
            this.LearningRule = new SupervisedHebbianLearning();
        }
コード例 #6
0
ファイル: Hopfield.cs プロジェクト: starhash/Neuroph.NET
        /// <summary>
        /// Creates Hopfield network architecture
        /// </summary>
        /// <param name="neuronsCount">
        ///            neurons number in Hopfied network </param>
        /// <param name="neuronProperties">
        ///            neuron properties </param>
        private void createNetwork(int neuronsCount, NeuronProperties neuronProperties)
        {
            // set network type
            this.NetworkType = NeuralNetworkType.HOPFIELD;

            // createLayer neurons in layer
            Layer layer = LayerFactory.createLayer(neuronsCount, neuronProperties);

            // createLayer full connectivity in layer
            ConnectionFactory.fullConnect(layer, 0.1);

            // add layer to network
            this.addLayer(layer);

            // set input and output cells for this network
            NeuralNetworkFactory.DefaultIO = this;

            // set Hopfield learning rule for this network
            //this.setLearningRule(new HopfieldLearning(this));
            this.LearningRule = new BinaryHebbianLearning();
        }
コード例 #7
0
        /// <summary>
        /// Creates adaline network architecture with specified number of input neurons
        /// </summary>
        /// <param name="inputNeuronsCount">
        ///              number of neurons in input layer </param>
        private void createNetwork(int inputNeuronsCount)
        {
            // set network type code
            this.NetworkType = NeuralNetworkType.ADALINE;

            // create input layer neuron settings for this network
            NeuronProperties inNeuronProperties = new NeuronProperties();

            inNeuronProperties.setProperty("transferFunction", TransferFunctionType.Linear.ToString());

            // createLayer input layer with specified number of neurons
            Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, inNeuronProperties);

            inputLayer.addNeuron(new BiasNeuron());                             // add bias neuron (always 1, and it will act as bias input for output neuron)
            this.addLayer(inputLayer);

            // create output layer neuron settings for this network
            NeuronProperties outNeuronProperties = new NeuronProperties();

            outNeuronProperties.setProperty("transferFunction", TransferFunctionType.Ramp.ToString());
            outNeuronProperties.setProperty("transferFunction.slope", 1);
            outNeuronProperties.setProperty("transferFunction.yHigh", 1);
            outNeuronProperties.setProperty("transferFunction.xHigh", 1);
            outNeuronProperties.setProperty("transferFunction.yLow", -1);
            outNeuronProperties.setProperty("transferFunction.xLow", -1);

            // createLayer output layer (only one neuron)
            Layer outputLayer = LayerFactory.createLayer(1, outNeuronProperties);

            this.addLayer(outputLayer);

            // createLayer full conectivity between input and output layer
            ConnectionFactory.fullConnect(inputLayer, outputLayer);

            // set input and output cells for network
            NeuralNetworkFactory.DefaultIO = this;

            // set LMS learning rule for this network
            this.LearningRule = new LMS();
        }
コード例 #8
0
        public virtual void createDemoNetwork()
        {
            int productsCount = 20;
            int typesCount    = 3;
            int brandsCount   = 3;
            int priceCount    = 3;
            int promoCount    = 3;

            this.NetworkType = NeuralNetworkType.RECOMMENDER;
            //this.getLayers().clear();
            // init neuron settings for this type of network
            NeuronProperties neuronProperties = new NeuronProperties();

            neuronProperties.setProperty("transferFunction", TransferFunctionType.Ramp.ToString());
            // for sigmoid and tanh transfer functions
            neuronProperties.setProperty("transferFunction.slope", 1);

            // create input layer
            Layer inputLayer = LayerFactory.createLayer(productsCount, neuronProperties);

            this.addLayer(inputLayer);
            createProductLabels(inputLayer);


            // create product types layer
            Layer typeLayer = LayerFactory.createLayer(typesCount, neuronProperties);

            createTypeLabels(typeLayer);
            this.addLayer(typeLayer);


            // create brands layer
            Layer brandLayer = LayerFactory.createLayer(brandsCount, neuronProperties);

            createBrandLabels(brandLayer);
            this.addLayer(brandLayer);


            // create price layer
            Layer priceLayer = LayerFactory.createLayer(priceCount, neuronProperties);

            createPriceLabels(priceLayer);
            this.addLayer(priceLayer);

            // create price layer
            Layer promoLayer = LayerFactory.createLayer(promoCount, neuronProperties);

            createPromoLabels(promoLayer);
            this.addLayer(promoLayer);

            // create output layer
            Layer outputLayer = LayerFactory.createLayer(productsCount, neuronProperties);

            this.addLayer(outputLayer);
            createProductLabels(outputLayer);

            createTypeConnections();
            createBrandConnections();
            createPriceConnections();
            createPromoConnections();


            // create reccurent self connections in output layer
            foreach (Neuron neuron in this.getLayerAt(outputLayerIdx).Neurons)
            {
                neuron.addInputConnection(neuron, 1);
            }

            // set input and output cells for this network
            NeuralNetworkFactory.DefaultIO = this;

            // dont learn the self connections
            // moze cak i posle svakog prolaza da se primenjuje hebbianovo pravilo a ne samo nakon kupovine
            // napravi vise varijanti
            // ako kupuje onda moze da se primenjje winner takes all hebbian learning
            this.LearningRule = new UnsupervisedHebbianLearning();
        }