Skip to content

Commit

Permalink
class members with the parameter names (#5042) (#5094)
Browse files Browse the repository at this point in the history
* class members with the parameter names (#5042)

* WeightedMajorityVote, Clustering, CrossValidation

* GradientEval, MachineEval, MulticlassOVRE

* SigmoidCalibra, SplittingStrat, TimeSeries

* Cross Validation fix

* removing m prefix
  • Loading branch information
JasonSurendran committed Jul 15, 2020
1 parent 6351bcb commit c964c9d
Show file tree
Hide file tree
Showing 22 changed files with 103 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/shogun/ensemble/WeightedMajorityVote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@ void WeightedMajorityVote::init()

void WeightedMajorityVote::register_parameters()
{
SG_ADD(&m_weights, "weights", "Weights for the majority vote", ParameterProperties::HYPER);
SG_ADD(&m_weights, kWeights, "Weights for the majority vote", ParameterProperties::HYPER);
}
4 changes: 4 additions & 0 deletions src/shogun/ensemble/WeightedMajorityVote.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ namespace shogun
private:
void init();
void register_parameters();
#ifndef SWIG
public:
static constexpr std::string_view kWeights = "weights";
#endif
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/shogun/evaluation/ClusteringEvaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace std;
ClusteringEvaluation::ClusteringEvaluation() : Evaluation()
{
m_use_best_map = true;
SG_ADD(&m_use_best_map, "use_best_map",
SG_ADD(&m_use_best_map, kBestMap,
"Find best match between predicted labels and the ground truth");
}

Expand Down
5 changes: 5 additions & 0 deletions src/shogun/evaluation/ClusteringEvaluation.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class ClusteringEvaluation: public Evaluation
// A flag to find best match between predicted labels and the ground truth
// before evaluation
bool m_use_best_map;

#ifndef SWIG
public:
static constexpr std::string_view kBestMap = "use_best_map";
#endif
};

} // namespace shogun
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/evaluation/CrossValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void CrossValidation::init()
{
m_num_runs = 1;

SG_ADD(&m_num_runs, "num_runs", "Number of repetitions");
SG_ADD(&m_num_runs, kNumRuns, "Number of repetitions");
}

std::shared_ptr<EvaluationResult> CrossValidation::evaluate_impl() const
Expand Down
5 changes: 5 additions & 0 deletions src/shogun/evaluation/CrossValidation.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ namespace shogun

/** number of evaluation runs for one fold */
int32_t m_num_runs;

#ifndef SWIG
public:
static constexpr std::string_view kNumRuns = "num_runs";
#endif
};
}

Expand Down
22 changes: 11 additions & 11 deletions src/shogun/evaluation/CrossValidationStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,28 @@ using namespace shogun;
CrossValidationFoldStorage::CrossValidationFoldStorage() : EvaluationResult()
{
SG_ADD(
&m_current_run_index, "run_index", "The current run index of this fold",
&m_current_run_index, kCurrentRunIndex, "The current run index of this fold",
ParameterProperties::HYPER);
SG_ADD(
&m_current_fold_index, "fold_index", "The current fold index",
&m_current_fold_index, kCurrentFoldIndex, "The current fold index",
ParameterProperties::HYPER);
SG_ADD(
&m_trained_machine, "trained_machine",
&m_trained_machine, kTrainedMachine,
"The machine trained by this fold", ParameterProperties::HYPER);
SG_ADD(
&m_test_result, "predicted_labels",
&m_test_result, kTestResult,
"The test result of this fold", ParameterProperties::HYPER);
SG_ADD(
&m_test_true_result, "ground_truth_labels",
&m_test_true_result, kTestTrueResult,
"The true test result for this fold", ParameterProperties::HYPER);
SG_ADD(
&m_train_indices, "train_indices", "Indices used for training",
&m_train_indices, kTrainIndices, "Indices used for training",
ParameterProperties::HYPER);
SG_ADD(
&m_test_indices, "test_indices", "Indices used for testing",
&m_test_indices, kTestIndices, "Indices used for testing",
ParameterProperties::HYPER);
SG_ADD(
&m_evaluation_result, "evaluation_result", "Result of the evaluation",
&m_evaluation_result, kEvalulationResult, "Result of the evaluation",
ParameterProperties::HYPER);
}

Expand All @@ -92,13 +92,13 @@ CrossValidationStorage::CrossValidationStorage() : EvaluationResult()
m_num_folds = 0;

