Skip to content

Commit

Permalink
Merge pull request #180 from shijiashuai/fix-memory-leak
Browse files Browse the repository at this point in the history
fix memory leak
  • Loading branch information
QinbinLi committed Nov 18, 2019
2 parents e71013a + 9f58e21 commit 831a8c4
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/thundersvm/model/nusvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* @brief Nu-Support Vector Machine for classification
*/
class NuSVC : public SVC {
public:
~NuSVC() override = default;

protected:
void train_binary(const DataSet &dataset, int i, int j, SyncArray<float_type> &alpha, float_type &rho) override;

Expand Down
2 changes: 2 additions & 0 deletions include/thundersvm/model/nusvr.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class NuSVR : public SVR {
public:
void train(const DataSet &dataset, SvmParam param) override;

~NuSVR() override = default;

protected:
void model_setup(const DataSet &dataset, SvmParam &param) override;

Expand Down
2 changes: 2 additions & 0 deletions include/thundersvm/model/oneclass_svc.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class OneClassSVC : public SvmModel {

vector<float_type> predict(const DataSet::node2d &instances, int batch_size) override;

~OneClassSVC() override = default;

protected:
void model_setup(const DataSet &dataset, SvmParam &param) override;

Expand Down
1 change: 1 addition & 0 deletions include/thundersvm/model/svc.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SVC : public SvmModel {

vector<float_type> predict(const DataSet::node2d &instances, int batch_size) override;

~SVC() override = default;
protected:
/**
* train a binary SVC model \f$SVM_{i,j}\f$ for class i and class j.
Expand Down
5 changes: 4 additions & 1 deletion include/thundersvm/model/svmmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class SvmModel {

//set max_memory_size during training and prediction (input unit Byte)
void set_max_memory_size_Byte(size_t size);

//return n_binary_models
int get_n_binary_models() const;

Expand All @@ -120,6 +120,9 @@ class SvmModel {

//return param.probability
const bool is_prob() const;

virtual ~SvmModel() = default;

protected:

/**
Expand Down
2 changes: 2 additions & 0 deletions include/thundersvm/model/svr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class SVR : public SvmModel {
public:
void train(const DataSet &dataset, SvmParam param) override;

~SVR() override = default;

protected:
void model_setup(const DataSet &dataset, SvmParam &param) override;

Expand Down
2 changes: 2 additions & 0 deletions include/thundersvm/solver/csmosolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class CSMOSolver {
void solve(const KernelMatrix &k_mat, const SyncArray<int> &y, SyncArray<float_type> &alpha, float_type &rho,
SyncArray<float_type> &f_val, float_type eps, float_type Cp, float_type Cn, int ws_size, int max_iter) const;

virtual ~CSMOSolver() = default;

protected:
void init_f(const SyncArray<float_type> &alpha, const SyncArray<int> &y, const KernelMatrix &k_mat,
SyncArray<float_type> &f_val) const;
Expand Down
1 change: 1 addition & 0 deletions include/thundersvm/solver/nusmosolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class NuSMOSolver : public CSMOSolver {
public:
explicit NuSMOSolver(bool for_svr) : for_svr(for_svr) {};
~NuSMOSolver() override = default;
protected:
float_type
calculate_rho(const SyncArray<float_type> &f_val, const SyncArray<int> &y, SyncArray<float_type> &alpha,
Expand Down
6 changes: 6 additions & 0 deletions include/thundersvm/util/metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ class Metric {
virtual string name() = 0;

virtual float_type score(const vector<float_type> &predict_y, const vector<float_type> &ground_truth_y) = 0;

virtual ~Metric() = default;
};

/**
* @brief Accuracy
*/
class Accuracy : public Metric {
public:
~Accuracy() override = default;
string name() override;

/**
Expand All @@ -36,6 +40,8 @@ class Accuracy : public Metric {
* @brief Mean Squared Error
*/
class MSE : public Metric {
public:
~MSE() override = default;
string name() override;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/thundersvm/svm_R_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ extern "C" {
if (metric) {
std::cout << metric->name() << " = " << metric->score(predict_y, train_dataset.y()) << std::endl;
}
delete metric;
}
delete model;
return succeed;
// model->train(train_dataset, param_cmd);
// model->save_to_file(model_file_path);
Expand Down Expand Up @@ -333,5 +335,7 @@ extern "C" {
if (metric) {
LOG(INFO) << metric->name() << " = " << metric->score(predict_y, predict_dataset.y());
}
delete model;
delete metric;
}
}
10 changes: 7 additions & 3 deletions src/thundersvm/svm_interface_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ extern "C" {
if (metric) {
LOG(INFO) << metric->name() << " = " << metric->score(predict_y, train_dataset.y()) << std::endl;
}
delete model;
delete metric;
return;
}
void thundersvm_train(int argc, char **argv) {
Expand All @@ -97,7 +99,7 @@ extern "C" {
parser.param_cmd.kernel_type = SvmParam::RBF;
parser.param_cmd.C = 100;
parser.param_cmd.gamma = 0;
parser.param_cmd.nu = 0.1;
parser.param_cmd.nu = 0.1;
parser.param_cmd.epsilon = 0.001;
*/
DataSet train_dataset;
Expand Down Expand Up @@ -155,6 +157,8 @@ extern "C" {
if (metric) {
LOG(INFO) << metric->name() << " = " << metric->score(predict_y, predict_dataset.y());
}
delete model;
delete metric;
}

void thundersvm_predict(int argc, char **argv){
Expand All @@ -174,11 +178,11 @@ extern "C" {
predict_dataset.load_from_file(predict_file_path);
thundersvm_predict_sub(predict_dataset, parser, model_file_path, output_file_path);
}

void load_from_python_interface(float *y, char **x, int len){
dataset_python.load_from_python(y, x, len);
}

void thundersvm_train_after_parse(char **option, int len, char *file_name){
CMDParser parser;
parser.parse_python(len, option);
Expand Down

0 comments on commit 831a8c4

Please sign in to comment.