Skip to content

Commit

Permalink
use SG_ADD rather than m_parameter->add
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Apr 15, 2018
1 parent d747ae8 commit 3b2b243
Show file tree
Hide file tree
Showing 34 changed files with 187 additions and 164 deletions.
25 changes: 13 additions & 12 deletions src/shogun/classifier/PluginEstimate.cpp
Expand Up @@ -20,18 +20,19 @@ CPluginEstimate::CPluginEstimate(float64_t pos_pseudo, float64_t neg_pseudo)
: CMachine(), m_pos_pseudo(1e-10), m_neg_pseudo(1e-10),
pos_model(NULL), neg_model(NULL), features(NULL)
{
m_parameters->add(&m_pos_pseudo,
"pos_pseudo","pseudo count for positive class");
m_parameters->add(&m_neg_pseudo,
"neg_pseudo", "pseudo count for negative class");

m_parameters->add((CSGObject**) &pos_model,
"pos_model", "LinearHMM modelling positive class.");
m_parameters->add((CSGObject**) &neg_model,
"neg_model", "LinearHMM modelling negative class.");

m_parameters->add((CSGObject**) &features,
"features", "String Features.");
SG_ADD(
&m_pos_pseudo, "pos_pseudo", "pseudo count for positive class",
MS_NOT_AVAILABLE);
SG_ADD(
&m_neg_pseudo, "neg_pseudo", "pseudo count for negative class",
MS_NOT_AVAILABLE);
SG_ADD(
&pos_model, "pos_model", "LinearHMM modelling positive class.",
MS_NOT_AVAILABLE);
SG_ADD(
&neg_model, "neg_model", "LinearHMM modelling negative class.",
MS_NOT_AVAILABLE);
SG_ADD(&features, "features", "String Features.", MS_NOT_AVAILABLE);
}

CPluginEstimate::~CPluginEstimate()
Expand Down
7 changes: 4 additions & 3 deletions src/shogun/classifier/svm/OnlineLibLinear.cpp
Expand Up @@ -63,9 +63,10 @@ void COnlineLibLinear::init()
Cn=1;
use_bias=false;

m_parameters->add(&C1, "C1", "C Cost constant 1.");
m_parameters->add(&C2, "C2", "C Cost constant 2.");
m_parameters->add(&use_bias, "use_bias", "Indicates if bias is used.");
SG_ADD(&C1, "C1", "C Cost constant 1.", MS_AVAILABLE);
SG_ADD(&C2, "C2", "C Cost constant 2.", MS_AVAILABLE);
SG_ADD(
&use_bias, "use_bias", "Indicates if bias is used.", MS_NOT_AVAILABLE);

PG = 0;
PGmax_old = CMath::INFTY;
Expand Down
23 changes: 13 additions & 10 deletions src/shogun/classifier/svm/OnlineSVMSGD.cpp
Expand Up @@ -204,14 +204,17 @@ void COnlineSVMSGD::init()
loss=new CHingeLoss();
SG_REF(loss);

m_parameters->add(&C1, "C1", "Cost constant 1.");
m_parameters->add(&C2, "C2", "Cost constant 2.");
m_parameters->add(&lambda, "lambda", "Regularization parameter.");
m_parameters->add(&wscale, "wscale", "W scale");
m_parameters->add(&bscale, "bscale", "b scale");
m_parameters->add(&epochs, "epochs", "epochs");
m_parameters->add(&skip, "skip", "skip");
m_parameters->add(&count, "count", "count");
m_parameters->add(&use_bias, "use_bias", "Indicates if bias is used.");
m_parameters->add(&use_regularized_bias, "use_regularized_bias", "Indicates if bias is regularized.");
SG_ADD(&C1, "C1", "Cost constant 1.", MS_AVAILABLE);
SG_ADD(&C2, "C2", "Cost constant 2.", MS_AVAILABLE);
SG_ADD(&lambda, "lambda", "Regularization parameter.", MS_AVAILABLE);
SG_ADD(&wscale, "wscale", "W scale", MS_NOT_AVAILABLE);
SG_ADD(&bscale, "bscale", "b scale", MS_NOT_AVAILABLE);
SG_ADD(&epochs, "epochs", "epochs", MS_NOT_AVAILABLE);
SG_ADD(&skip, "skip", "skip", MS_NOT_AVAILABLE);
SG_ADD(&count, "count", "count", MS_NOT_AVAILABLE);
SG_ADD(
&use_bias, "use_bias", "Indicates if bias is used.", MS_NOT_AVAILABLE);
SG_ADD(
&use_regularized_bias, "use_regularized_bias",
"Indicates if bias is regularized.", MS_NOT_AVAILABLE);
}
10 changes: 5 additions & 5 deletions src/shogun/classifier/svm/SGDQN.cpp
Expand Up @@ -224,9 +224,9 @@ void CSGDQN::init()
loss=new CHingeLoss();
SG_REF(loss);