SG_ADD(
&m_num_runs, "num_runs", "The total number of cross-validation runs",
&m_num_runs, kNumRuns, "The total number of cross-validation runs",
ParameterProperties::HYPER);
SG_ADD(
&m_num_folds, "num_folds", "The total number of cross-validation folds",
&m_num_folds, kNumFold, "The total number of cross-validation folds",
ParameterProperties::HYPER);
SG_ADD(
&m_original_labels, "labels",
&m_original_labels, kOriginalLabels,
"The labels used for this cross-validation",
ParameterProperties::HYPER);
this->watch_param(
Expand Down
19 changes: 19 additions & 0 deletions src/shogun/evaluation/CrossValidationStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ namespace shogun

/** Evaluation result for this fold */
float64_t m_evaluation_result{};

#ifndef SWIG
public:
static constexpr std::string_view kCurrentRunIndex = "run_index";
static constexpr std::string_view kCurrentFoldIndex = "fold_index";
static constexpr std::string_view kTrainedMachine = "trained_machine";
static constexpr std::string_view kTestResult = "predicted_labels";
static constexpr std::string_view kTestTrueResult = "ground_truth_labels";
static constexpr std::string_view kTrainIndices = "train_indices";
static constexpr std::string_view kTestIndices = "test_indices";
static constexpr std::string_view kEvalulationResult = "evaluation_result";
#endif
};

/**
Expand Down Expand Up @@ -156,6 +168,13 @@ namespace shogun

/** Vector with all the folds results */
std::vector<std::shared_ptr<EvaluationResult>> m_folds_results;

#ifndef SWIG
public:
static constexpr std::string_view kNumRuns = "num_runs";
static constexpr std::string_view kNumFold = "num_folds";
static constexpr std::string_view kOriginalLabels = "labels";
#endif
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/shogun/evaluation/GradientEvaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void GradientEvaluation::init()
m_diff=NULL;

SG_ADD(
&m_diff, "differentiable_function", "Differentiable function",
&m_diff, kDifferentiableFunction, "Differentiable function",
ParameterProperties::HYPER);
}

Expand Down
4 changes: 4 additions & 0 deletions src/shogun/evaluation/GradientEvaluation.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class GradientEvaluation: public MachineEvaluation

/** parameter dictionary of differentiable function */
mutable std::map<Parameters::value_type, std::shared_ptr<SGObject>> m_parameter_dictionary;
#ifndef SWIG
public:
static constexpr std::string_view kDifferentiableFunction = "differentiable_function";
#endif
};
}
#endif /* CGRADIENTEVALUATION_H_ */
10 changes: 5 additions & 5 deletions src/shogun/evaluation/MachineEvaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ void MachineEvaluation::init()
m_cancel_computation = false;
m_pause_computation_flag = false;

SG_ADD(&m_machine, "machine", "Used learning machine");
SG_ADD(&m_features, "features", "Used features");
SG_ADD(&m_labels, "labels", "Used labels");
SG_ADD(&m_splitting_strategy, "splitting_strategy",
SG_ADD(&m_machine, kMachine, "Used learning machine");
SG_ADD(&m_features, kFeatures, "Used features");
SG_ADD(&m_labels, kLabels, "Used labels");
SG_ADD(&m_splitting_strategy, kSplittingStrategy,
"Used splitting strategy");
SG_ADD(&m_evaluation_criterion, "evaluation_criterion",
SG_ADD(&m_evaluation_criterion, kEvaluationCriterion,
"Used evaluation criterion");
}

Expand Down
8 changes: 8 additions & 0 deletions src/shogun/evaluation/MachineEvaluation.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ namespace shogun

/** Criterion for evaluation */
std::shared_ptr<Evaluation> m_evaluation_criterion;
#ifndef SWIG
public:
static constexpr std::string_view kMachine = "machine";
static constexpr std::string_view kFeatures = "features";
static constexpr std::string_view kLabels = "labels";
static constexpr std::string_view kSplittingStrategy = "splitting_strategy";
static constexpr std::string_view kEvaluationCriterion = "evaluation_criterion";
#endif
};

} /* namespace shogun */
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/evaluation/MulticlassOVREvaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ MulticlassOVREvaluation::MulticlassOVREvaluation() :
MulticlassOVREvaluation::MulticlassOVREvaluation(const std::shared_ptr<BinaryClassEvaluation>& binary_evaluation) :
Evaluation(), m_binary_evaluation(nullptr), m_graph_results(nullptr), m_num_graph_results(0)
{
SG_ADD((std::shared_ptr<Evaluation>*)&m_binary_evaluation, "binary_evaluation", "binary evaluator")
SG_ADD((std::shared_ptr<Evaluation>*)&m_binary_evaluation, kBinaryEvaluation, "binary evaluator")
}

MulticlassOVREvaluation::~MulticlassOVREvaluation()
Expand Down
4 changes: 4 additions & 0 deletions src/shogun/evaluation/MulticlassOVREvaluation.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class MulticlassOVREvaluation: public Evaluation

/** number of graph results */
int32_t m_num_graph_results;
#ifndef SWIG
public:
static constexpr std::string_view kBinaryEvaluation = "binary_evaluation";
#endif

};

