2012-04-24 12 views
0

フィーチャーとウェイトの2つの行列があります。学習アルゴリズムを実装しています。私はarraylistの要素を更新したいです(特徴の1つのサンプルを表すためのベクトル)。以下はコードです。しかし、行列の私の要素(ベクトル要素は更新されません)が更新されました。私はサンプル溶液も入れました。更新前と更新後の同じ値は期待されません。コードの欠陥がどこにあるのか教えてください。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)); 
} 

サンプル出力は、::私はこれが起こる理由は、合理的な理由の夫婦のみと考えることができます

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] 
+3

デバッガを使用し、コード内の行をステップ実行する必要があります。 –

+1

1.あなたのコードをフォーマットする2. 'testList'はどこから来ていますか? (投稿したコードに初期化はありません)。 – aviad

+0

テストリストはメソッドのパラメータとして用意されています。 – thetna

答えて

2

です:

  1. レート== 0
  2. testList.contains (i)は常に偽である。

ブレークポイントを使ってこれをデバッグすることを強くお勧めします。少なくとも、それが呼び出されることを確認するために、featureVector.set()が呼び出されるSystem.out.printlnを配置します。条件が真実にならないので、決して呼ばれないと思います。

が使用ブレークポイントを実行し、それがtestList.get(j)の戻り値の型である

0

何...命の恩人だろうか?あなたは整数を、私が二重であると思われるものと比較しています。それはあまりうまくいかないでしょう...

関連する問題