1

これを理解するのに少し問題があります。

基本的に、サイズが 1024x1024 のブロックを含む 2D ベクトルがあり、これらのブロックの総エネルギーを計算します。したがって、ブロックが特定のしきい値内にある場合、別の 2D ベクトル内に格納できます。問題は、しきい値が負になるまで複数のブロックをキャプチャ (プッシュ バック) する必要があることです。以下に例を示します。

blocks[0] = 0.124 <- This is not pushed back
blocks[1] = 0.123 <- This is not pushed back
blocks[2] = 0.456 <- This is not pushed back 
blocks[3] = 1.23 <- This is pushed back to vector[0]
blocks[4] = 2.45 <- This is pushed back to vector[0]
blocks[5] = 7.23 <- This is pushed back to vector[0]
blocks[6] = 8.12 <- This is pushed back to vector[0]
blocks[7] = 0.12 <- This is not pushed back
blocks[8] = 0.124 <- This is not pushed back
blocks[9] = 0.125 <- This is not pushed back
blocks[10] = 8.123 <- This is pushed back to vector[1]
blocks[11] = 8.123 <- This is pushed back to vector[1]
blocks[12] = 8.123 <- This is pushed back to vector[1]
blocks[13] = 0.12 <- This is not pushed back

したがって、基本的に、ブロックのしきい値が true の場合、ブロックは、ブロックが負になるまで位置 [i] で 2D ベクトルに挿入されます。値が再び true になると、ブロックは位置 [i + 1] に押し戻されます。

これまでの私の考え:

プッシュバックする必要があるブロックの数を格納する2つの変数と、ベクトルがプッシュバックされる位置を格納する別の変数がある場合..currentpos[1]つまり、次の位置は次のようになりますcurrentpos[2]

あなたが提供できるどんな助けでも、疑似コードはさらに良いでしょう。

編集:

しきい値関数は次のとおりです。

bool threshold (vector<double> val)
{

//short threshold = 10000;
float sum = 0.0;
for(unsigned i=0; (i < val.size()); i++)
{
    sum += (val[i]*val[i]);
}
return (sum > 0.082);

}

そして、私は次のものを持っています:

std::vector<vector<double> > blocks = splitVector(1024, 1024); // this is fine, it works!
// then
std::vector<vector<double> > clusters;
for(unsigned i=0; (i < blocks.size()); i++)
{
   if(threshold(blocks[i])) { 
   // true
   clusters[i].push_back(d[i]);
   }else{
    // false do not do anything
   }
}

しかし、私が抱えている問題は、「クラスター」には返された「ポジティブ」ブロックの量しか含まれないということです。では、これblocks.size() = 745 (size)はどこでclusters.size() = 6より理にかなっていますか?

編集 - この例は機能します:

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool energy(const std::vector<double> &vals)
{
float sum = 0.0;
for(unsigned i=0; (i < vals.size()); i++)
{
    sum += (vals[i]*vals[i]);
}
//cout << sum << endl;
return (sum >= 5);

}

int main(int argc, char *argv[]) {

std::vector<vector<double> > vals {

    {0, 0, 0, 0, 0}, // This has an energy of "0" -> does not count
    {1, 1, 1, 1, 1}, // This has an energy of "5" -> push_back to vector[0]
    {1, 1, 1, 1, 1}, // This has an energy of "5" -> push_back to vector[0]
    {1, 1, 1, 1, 1}, // This has an energy of "5" -> push_back to vector[0]
    {1, 1, 1, 1, 1}, //This has an energy of "5" -> push_back to vector[0]
    {0, 0, 0, 0, 0}, // This has an energy of "0" -> does not count && start a new vector
    {1, 2, 3, 4, 5}, // This has an energy of "55" -> push_back to vector[1]
    {1, 2, 3, 4, 5}, // This has an energy of "55" -> push_back to vector[1]
    {1, 2, 3, 4, 5}, // This has an energy of "55" -> push_back to vector[1]
    {1, 2, 3, 4, 5} // This has an energy of "55" -> push_back to vector[1]
};
std::vector<vector<double> > clusters; 

//std::for_each(vals.begin(), vals.end(), energy);

int j = 0;

for(unsigned i=0; (i < vals.size()); i++)
{
    if(energy(vals[i]))
    {
        clusters.resize(j + 1);

        clusters[j] = vals[i];
    }else if(!energy(vals[i]) && energy(vals[i+1]))
    {
        j++;
    }
}

 }

ただし、値を「連結」する代わりに、値を上書きするclusters[0]だけなので、値だけが含まれます。演算子{1, 1, 1, 1, 1}の代わりに{1, 1, 1, 1, 1} + {1, 1, 1, 1, 1} + {1, 1, 1, 1, 1}+要素の合計ではなく連結を意味します。

したがって、値を連結するにはどうすればよいでしょうか。

4

2 に答える 2

1

次の疑似コードを使用できます。

bool flag = false;
int j = 0;
for i in blocks
{
 if(blocks[i] > 0)
 {
  vector[j].push_back(blocks[i]);
 flag = true;
 }
 else
  if(flag)
  {
   j++;
   flag = flase;
  }
}
于 2013-09-18T11:09:20.760 に答える