Java 无法更新arrayList中的元素

Java 无法更新arrayList中的元素,java,arraylist,machine-learning,Java,Arraylist,Machine Learning,我有两个矩阵用于特征和权重元素。我正在实现一个学习算法。我想更新arraylist的元素(表示一个特征样本的向量)。下面是代码。但是我的矩阵元素(向量元素)没有更新。我也放了样品溶液。更新前后的值不应相同。你能告诉我代码中的漏洞在哪里吗 for(int i =0 ; i< N ; i++){ //N is a large real number ArrayList<Double> featureVector = new ArrayList<Double&

我有两个矩阵用于特征和权重元素。我正在实现一个学习算法。我想更新arraylist的元素(表示一个特征样本的向量)。下面是代码。但是我的矩阵元素(向量元素)没有更新。我也放了样品溶液。更新前后的值不应相同。你能告诉我代码中的漏洞在哪里吗

    for(int i =0 ; i< N ; i++){  //N is a large real number
    ArrayList<Double> featureVector = new ArrayList<Double>();
    featureVector = FeatureMatrix.get(i);
    System.out.println("Before::"+ featureVector);
    if(testList.contains(i)){
    for(int j=0 ; j< testList.size(); j++){
        if(i == testList.get(j)){       
        int indexInTestList= j;
        List<Double> subListNextCandidate ;
        subListNextCandidate =  weightVectorNextCandidate.subList((10*indexIntTestList),((10)*(indexInTestList+1))); //clips a portion of member from long list of members
        List<Double> approxWeight = new ArrayList<Double>();
        approxWeight = getApproxWeight(FeatureVector, indexInTestList, FeatureMatrix,WeightMatrix, bias); //approxWeight is a vector of same dimension as of featureVector

        for(int l=0 ; l< 10;l++){                 
            double Update = featureVector.get(l)+ Rate*((subListCandidate.get(l)-approxWeight.get(l))-(lambda*featureVector.get(l)*(1/M)));//M is large real number
            featureVector.set(l,Update);

        }                   
        }
    }
    }

    else{
    for(int l=0 ; l< 10;l++){
        double Update = featureVector.get(l)  -Rate*(lambda*featureVector.get(l)*(1/M));
        featureVector.set(l, Update);
    }                   
    }
    System.out.println("After:::"+ FeatureMatrix.get(i) );  
}

我只能想出几个合理的理由来解释为什么会发生这种情况:

  • 比率==0
  • testList.contains(i)始终为false
  • 我强烈建议使用断点来调试它。至少,将System.out.println放在调用featureVector.set()的位置,以确保调用过它。我猜它从来没有被调用过,因为条件永远不会变为现实


    一定要使用断点,它将是一个救命稻草…

    testList.get(j)的返回类型是什么?你把一个整数和我怀疑的双精度进行比较。这不太可能顺利…

    您应该使用调试器并逐步完成代码中的行。1。格式化代码2。
    testList
    来自哪里?(您发布的代码中没有初始化。)测试列表作为方法的参数出现。
     Before::[0.04539928251182193, -0.16233604402485394, 0.905018369795912, -1.2817141994528614, 0.7065420460225843, -0.8946090188977665, -1.74892020689701, -2.1539901172158187, 1.8229765478806985, -1.8109945435256574]
     After:::[0.04539928251182193, -0.16233604402485394, 0.905018369795912, -1.2817141994528614, 0.7065420460225843, -0.8946090188977665, -1.74892020689701, -2.1539901172158187, 1.8229765478806985, -1.8109945435256574]