Changeset 860 for trunk/yat/classifier


Ignore:
Timestamp:
Sep 7, 2007, 9:39:30 PM (14 years ago)
Author:
Peter
Message:

fixes #149 - Target constructor from Target and vector<string>

Location:
trunk/yat/classifier
Files:
2 edited

Legend:

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

    r831 r860  
    44  Copyright (C) 2005 Peter Johansson
    55  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson
     6  Copyright (C) 2007 Peter Johansson
    67
    78  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
     
    4647  }
    4748 
    48   Target::Target(const Target& t,
    49                  const std::vector<size_t>& index)
     49
     50  Target::Target(const std::vector<std::string>& label,
     51                 const Target& t)
    5052    : class_map_(t.class_map_)
    5153  {
    5254    binary_=t.binary_;
    53     classes_.resize(index.size());
    54     for (size_t i=0; i<index.size(); i++) {
    55       assert(index[i]<t.size());
    56       classes_[i]=t.classes_[index[i]];
    57     }
    5855    labels_ = t.labels_;
     56    classes_.reserve(label.size());
     57    for (std::vector<std::string>::const_iterator lab=label.begin();
     58         lab!=label.end(); ++lab) {
     59      std::map<std::string,size_t>::iterator i=class_map_.lower_bound(*lab);
     60      if (i->first==*lab) // label exists
     61        classes_.push_back(i->second);
     62      else {
     63        binary_.push_back(0);
     64        classes_.push_back(labels_.size());
     65        class_map_.insert(i, std::make_pair(*lab, labels_.size()));
     66        labels_.push_back(*lab);
     67      }
     68    }
    5969  }
    6070
     
    8595  }
    8696 
     97
     98  Target::Target(const Target& t,
     99                 const std::vector<size_t>& index)
     100    : class_map_(t.class_map_)
     101  {
     102    binary_=t.binary_;
     103    classes_.resize(index.size());
     104    for (size_t i=0; i<index.size(); i++) {
     105      assert(index[i]<t.size());
     106      classes_[i]=t.classes_[index[i]];
     107    }
     108    labels_ = t.labels_;
     109  }
     110
     111
    87112  Target::~Target(void)
    88113  {
  • trunk/yat/classifier/Target.h

    r831 r860  
    5252    explicit Target(const std::vector<std::string>& labels);
    5353
     54    /**
     55       @brief Constructor
     56    */
     57    Target(const std::vector<std::string>& labels, const Target&);
     58
    5459    ///
    5560    /// @brief istream constructor.
     
    5762    Target(std::istream&, char sep='\0')
    5863      throw (utility::IO_error,std::exception);
    59 
    60     ///
    61     /// @brief Copy Constructor
    62     ///
    63     //Target(const Target& other)
    64     //  : classes_(other.classes_), class_map_(other.class_map_),
    65     //    labels_(other.labels_) {}
    6664
    6765    ///
     
    8482    const std::map<std::string,size_t>& classes(void) const;
    8583   
    86     ///
    87     /// This function is equivalent to Target::classes().size()
    88     ///
    89     /// @return number of classes
    90     ///
     84    /**
     85       This function is equivalent to Target::classes().size()
     86       
     87       \return number of classes
     88       
     89       \note there might be empty classes, i.e., classes with zero
     90       samples. This may happen when using
     91       Target(const std::vector<std::string>& labels, const Target&) or
     92       Target(const Target& org, const std::vector<size_t>& vec).
     93    */
    9194    const size_t nof_classes(void) const;
    9295
     
    157160
    158161  private:
     162    /// @brief Copy Constructor
     163    // using compiler generated constructor
     164    //Target(const Target& other);
     165
    159166    // binary target for class i
    160167    std::vector<char> binary_; // avoid using vector<bool>
Note: See TracChangeset for help on using the changeset viewer.