Changeset 1175 for trunk/yat/classifier


Ignore:
Timestamp:
Feb 27, 2008, 5:27:13 PM (16 years ago)
Author:
Peter
Message:

fixed bug in SVM. SVM does not own the Kernel and should therefore never delete it. Cpy and assignment can simply copy the pointer without problem. Yet if the Kernel is deallocated outside, behavior of SVM is undefined.

Location:
trunk/yat/classifier
Files:
2 edited

Legend:

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

    r1121 r1175  
    6060
    6161  SVM::SVM(const SVM& other)
    62     : bias_(other.bias_), C_inverse_(other.C_inverse_), kernel_(NULL),
     62    : bias_(other.bias_), C_inverse_(other.C_inverse_), kernel_(kernel_),
    6363      margin_(0), max_epochs_(other.max_epochs_), tolerance_(other.tolerance_),
    6464      trained_(other.trained_)
    6565  {
    66     if (other.kernel_)
    67       kernel_ = new KernelLookup(*other.kernel_);
    6866  }
    6967
     
    7169  SVM::~SVM()
    7270  {
    73     if (kernel_)
    74       delete kernel_;
    7571  }
    7672
     
    118114  SVM* SVM::make_classifier(void) const
    119115  {
    120     return new SVM(*this);
     116    SVM* svm = new SVM(*this);
     117    svm->trained_ = false;
     118    return svm;
    121119  }
    122120
     
    181179  void SVM::train(const KernelLookup& kernel, const Target& targ)
    182180  {
    183     if (kernel_)
    184       delete kernel_;
    185181    kernel_ = new KernelLookup(kernel);
    186182    target_ = targ;
  • trunk/yat/classifier/SVM.h

    r1170 r1175  
    230230    double bias_;
    231231    double C_inverse_;
     232    // not owned by SVM
    232233    const KernelLookup* kernel_;
    233234    double margin_;
Note: See TracChangeset for help on using the changeset viewer.