m_parameters->add(&C1, "C1", "Cost constant 1.");
m_parameters->add(&C2, "C2", "Cost constant 2.");
m_parameters->add(&epochs, "epochs", "epochs");
m_parameters->add(&skip, "skip", "skip");
m_parameters->add(&count, "count", "count");
SG_ADD(&C1, "C1", "Cost constant 1.", MS_AVAILABLE);
SG_ADD(&C2, "C2", "Cost constant 2.", MS_AVAILABLE);
SG_ADD(&epochs, "epochs", "epochs", MS_AVAILABLE);
SG_ADD(&skip, "skip", "skip", MS_NOT_AVAILABLE);
SG_ADD(&count, "count", "count", MS_NOT_AVAILABLE);
}
19 changes: 11 additions & 8 deletions src/shogun/classifier/svm/SVMOcas.cpp
Expand Up @@ -345,14 +345,17 @@ void CSVMOcas::init()

primal_objective = 0.0;

m_parameters->add(&C1, "C1", "Cost constant 1.");
m_parameters->add(&C2, "C2", "Cost constant 2.");
m_parameters->add(&use_bias, "use_bias",
"Indicates if bias is used.");
m_parameters->add(&epsilon, "epsilon", "Convergence precision.");
m_parameters->add(&bufsize, "bufsize", "Maximum number of cutting planes.");
m_parameters->add((machine_int_t*) &method, "method",
"SVMOcas solver type.");
SG_ADD(&C1, "C1", "Cost constant 1.", MS_AVAILABLE);
SG_ADD(&C2, "C2", "Cost constant 2.", MS_AVAILABLE);
SG_ADD(
&use_bias, "use_bias", "Indicates if bias is used.", MS_NOT_AVAILABLE);
SG_ADD(&epsilon, "epsilon", "Convergence precision.", MS_NOT_AVAILABLE);
SG_ADD(
&bufsize, "bufsize", "Maximum number of cutting planes.",
MS_NOT_AVAILABLE);
SG_ADD(
(machine_int_t*)&method, "method", "SVMOcas solver type.",
MS_NOT_AVAILABLE);
}

float64_t CSVMOcas::compute_primal_objective() const
Expand Down
4 changes: 3 additions & 1 deletion src/shogun/clustering/GMM.cpp
Expand Up @@ -822,6 +822,8 @@ void CGMM::register_params()
{
//TODO serialization broken
//m_parameters->add((SGVector<CSGObject*>*) &m_components, "m_components", "Mixture components");
m_parameters->add(&m_coefficients, "m_coefficients", "Mixture coefficients.");
SG_ADD(
&m_coefficients, "m_coefficients", "Mixture coefficients.",
MS_NOT_AVAILABLE);
}

3 changes: 1 addition & 2 deletions src/shogun/converter/HashedDocConverter.cpp
Expand Up @@ -65,8 +65,7 @@ void CHashedDocConverter::init(CTokenizer* tzer, int32_t hash_bits, bool normali
MS_NOT_AVAILABLE);
SG_ADD(&should_normalize, "should_normalize", "Whether to normalize vectors or not",
MS_NOT_AVAILABLE);
m_parameters->add((CSGObject**) &tokenizer, "tokenizer",
"Tokenizer");
SG_ADD(&tokenizer, "tokenizer", "Tokenizer", MS_NOT_AVAILABLE);
}

