Changeset 1004


Ignore:
Timestamp:
Jan 23, 2008, 7:24:53 PM (16 years ago)
Author:
Peter
Message:

adding a wrapper around std::random_shuffle that uses the RNG class. Changed all calls to random_shuffle to use the added function. Acctually all calls already used the RNG class so essentially this change is only cosmetic, but by providing a function I think it is easier to avoid using multiple random generators.

Location:
trunk/yat
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/classifier/CrossValidationSampler.cc

    r1002 r1004  
    6666    my_begin.push_back(target.size());
    6767
    68     random::DiscreteUniform rnd;
    69 
    7068    for (size_t i=0; i<N; ) {
    7169      // shuffle indices within class each class
    7270      for (size_t j=0; j+1<my_begin.size(); ++j)
    73         random_shuffle(v.begin()+my_begin[j],v.begin()+my_begin[j+1],rnd);
     71        random::random_shuffle(v.begin()+my_begin[j],v.begin()+my_begin[j+1]);
    7472     
    7573      for (size_t part=0; part<k && i<N; i++, part++) {
  • trunk/yat/classifier/FeatureSelectorRandom.cc

    r1000 r1004  
    6666    for (size_t i=0; i<total_N; ++i)
    6767      features_.push_back(i);
    68     random::DiscreteUniform rnd;
    6968    // Peter should use random_sample here, but not included in std
    70     std::random_shuffle(features_.begin(), features_.end(), rnd);
     69    random::random_shuffle(features_.begin(), features_.end());
    7170    features_.resize(N_);
    7271  }
  • trunk/yat/classifier/SVindex.cc

    r1000 r1004  
    120120  void SVindex::shuffle(void)
    121121  {
    122     random::DiscreteUniform a;
    123     random_shuffle(vec_.begin()+nof_sv_, vec_.end(), a);
     122    random::random_shuffle(vec_.begin()+nof_sv_, vec_.end());
    124123  }
    125124
  • trunk/yat/classifier/Target.cc

    r1000 r1004  
    167167  void Target::random_shuffle(void)
    168168  {
    169     random::DiscreteUniform d;
    170     std::random_shuffle(classes_.begin(), classes_.end(),d);
     169    random::random_shuffle(classes_.begin(), classes_.end());
    171170  }
    172171
  • trunk/yat/random/random.h

    r1000 r1004  
    3030#include <gsl/gsl_randist.h>
    3131
     32#include <algorithm>
    3233#include <string>
    3334
     
    555556  };
    556557
     558  /**
     559     \brief Convenience function to shuffle a range with singleton RNG.
     560
     561     Wrapper around std::random_shuffle using DiscreteUniform as
     562     random generator and thereby using the underlying RNG class,
     563     which is singleton.
     564   */
     565  template<typename T>
     566  void random_shuffle(T first, T last)
     567  {
     568    DiscreteUniform rnd;
     569    std::random_shuffle(first, last, rnd);
     570  }
     571
    557572}}} // of namespace random, yat, and theplu
    558573
  • trunk/yat/statistics/KolmogorovSmirnov.cc

    r1003 r1004  
    11// $Id$
     2
     3/*
     4  Copyright (C) 2008 Peter Johansson
     5
     6  This file is part of the yat library, http://trac.thep.lu.se/yat
     7
     8  The yat library is free software; you can redistribute it and/or
     9  modify it under the terms of the GNU General Public License as
     10  published by the Free Software Foundation; either version 2 of the
     11  License, or (at your option) any later version.
     12
     13  The yat library is distributed in the hope that it will be useful,
     14  but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
     16  General Public License for more details.
     17
     18  You should have received a copy of the GNU General Public License
     19  along with this program; if not, write to the Free Software
     20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
     21  02111-1307, USA.
     22*/
    223
    324#include "KolmogorovSmirnov.h"
  • trunk/yat/utility/vector.cc

    r1000 r1004  
    521521  void shuffle(vector& invec)
    522522  {
    523     random::DiscreteUniform rnd;
    524     std::random_shuffle(invec.begin(), invec.end(), rnd);
     523    random::random_shuffle(invec.begin(), invec.end());
    525524  }
    526525
Note: See TracChangeset for help on using the changeset viewer.