为什么对象的价值在C#中自行改变?

时间:2015-09-03 06:40:28

标签: c#

我需要保存sv,label_sv,alfa,b和tanda的值,所有这些保存到树中,但是当我尝试将数据保存到树中时,我不知道为什么但是root中的值已被新值改变,我在树上抛出一个断点,但我仍然不知道为什么会发生这种情况,也许有人可以帮助我,thx

这里是树的代码

class bdt
{
    public Node root;

    public void insert(List<List<double>> D, List<double> L,List<double> A,double B, int T)
    {
        Node newNode = new Node();
        newNode.iData=D;
        newNode.ilabel = L;
        newNode.ialphas = A;
        newNode.ib = B;
        newNode.itanda = T;

        if (root == null)
        {
            root = newNode;
        }
        else
        {
            Node current=root;
            Node parent;
            while(true)
            {
                parent = current;
                if (current.itanda <= 0)
                {
                    current = current.ileftChild;
                    if (current == null)
                    {
                        parent.ileftChild = newNode;
                        return;
                    }
                }
                else
                {
                    current = current.irightChild;
                    if (current == null)
                    {
                        parent.irightChild = newNode;
                        return;
                    }
                }
            }
        }
    }

    public void InOrder(Node theRoot)
    {
        if (!(theRoot == null))
        {
            InOrder(theRoot.ileftChild);

            Console.WriteLine("data : ");
            foreach(var sublist in theRoot.iData)
            {
                foreach (var value in sublist)
                {
                    Console.Write(" " + value);
                }
                Console.WriteLine();
            }

            Console.WriteLine();
            Console.WriteLine("label : ");
            foreach (var value in theRoot.ilabel)
            {
                Console.WriteLine(" " + value);
            }

            Console.WriteLine();
            Console.WriteLine("alphas : ");
            foreach (var value in theRoot.ialphas)
            {
                Console.WriteLine(" " + value);
            }

            Console.WriteLine();
            Console.WriteLine("b: " + theRoot.ib);
            Console.WriteLine();
            Console.WriteLine("tanda : " + theRoot.itanda);

            InOrder(theRoot.irightChild);
        }
    }

}

这是调用树的方法

public void svm_bdt(List<List<double>> data_rekursif, List<double> label_rekursif, int tanda)
    {
        cluster clus = new cluster();
        clus.process_cluster(data_rekursif, label_rekursif);
        List<List<double>> temp_data = clus.get_data();
        List<double> temp_y = clus.get_data_y();
        List<List<double>> data1 = new List<List<double>>();
        List<List<double>> data2 = new List<List<double>>();
        List<double> temp_y1 = new List<double>();
        List<double> temp_y2 = new List<double>();

        //proses SVM dan simpan dalam tree alfa, sv, label sv
        if (jum_label(temp_y) > 1)
        {
            call_svm(data_rekursif, temp_y);
            BDT.insert(SV, label_sv, alfa, b, tanda);
        }
        else if (jum_label(temp_y) == 1)
        {
            BDT.insert(SV, label_sv, alfa, b, tanda);
        }

        double temp = -1;
        for (int i = 0; i < temp_data.Count; i++)
        {
            if (temp == temp_y[i])
            {
                temp_y1.Add(label_rekursif[i]);
                data1.Add(temp_data[i]);
            }
            else
            {
                temp_y2.Add(label_rekursif[i]);
                data2.Add(temp_data[i]);
            }
        }

        if (jum_label(temp_y1)>1)
        {
            svm_bdt(data1, temp_y1, -1);
        }

        if (jum_label(temp_y2) > 1)
        {
            svm_bdt(data2, temp_y2, 1);
        }

        if (jum_label(temp_y1) < 1 && jum_label(temp_y2) < 1)
        {
            return;
        }
    }   

0 个答案:

没有答案