sample.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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