Expand Down
12 changes: 6 additions & 6 deletions src/shogun/evaluation/SigmoidCalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ void SigmoidCalibration::init()
m_epsilon = 1E-5;

SG_ADD(
&m_sigmoid_as, "m_sigmoid_as",
&m_sigmoid_as, kSigmoidAs,
"Vector of paramter A of sigmoid for each class.");
SG_ADD(
&m_sigmoid_bs, "m_sigmoid_bs",
&m_sigmoid_bs, kSigmoidBs,
"Vector of paramter B of sigmoid for each class.");
SG_ADD(
&m_maxiter, "m_maxiter", "Maximum number of iteration for search.");
&m_maxiter, kMaxiter, "Maximum number of iteration for search.");
SG_ADD(
&m_minstep, "m_minstep", "Minimum step taken in line search.");
&m_minstep, kMinstep, "Minimum step taken in line search.");
SG_ADD(
&m_sigma, "m_sigma",
&m_sigma, kSigma,
"Positive parameter to ensure positive semi-definite Hessian.");
SG_ADD(&m_epsilon, "m_epsilon", "Stopping criteria.");
SG_ADD(&m_epsilon, kEpsilon, "Stopping criteria.");
}

void SigmoidCalibration::set_maxiter(index_t maxiter)
Expand Down
9 changes: 9 additions & 0 deletions src/shogun/evaluation/SigmoidCalibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ namespace shogun
float64_t m_sigma;
/** Stopping criteria of search */
float64_t m_epsilon;
#ifndef SWIG
public:
static constexpr std::string_view kSigmoidAs = "sigmoid_as";
static constexpr std::string_view kSigmoidBs = "sigmoid_bs";
static constexpr std::string_view kMaxiter = "maxiter";
static constexpr std::string_view kMinstep = "minstep";
static constexpr std::string_view kSigma = "sigma";
static constexpr std::string_view kEpsilon = "epsilon";
#endif
};
}
#endif
8 changes: 4 additions & 4 deletions src/shogun/evaluation/SplittingStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ void SplittingStrategy::init()
m_is_filled=false;
m_num_subsets=0;

SG_ADD(&m_labels, "labels", "Labels for subsets");
SG_ADD(&m_labels, kLabels, "Labels for subsets");
SG_ADD(
&m_subset_indices, "subset_indices", "Set of sets of subset indices");
&m_subset_indices, kSubsetIndices, "Set of sets of subset indices");
SG_ADD(
&m_is_filled, "is_filled", "Whether ther are index sets");
&m_is_filled, kIsFilled, "Whether ther are index sets");
SG_ADD(
&m_num_subsets, "num_subsets", "Number of index sets");
&m_num_subsets, kSumSubsets, "Number of index sets");
}

SplittingStrategy::~SplittingStrategy()
Expand Down
7 changes: 7 additions & 0 deletions src/shogun/evaluation/SplittingStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ class SplittingStrategy: public SGObject
/** flag to check whether there is a set of index sets stored. If not,
* call build_subsets() */
bool m_is_filled;
#ifndef SWIG
public:
static constexpr std::string_view kLabels = "labels";
static constexpr std::string_view kSubsetIndices = "subset_indices";
static constexpr std::string_view kIsFilled = "is_filled";
static constexpr std::string_view kSumSubsets = "num_subsets";
#endif
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/shogun/evaluation/TimeSeriesSplitting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ TimeSeriesSplitting::TimeSeriesSplitting(std::shared_ptr<Labels> labels, index_t
void TimeSeriesSplitting::init()
{
m_min_subset_size = 1;
SG_ADD(&m_min_subset_size, "min_subset_size",
SG_ADD(&m_min_subset_size, kMinSubsetSize,
"The minimum subset size for test set");
}

Expand Down
5 changes: 5 additions & 0 deletions src/shogun/evaluation/TimeSeriesSplitting.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ namespace shogun

private:
void init();

#ifndef SWIG
public:
static constexpr std::string_view kMinSubsetSize = "min_subset_size";
#endif
};
}

Expand Down
1 change: 0 additions & 1 deletion src/shogun/neuralnets/DeepAutoencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,5 @@ void DeepAutoencoder::init()
"Pre-training L1 regularization coeff");
SG_ADD(&m_do_pretrain, "do_pretrain",
"Whether to pretrain with relevant parameters");

SG_ADD(&m_sigma, "m_sigma", "Initialization Sigma");
}
1 change: 1 addition & 0 deletions src/shogun/neuralnets/DeepAutoencoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class DeepAutoencoder : public Autoencoder
/** Standard deviation of the gaussian used to initialize the
* parameters */
float64_t m_sigma;

};
}
#endif

0 comments on commit c964c9d

Please sign in to comment.