std::vector<bool> reprVectors::encode(std::vector<float> input){
std::vector<float> distance;
for(size_t i=0;i<this->reprVectorsList.size();i++){
distance.push_back(distBtw(input,this->reprVectorsList[i]));
}
std::vector<float>::iterator it= min_element(distance.begin(),distance.end());
return this->reprVectorsList[it]->code;
}
float reprVectors::distBtw(std::vector<float> input, Node* node){
double distance=0;
for(size_t i=0;i<node->valuesInDim.size();i++){
distance = distance +
pow((node->valuesInDim[i]-input[i]),2);
}
return (float)pow(distance,0.5);
}
它迭代器给了我距离向量中的最小距离。如何在我的 reprVectorList 中找到对应的位置?如何从 min_element 返回的 it 迭代器中获取 int/size_t 值?