src/IO/SortedData.cpp

00001 /*
00002 * This file is part of MultiBoost, a multi-class 
00003 * AdaBoost learner/classifier
00004 *
00005 * Copyright (C) 2005 Norman Casagrande
00006 * For informations write to nova77@gmail.com
00007 *
00008 * This library is free software; you can redistribute it and/or
00009 * modify it under the terms of the GNU Lesser General Public
00010 * License as published by the Free Software Foundation; either
00011 * version 2.1 of the License, or (at your option) any later version.
00012 *
00013 * This library is distributed in the hope that it will be useful,
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 * Lesser General Public License for more details.
00017 *
00018 * You should have received a copy of the GNU Lesser General Public
00019 * License along with this library; if not, write to the Free Software
00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021 *
00022 */
00023 
00024 #include "SortedData.h"
00025 
00026 #include "Defaults.h" // for STABLE_SORT declaration
00027 #include "Utils/Utils.h" // for comparePairOnSecond
00028 
00029 // ------------------------------------------------------------------------
00030 namespace MultiBoost {
00031 
00032 void SortedData::load(const string& fileName, const eInputType inputType, const int verboseLevel)
00033 {
00034    InputData::load(fileName, inputType, verboseLevel);
00035 
00036    // Test does not need sorting
00037    if (inputType == IT_TEST)
00038       return;
00039 
00040    if (verboseLevel > 0)
00041    {
00042       cout << "Sorting data...";
00043       cout.flush();
00044    }
00045 
00046    // set the number of columns for the stored data
00047    _sortedData.resize(_numColumns);
00048    
00050    // Fill the sorted data vector.
00051    // The data is stored column-wise. The index [j] is the column
00052    // and the pair represent the index of the example with the value
00053    for (int i = 0; i < _numExamples; ++i)
00054    {
00055       for (int j = 0; j < _numColumns; ++j)
00056          _sortedData[j].push_back( make_pair(i, _data[i].pValues[j]) );
00057    }
00058 
00060    // Now sort the data.
00061 
00062    // For each column
00063    for (int j = 0; j < _numColumns; ++j)
00064    {
00065 #if STABLE_SORT
00066       stable_sort( _sortedData[j].begin(), _sortedData[j].end(), 
00067                    nor_utils::comparePairOnSecond< int, double, less<double> > );
00068 #else
00069       sort( _sortedData[j].begin(), _sortedData[j].end(), 
00070             nor_utils::comparePairOnSecond< int, double, less<double> > );
00071 #endif
00072    }
00073 
00074    if (verboseLevel > 0)
00075       cout << "Done!" << endl;
00076 }
00077 
00078 // ------------------------------------------------------------------------
00079 
00080 } // end of namespace MultiBoost

Generated on Mon Nov 28 21:43:46 2005 for MultiBoost by  doxygen 1.4.5