// $Id: NNI.cc 1487 2008-09-10 08:41:36Z jari$ /* Copyright (C) 2004 Jari Häkkinen Copyright (C) 2005 Peter Johansson Copyright (C) 2006 Jari Häkkinen Copyright (C) 2007 Jari Häkkinen, Peter Johansson Copyright (C) 2008 Peter Johansson This file is part of the yat library, http://dev.thep.lu.se/yat The yat library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The yat library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with yat. If not, see . */ #include "NNI.h" #include "stl_utility.h" #include #include #include namespace theplu { namespace yat { namespace utility { // For a discussion and motivation for various algorithm // implementations here see the paper cited in the class definition // documentation. NNI::NNI(const utility::Matrix& matrix,const utility::Matrix& weight, const unsigned int neighbours) : data_(matrix), imputed_data_(matrix), neighbours_(neighbours), weight_(weight) { } // d_{ij}^2=\frac {\sum_{k=1,C} w_{ik} w_{jk} (x_{ik}-x_{jk})^2 } // {\sum_{k=l,C} w_{ik} w_{jk} } // where C is the number of columns std::vector > NNI::calculate_distances(const size_t row) const { std::vector > distance; for (size_t i=0; i this_distance(i,0.0); for (size_t j=0; j& NNI::not_imputed(void) const { return not_imputed_; } // Contributing nearest neighbours are added up to the user set // number, and neighbours are disqualified if their element (column) // weight is zero std::vector NNI::nearest_neighbours(const size_t column, const std::vector >& d) const { std::vector index; double contribs=0; for (size_t i=0; ((i