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

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

File:
1 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  {
Note: See TracChangeset for help on using the changeset viewer.