// This is the main DLL file. #include "stdafx.h" #include "netsvm.h" namespace netsvm { SparseVector::SparseVector() { impl_ = new pcsvm::SparseVector(); } SparseVector::SparseVector(pcsvm::SparseVector *v) { impl_ = v; } SparseVector::~SparseVector() { delete impl_; } float SparseVector::get(int i) { return impl_->get(i); } void SparseVector::put(int i, float v) { impl_->put(i,v); } String * SparseVector::to_str() { std::string w =impl_->to_str(); return new String(w.c_str()); } void SparseVector::prune(float eps) { impl_->prune(eps); } void SparseVector::push_back(float v) { int idx = impl_->lastIndex(); impl_->put(idx+1, v); } int SparseVector::lastIndex() { return impl_->lastIndex(); } int SparseVector::entries() { return impl_->entries(); } void SparseVector::clear() { impl_->clear(); } bool SparseVector::empty() { return impl_->empty(); } std::vector * SparseVector::toVector(int index1, int index2) { std::vector * rv = new std::vector(impl_->toVector(index1,index2)); return rv; } ClassificationExample* ClassificationProblem::at(int i) { ClassificationExample *rv = new ClassificationExample(); pcsvm::ClassificationExample ex = impl_->get(i); pcsvm::SparseVector *temp = new pcsvm::SparseVector(ex.vector); // SparseVector übernimmt pointerverwaltung: rv->vector = new SparseVector(temp); rv->label = ex.label; return rv; } void ClassificationProblem::push_back(SparseVector *sv, bool label) { pcsvm::ClassificationExample ex(*(sv->impl_), label); impl_->push_back(ex); } void ClassificationProblem::push_back(ClassificationExample *ex) { pcsvm::ClassificationExample tex(*(ex->vector->impl_), ex->label); impl_->push_back(tex); } ClassifierCSVM::ClassifierCSVM(ClassificationProblem *p, KernelBase *k) { impl_ = new pcsvm::ClassifierCSVM(p->impl_, k->impl_); }; CSVMTrainInfo* ClassifierCSVM::train(float cp, float cn) { pcsvm::CSVMTrainInfo inf = impl_->train(cp, cn); CSVMTrainInfo * tinf = new CSVMTrainInfo(); tinf->numIter = inf.numIter; tinf->numSV = inf.numSV; pcsvm::SparseVector *temp = new pcsvm::SparseVector(inf.svWeights); tinf->svWeights = new SparseVector(temp); return tinf; } float ClassifierCSVM::classify(SparseVector *s) { return impl_->operator ()(*(s->impl_)); } }