Exemplo n.º 1
0
        //основной конструктор, размер входного слоя, размеры скрытых слоев и тд
        public NeuralNetwork(int inSize, List <int> hiddSizes,
                             int outSize, floatFun actFun, bool isB = false, Pair <float> r = null)
        {
            if (isB)
            {
                inSize++;
            }
            inputLayer = new Layer(inSize, 0, ActivationFun.linearFunction);
            int prevSize = inSize;

            foreach (int size in hiddSizes)
            {
                int sizeLayer = size;
                if (isB)
                {
                    sizeLayer++;
                }
                hiddenLayers.Add(new Layer(sizeLayer, prevSize, actFun));
                prevSize = sizeLayer;
            }
            outputLayer = new Layer(outSize, prevSize, actFun);
            if (r != null)
            {
                range = r;
            }
            layerSize = 2 + hiddenLayers.Count;
            isBias    = isB;
        }
Exemplo n.º 2
0
        //Изменение настроек НН
        private void changeNNSettings(object sender, EventArgs e)
        {
            float V;

            float.TryParse(textBoxLearnRate.Text, out V);
            Information.NN.LearnSpeed = V;
            string funStr = comboBoxFunAct.Text;

            if (funStr == "")
            {
                funStr = "Linear";
            }
            floatFun F = ActivationFun.sigmoidFunction;

            if (funStr == "Linear")
            {
                F = ActivationFun.linearFunction;
            }
            if (funStr == "Sigmoid")
            {
                F = ActivationFun.sigmoidFunction;
            }
            if (funStr == "Tangent")
            {
                F = ActivationFun.tangentFunction;
            }
            Information.NN.SetActFun(F);
            float M;

            float.TryParse(textBoxMoment.Text, out M);
            Information.NN.LearnMoment = M;
            console.AppendText("fun = " + funStr + " V = " + Information.NN.LearnSpeed);
            console.AppendText(" M = " + Information.NN.LearnMoment + "\r\n");
        }
Exemplo n.º 3
0
 public void SetActFun(floatFun dF)
 {
     foreach (var l in hiddenLayers)
     {
         l.setActivationFunction(dF);
     }
     outputLayer.setActivationFunction(dF);
 }
Exemplo n.º 4
0
        //по умолчанию
        public NeuralNetwork(int size, floatFun actFun, bool isB = false, Pair <float> r = null)
        {
            int sizeOut = size;

            if (isB)
            {
                size++;
            }
            inputLayer = new Layer(size, 0, ActivationFun.linearFunction);
            hiddenLayers.Add(new Layer(size, size, actFun));
            outputLayer = new Layer(sizeOut, size, actFun);
            if (r != null)
            {
                range = r;
            }
            layerSize = 3;
            isBias    = isB;
        }
Exemplo n.º 5
0
        //конструктор с инициализацией весов(выгрузка из файла)
        public NeuralNetwork(int inSize, List <int> hiddSizes, int outSize,
                             floatFun actFun, List <List <float> > weights, bool isB = false)
        {
            isBias     = isB;
            inputLayer = new Layer(inSize, 0, ActivationFun.linearFunction);
            int weightIndex = 1;
            int prevSize    = inSize;

            foreach (int sizeLayer in hiddSizes)
            {
                hiddenLayers.Add(new Layer(sizeLayer, prevSize, actFun));
                prevSize = sizeLayer;
                hiddenLayers[weightIndex - 1].Weights = weights[weightIndex];
                weightIndex++;
            }
            outputLayer         = new Layer(outSize, prevSize, actFun);
            outputLayer.Weights = weights[weightIndex];
            layerSize           = 2 + hiddenLayers.Count;
        }
Exemplo n.º 6
0
        //конструктор слоя
        public Layer(int size, int sizePrev, floatFun actFun, float a = -0.8f, float b = 0.8f)
        {
            sizeNeurons   = size;
            outputs       = new List <float>(sizeNeurons);
            activationFun = actFun;
            Thread.Sleep(TimeSpan.FromMilliseconds(100));
            Random rand = new Random(DateTime.Now.Millisecond);

            if (sizePrev > 0)
            {
                sizeWeights = size * sizePrev;
                weights     = new List <float>(sizeWeights);
                //deltaWeights = new List<float>(sizeWeights);
                for (int i = 0; i < sizeWeights; i++)
                {
                    weights.Add(a + (float)rand.NextDouble() * (b - a));
                    //deltaWeights.Add(0);
                }
            }
        }
Exemplo n.º 7
0
 public void setActivationFunction(floatFun fun)
 {
     activationFun = fun;
 }