const char* CHashedDocConverter::get_name() const
Expand Down
4 changes: 3 additions & 1 deletion src/shogun/distance/AttenuatedEuclideanDistance.cpp
Expand Up @@ -66,5 +66,7 @@ void CAttenuatedEuclideanDistance::init()
{
disable_sqrt=false;

m_parameters->add(&disable_sqrt, "disable_sqrt", "If sqrt shall not be applied.");
SG_ADD(
&disable_sqrt, "disable_sqrt", "If sqrt shall not be applied.",
MS_NOT_AVAILABLE);
}
7 changes: 5 additions & 2 deletions src/shogun/distance/CustomDistance.cpp
Expand Up @@ -123,9 +123,12 @@ void CCustomDistance::init()
upper_diagonal=false;

m_parameters->add_matrix(&dmatrix, &num_rows, &num_cols, "dmatrix", "Distance Matrix");
watch_param("dmatrix", &dmatrix, &num_rows, &num_cols);
watch_param(
"dmatrix", &dmatrix, &num_rows, &num_cols,
AnyParameterProperties("Distance Matrix"));

m_parameters->add(&upper_diagonal, "upper_diagonal", "Upper diagonal");
SG_ADD(
&upper_diagonal, "upper_diagonal", "Upper diagonal", MS_NOT_AVAILABLE);
}

void CCustomDistance::cleanup()
Expand Down
10 changes: 6 additions & 4 deletions src/shogun/distance/Distance.cpp
Expand Up @@ -259,10 +259,12 @@ void CDistance::init()
num_lhs=0;
num_rhs=0;

m_parameters->add((CSGObject**) &lhs, "lhs",
"Feature vectors to occur on left hand side.");
m_parameters->add((CSGObject**) &rhs, "rhs",
"Feature vectors to occur on right hand side.");
SG_ADD(
&lhs, "lhs", "Feature vectors to occur on left hand side.",
MS_NOT_AVAILABLE);
SG_ADD(
&rhs, "rhs", "Feature vectors to occur on right hand side.",
MS_NOT_AVAILABLE);
}

template <class T>
Expand Down
5 changes: 3 additions & 2 deletions src/shogun/distance/HammingWordDistance.cpp
Expand Up @@ -169,6 +169,7 @@ float64_t CHammingWordDistance::compute(int32_t idx_a, int32_t idx_b)
void CHammingWordDistance::init()
{
use_sign = false;
m_parameters->add(&use_sign, "use_sign",
"If signum(counts) is used instead of counts.");
SG_ADD(
&use_sign, "use_sign", "If signum(counts) is used instead of counts.",
MS_NOT_AVAILABLE);
}
5 changes: 2 additions & 3 deletions src/shogun/distance/KernelDistance.cpp
Expand Up @@ -69,7 +69,6 @@ void CKernelDistance::init()
kernel = NULL;
width = 0.0;

m_parameters->add(&width, "width", "Width of RBF Kernel");
m_parameters->add((CSGObject**) &kernel, "kernel",
"Kernel.");
SG_ADD(&width, "width", "Width of RBF Kernel", MS_AVAILABLE);
SG_ADD(&kernel, "kernel", "Kernel.", MS_NOT_AVAILABLE);
}
10 changes: 8 additions & 2 deletions src/shogun/distance/MahalanobisDistance.cpp
Expand Up @@ -110,7 +110,13 @@ void CMahalanobisDistance::init()
disable_sqrt=false;
use_mean=false;

m_parameters->add(&disable_sqrt, "disable_sqrt", "If sqrt shall not be applied.");
m_parameters->add(&use_mean, "use_mean", "If distance shall be computed between mean vector and vector from rhs or between lhs and rhs.");
SG_ADD(
&disable_sqrt, "disable_sqrt", "If sqrt shall not be applied.",
MS_NOT_AVAILABLE);
SG_ADD(
&use_mean, "use_mean", "If distance shall be computed between mean "
"vector and vector from rhs or between lhs and "
"rhs.",
MS_NOT_AVAILABLE);
}

10 changes: 5 additions & 5 deletions src/shogun/distributions/PositionalPWM.cpp
Expand Up @@ -124,11 +124,11 @@ void CPositionalPWM::compute_w(int32_t num_pos)

