コンポーネントのベクトルがあるとします(各コンポーネントはフロートのベクトルです)
vector<vector<float> > components
そして、データのベクトルがあります(各データは、コンポーネントと同じサイズの浮動小数点のベクトルです)
vector< vector<float> > data
およびこのデータに関連付けられたラベル
vector<string> labels
(ここで意味するlabel[i]
のは のラベルですdata[i]
)。2 つのベクトル間の距離を返す距離関数もあります。
float distance(vector<float> v1, vector<float> v2);
このコンポーネントに関連付けられたデータの中で最も発生するラベルに従って、各コンポーネントにラベルを付けたいと思います。つまり、次のようなものです。
for each data d from data
{
let c the nearest component from d according to distance.
associate the label of d to c.
}
for each component c
{
definitely give to c the label that occur the most among labels associated to it
// example if labels {l1,l2,l1,l2,l1,l1,l1,l8,l1} were associated to c, then its label should be l1
}
<component,label>
返される最終結果は、次のように記述されたラベル付きコンポーネント ( のペア) のベクトルです。
vector< pair< vector<float>, string > > labeledComponents.
C++ でそれを行う簡単で迅速な方法は何ですか?