sample.cc

Go to the documentation of this file.
00001 /* MLPACK 0.2
00002  *
00003  * Copyright (c) 2008, 2009 Alexander Gray,
00004  *                          Garry Boyer,
00005  *                          Ryan Riegel,
00006  *                          Nikolaos Vasiloglou,
00007  *                          Dongryeol Lee,
00008  *                          Chip Mappus, 
00009  *                          Nishant Mehta,
00010  *                          Hua Ouyang,
00011  *                          Parikshit Ram,
00012  *                          Long Tran,
00013  *                          Wee Chin Wong
00014  *
00015  * Copyright (c) 2008, 2009 Georgia Institute of Technology
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License as
00019  * published by the Free Software Foundation; either version 2 of the
00020  * License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful, but
00023  * WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301, USA.
00031  */
00038 #include <fastlib/fastlib.h>
00039 
00040 const char *help_text[] = {
00041   "sample - Randomizes a data set",
00042   "",
00043   "Parameters:",
00044   " --in file.txt       (input file)",
00045   " --out file100k.txt  (output file)",
00046   " --n 100000          (number of points; if omitted, entire dataset)",
00047   " --seed 31415926     (srand seed; if omitted, time is used)"
00048 };
00049 
00050 int main(int argc, char *argv[]) {
00051   fx_init(argc, argv);
00052 
00053   const char *in = fx_param_str_req(fx_root, "in");
00054   const char *out = fx_param_str_req(fx_root, "out");
00055 
00056   fx_timer_start(fx_root, "read_in_matrix");
00057   Matrix m_in;
00058   data::Load(in, &m_in);
00059   fx_timer_stop(fx_root, "read_in_matrix");
00060 
00061   index_t n = fx_param_int(fx_root, "n", m_in.n_cols());
00062   index_t seed = fx_param_int(fx_root, "seed", time(NULL));
00063 
00064   srand(seed);
00065 
00066   fx_timer_start(fx_root, "make_permutation");
00067   ArrayList<index_t> permutation;
00068   math::MakeRandomPermutation(m_in.n_cols(), &permutation);
00069   fx_timer_stop(fx_root, "make_permutation");
00070 
00071   fx_timer_start(fx_root, "make_new_matrix");
00072   Matrix m_out;
00073   m_out.Init(m_in.n_rows(), n);
00074 
00075   for (index_t i = 0; i < n; i++) {
00076     Vector v_in;
00077     Vector v_out;
00078 
00079     m_in.MakeColumnVector(permutation[i], &v_in);
00080     m_out.MakeColumnVector(i, &v_out);
00081     v_out.CopyValues(v_in);
00082   }
00083   fx_timer_stop(fx_root, "make_new_matrix");
00084 
00085   fx_timer_start(fx_root, "save_new_matrix");
00086   data::Save(out, m_out);
00087   fx_timer_stop(fx_root, "save_new_matrix");
00088 
00089   fx_done();
00090 }
00091 
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3