void CPositionalPWM::register_params()
{
m_parameters->add(&m_poim, "poim", "POIM Scoring Matrix");
m_parameters->add(&m_w, "w", "Scoring Matrix");
m_parameters->add(&m_pwm, "pwm", "Positional Weight Matrix.");
m_parameters->add(&m_sigma, "sigma", "Standard Deviation.");
m_parameters->add(&m_mean, "mean", "Mean.");
SG_ADD(&m_poim, "poim", "POIM Scoring Matrix", MS_NOT_AVAILABLE);
SG_ADD(&m_w, "w", "Scoring Matrix", MS_NOT_AVAILABLE);
SG_ADD(&m_pwm, "pwm", "Positional Weight Matrix.", MS_NOT_AVAILABLE);
SG_ADD(&m_sigma, "sigma", "Standard Deviation.", MS_NOT_AVAILABLE);
SG_ADD(&m_mean, "mean", "Mean.", MS_NOT_AVAILABLE);
}

void CPositionalPWM::compute_scoring(int32_t max_degree)
Expand Down
15 changes: 10 additions & 5 deletions src/shogun/evaluation/SplittingStrategy.cpp
Expand Up @@ -56,11 +56,16 @@ void CSplittingStrategy::init()
m_is_filled=false;
m_num_subsets=0;

m_parameters->add((CSGObject**)&m_labels, "labels", "Labels for subsets");
m_parameters->add((CSGObject**)&m_subset_indices, "subset_indices",
"Set of sets of subset indices");
m_parameters->add(&m_is_filled, "is_filled", "Whether ther are index sets");
m_parameters->add(&m_num_subsets, "num_subsets", "Number of index sets");
SG_ADD(&m_labels, "labels", "Labels for subsets", MS_NOT_AVAILABLE);
SG_ADD(
&m_subset_indices, "subset_indices", "Set of sets of subset indices",
MS_NOT_AVAILABLE);
SG_ADD(
&m_is_filled, "is_filled", "Whether ther are index sets",
MS_NOT_AVAILABLE);
SG_ADD(
&m_num_subsets, "num_subsets", "Number of index sets",
MS_NOT_AVAILABLE);
}

CSplittingStrategy::~CSplittingStrategy()
Expand Down
12 changes: 5 additions & 7 deletions src/shogun/features/Alphabet.cpp
Expand Up @@ -726,13 +726,11 @@ void CAlphabet::init()
memset(maptable_to_char, 0, sizeof (maptable_to_char));
memset(histogram, 0, sizeof (histogram));


m_parameters->add((machine_int_t*) &alphabet, "alphabet",
"Alphabet enum.");
m_parameters->add(&num_symbols, "num_symbols",
"Number of symbols.");
m_parameters->add(&num_bits, "num_bits",
"Number of bits.");
SG_ADD(
(machine_int_t*)&alphabet, "alphabet", "Alphabet enum.",
MS_NOT_AVAILABLE);
SG_ADD(&num_symbols, "num_symbols", "Number of symbols.", MS_NOT_AVAILABLE);
SG_ADD(&num_bits, "num_bits", "Number of bits.", MS_NOT_AVAILABLE);

