There is an ANN package in OF, that provides bindings to the ANN library
http://www.cs.umd.edu/~mount/ANN/. Unfortunately, this package only works
up to Octave 3.2.x. I have written a simple octave function for nearest
neighbors search that simply calls a slightly modified search program that
is part of ANN. The Octave code is below. If you look at it , you'll see
that it writes query and target files to /tmp. That's a little
inconvenient, and it makes the code Linux specific. Also, to use this, you
need my modified source code for ann_sample. The benefit is that you end up
with fast and simple nearest neighbors search, is doesn't require SWIG, and
it works with latest Octave. Because of the Linux specificity and the need
for the modified source code for ann_sample, I don't know if this makes a
good inclusion into Octave Forge. Any suggestions on what to do with this?
I'm thinking of just putting this on my own page with instructions. If
anyone would like to try it out, I can provide the modified ann_sample.
Michael
# Copyright (C) 2012 Michael Creel <michael.cr...@uab.es>
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; If not, see <http://www.gnu.org/licenses/>.
# nearest_neighbors: find K nearest neighbors to query in target
#
# usage:
# [idx, dist] = nearest_neighbors(target, query, neighbors)
#
# inputs:
# target: mxK matrix: m points in R^K
# query: nxK matrix: n points in R^K
# neighbors: integer, the number of neighbors to find
# outputs:
# idx: m x neighbors matrix; indices of the closest neighbors points in
query to each point in target
# dist: m x neighbors matrix: the distances of the closest neighbors
points in query to each point in target
function [idx, dist] = nearest_neighbors(target, query, neighbors)
dim = columns(target);
limit = rows(query);
# save target and query to file
save -ascii /tmp/_nearest_neighbors_target target;
save -ascii /tmp/_nearest_neighbors_query query;
system("sync");
s = sprintf("ann_sample -d %d -max %d -nn %d -df
/tmp/_nearest_neighbors_query -qf /tmp/_nearest_neighbors_target", dim,
limit, neighbors);
[junk output] = system(s); # the call to ANN
# manipulate to get idx
output = str2num(output);
idx = output(:,1);
# recover from base-0 indexing
idx = idx + 1;
idx = reshape(idx, neighbors, rows(idx)/neighbors);
idx = idx';
dist = output(:,2);
dist = reshape(dist, neighbors, rows(dist)/neighbors);
dist = dist';
endfunction
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev