Beispiel #1
0
        private void pertube(int m, Node node, double[][] dataInput)
        {
            if (!node.ActiveAtributtes[m])
                return;

            Node auxNode = (Node)node.Clone();
            double[] U = new double[dataInput.Length];
            for (int i = 0; i < dataInput.Length; i++)
                U[i] = Math.Min((node.weights[m] * dataInput[i][m] - node.Evaluate(dataInput[i])) / dataInput[i][m], 0);
            Array.Sort(U);

            int bestA = 0;
            int dif = Int16.MaxValue;
            for (int i = 0; i < U.Length; i++)
            {
                int positive = 0;
                int negative = 0;
                for (int j = 0; j < U.Length; j++)
                {
                    if (j <= i && U[j] <= 0)
                        negative++;
                    else if (j > i && U[j] > 0)
                        positive++;
                }
                if (Math.Abs(positive - negative) < dif)
                {
                    dif = Math.Abs(positive - negative);
                    bestA = i;
                }

            }

            auxNode.weights[m] = U[bestA];
            if (gain(dataInput, auxNode) > gain(dataInput, node))
            {
                node.weights[m] = U.Max();
                node.ResetPmove();
            }
            else if (gain(dataInput, auxNode) == gain(dataInput, node))
            {
                if(node.EvaluatePmove())
                    node.weights[m] = U.Max();
                node.DecreasePmove();
            }
        }
Beispiel #2
0
        /*
         * data[0]: left
         * data[1]: right
         */
        private static List<double[]>[] divideData(double[][] input, Node node)
        {
            List<double[]>[] data = new List<double[]>[2];
            data[0] = new List<double[]>();
            data[1] = new List<double[]>();

            for (int i = 0; i < input.Length; i++)
            {
                if (node.Evaluate(input[i]) < 0) //Curioso caso.
                    data[0].Add(input[i]);
                else
                    data[1].Add(input[i]);
            }
            return data;
        }