/* We don't need to serialize the mapping tables / they can be computed
* after de-serializing. Lets not serialize the histogram for now. Doesn't
Expand Down
13 changes: 7 additions & 6 deletions src/shogun/features/CombinedDotFeatures.cpp
Expand Up @@ -341,11 +341,12 @@ void CCombinedDotFeatures::set_subfeature_weights(SGVector<float64_t> weights)

void CCombinedDotFeatures::init()
{
m_parameters->add(&num_dimensions, "num_dimensions",
"Total number of dimensions.");
m_parameters->add(&num_vectors, "num_vectors",
"Total number of vectors.");
m_parameters->add((CSGObject**) &feature_array,
"feature_array", "Feature array.");
SG_ADD(
&num_dimensions, "num_dimensions", "Total number of dimensions.",
MS_NOT_AVAILABLE);
SG_ADD(
&num_vectors, "num_vectors", "Total number of vectors.",
MS_NOT_AVAILABLE);
SG_ADD(&feature_array, "feature_array", "Feature array.", MS_NOT_AVAILABLE);
}

5 changes: 3 additions & 2 deletions src/shogun/features/DotFeatures.cpp
Expand Up @@ -406,6 +406,7 @@ SGMatrix<float64_t> CDotFeatures::compute_cov(
void CDotFeatures::init()
{
set_property(FP_DOT);
m_parameters->add(&combined_weight, "combined_weight",
"Feature weighting in combined dot features.");
SG_ADD(
&combined_weight, "combined_weight",
"Feature weighting in combined dot features.", MS_NOT_AVAILABLE);
}
5 changes: 3 additions & 2 deletions src/shogun/features/DummyFeatures.cpp
Expand Up @@ -46,6 +46,7 @@ EFeatureClass CDummyFeatures::get_feature_class() const

void CDummyFeatures::init()
{
m_parameters->add(&num_vectors, "num_vectors",
"Number of feature vectors.");
SG_ADD(
&num_vectors, "num_vectors", "Number of feature vectors.",
MS_NOT_AVAILABLE);
}
2 changes: 1 addition & 1 deletion src/shogun/features/FKFeatures.cpp
Expand Up @@ -255,5 +255,5 @@ void CFKFeatures::init()
//TODO serialize HMMs
//m_parameters->add((CSGObject**) &pos, "pos", "HMM for positive class.");
//m_parameters->add((CSGObject**) &neg, "neg", "HMM for negative class.");
m_parameters->add(&weight_a, "weight_a", "Class prior.");
SG_ADD(&weight_a, "weight_a", "Class prior.", MS_NOT_AVAILABLE);
}
21 changes: 13 additions & 8 deletions src/shogun/features/PolyFeatures.cpp
Expand Up @@ -376,14 +376,19 @@ CFeatures* CPolyFeatures::duplicate() const

void CPolyFeatures::register_parameters()
{
m_parameters->add((CSGObject**) &m_feat, "features",
"Features in original space.");
m_parameters->add(&m_degree, "degree", "Degree of the polynomial kernel.");
m_parameters->add(&m_normalize, "normalize", "Normalize?");
m_parameters->add(&m_input_dimensions, "input_dimensions",
"Dimensions of the input space.");
m_parameters->add(&m_output_dimensions, "output_dimensions",
"Dimensions of the feature space of the polynomial kernel.");
SG_ADD(
(CSGObject**)&m_feat, "features", "Features in original space.",
MS_NOT_AVAILABLE);
SG_ADD(
&m_degree, "degree", "Degree of the polynomial kernel.", MS_AVAILABLE);
SG_ADD(&m_normalize, "normalize", "Normalize?", MS_NOT_AVAILABLE);
SG_ADD(
&m_input_dimensions, "input_dimensions",
"Dimensions of the input space.", MS_NOT_AVAILABLE);
SG_ADD(
&m_output_dimensions, "output_dimensions",
"Dimensions of the feature space of the polynomial kernel.",
MS_NOT_AVAILABLE);

multi_index_length=m_output_dimensions*m_degree;
m_parameters->add_vector(
Expand Down
5 changes: 3 additions & 2 deletions src/shogun/features/RandomFourierDotFeatures.cpp
Expand Up @@ -54,8 +54,9 @@ void CRandomFourierDotFeatures::init(KernelName kernel_name, SGVector<float64_t>
kernel_params = params;

constant = num_samples > 0 ? std::sqrt(2.0 / num_samples) : 1;
m_parameters->add(&kernel_params, "kernel_params",
"The parameters of the kernel to approximate");
SG_ADD(
&kernel_params, "kernel_params",
"The parameters of the kernel to approximate", MS_NOT_AVAILABLE);
SG_ADD((machine_int_t* ) &kernel, "kernel",
"The kernel to approximate", MS_NOT_AVAILABLE);
SG_ADD(&constant, "constant", "A constant needed",
Expand Down
4 changes: 3 additions & 1 deletion src/shogun/features/RandomKitchenSinksDotFeatures.cpp
Expand Up @@ -75,7 +75,9 @@ void CRandomKitchenSinksDotFeatures::init(CDotFeatures* dataset,

SG_ADD((CSGObject** ) &feats, "feats", "Features to work on",
MS_NOT_AVAILABLE);
m_parameters->add(&random_coeff, "random_coeff", "Random function parameters");
SG_ADD(
&random_coeff, "random_coeff", "Random function parameters",
MS_NOT_AVAILABLE);
}

int32_t CRandomKitchenSinksDotFeatures::get_dim_feature_space() const
Expand Down

0 comments on commit 3b2b243

Please sign in to comment.