Skip to content

Commit

Permalink
Merge pull request #366 from karlnapf/master
Browse files Browse the repository at this point in the history
added print_modsel_params method
  • Loading branch information
Soeren Sonnenburg committed Feb 3, 2012
2 parents 3a9377d + 269dbf9 commit 1778466
Show file tree
Hide file tree
Showing 18 changed files with 327 additions and 108 deletions.
Expand Up @@ -32,6 +32,11 @@ CModelSelectionParameters* create_param_tree()
c->build_values(1.0, 2.0, R_EXP);

CGaussianKernel* gaussian_kernel=new CGaussianKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
gaussian_kernel->print_modsel_params();

CModelSelectionParameters* param_gaussian_kernel=
new CModelSelectionParameters("kernel", gaussian_kernel);

Expand Down
Expand Up @@ -43,6 +43,11 @@ CModelSelectionParameters* create_param_tree()
c2->build_values(-1.0, 1.0, R_EXP);

CGaussianKernel* gaussian_kernel=new CGaussianKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
gaussian_kernel->print_modsel_params();

CModelSelectionParameters* param_gaussian_kernel=
new CModelSelectionParameters("kernel", gaussian_kernel);
CModelSelectionParameters* gaussian_kernel_width=
Expand All @@ -52,6 +57,11 @@ CModelSelectionParameters* create_param_tree()
root->append_child(param_gaussian_kernel);

CPowerKernel* power_kernel=new CPowerKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
power_kernel->print_modsel_params();

CModelSelectionParameters* param_power_kernel=
new CModelSelectionParameters("kernel", power_kernel);

Expand All @@ -63,6 +73,11 @@ CModelSelectionParameters* create_param_tree()
param_power_kernel->append_child(param_power_kernel_degree);

CMinkowskiMetric* m_metric=new CMinkowskiMetric(10);

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
m_metric->print_modsel_params();

CModelSelectionParameters* param_power_kernel_metric1=
new CModelSelectionParameters("distance", m_metric);

Expand Down Expand Up @@ -114,6 +129,10 @@ int main(int argc, char **argv)
splitting_strategy, evaluation_criterium);
cross->set_num_runs(1);

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
classifier->print_modsel_params();

/* model parameter selection, deletion is handled by modsel class (SG_UNREF) */
CModelSelectionParameters* param_tree=create_param_tree();
param_tree->print_tree();
Expand Down
14 changes: 14 additions & 0 deletions examples/undocumented/libshogun/modelselection_grid_search_krr.cpp
Expand Up @@ -37,6 +37,11 @@ CModelSelectionParameters* create_param_tree()
tau->build_values(-1.0, 1.0, R_EXP);

CGaussianKernel* gaussian_kernel=new CGaussianKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
gaussian_kernel->print_modsel_params();

CModelSelectionParameters* param_gaussian_kernel=
new CModelSelectionParameters("kernel", gaussian_kernel);
CModelSelectionParameters* gaussian_kernel_width=
Expand All @@ -46,6 +51,11 @@ CModelSelectionParameters* create_param_tree()
root->append_child(param_gaussian_kernel);

CPolyKernel* poly_kernel=new CPolyKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
poly_kernel->print_modsel_params();

CModelSelectionParameters* param_poly_kernel=
new CModelSelectionParameters("kernel", poly_kernel);

Expand Down Expand Up @@ -105,6 +115,10 @@ void test_cross_validation()
cross->set_num_runs(3);
cross->set_conf_int_alpha(0.05);

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
krr->print_modsel_params();

/* model parameter selection, deletion is handled by modsel class (SG_UNREF) */
CModelSelectionParameters* param_tree=create_param_tree();
param_tree->print_tree();
Expand Down
Expand Up @@ -79,6 +79,11 @@ int main(int argc, char **argv)
CCrossValidation* cross=new CCrossValidation(classifier, features, labels,
splitting_strategy, evaluation_criterium);

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
classifier->print_modsel_params();


/* model parameter selection, deletion is handled by modsel class (SG_UNREF) */
CModelSelectionParameters* param_tree=create_param_tree();
param_tree->print_tree();
Expand Down
Expand Up @@ -41,6 +41,12 @@ CModelSelectionParameters* create_param_tree()
c2->build_values(1.0, 2.0, R_EXP);

CDistantSegmentsKernel* ds_kernel=new CDistantSegmentsKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
ds_kernel->print_modsel_params();


CModelSelectionParameters* param_ds_kernel=
new CModelSelectionParameters("kernel", ds_kernel);
root->append_child(param_ds_kernel);
Expand Down Expand Up @@ -116,6 +122,10 @@ int main(int argc, char **argv)
splitting_strategy, evaluation_criterium);
cross->set_num_runs(2);

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
classifier->print_modsel_params();

/* model parameter selection, deletion is handled by modsel class (SG_UNREF) */
CModelSelectionParameters* param_tree=create_param_tree();
param_tree->print_tree();
Expand Down
Expand Up @@ -32,6 +32,11 @@ CModelSelectionParameters* build_complex_example_tree()
c->build_values(1.0, 1.0, R_EXP);

CPowerKernel* power_kernel=new CPowerKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
power_kernel->print_modsel_params();

CModelSelectionParameters* param_power_kernel=
new CModelSelectionParameters("kernel", power_kernel);

Expand All @@ -54,6 +59,11 @@ CModelSelectionParameters* build_complex_example_tree()
param_power_kernel_metric1->append_child(param_power_kernel_metric1_k);

CGaussianKernel* gaussian_kernel=new CGaussianKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
gaussian_kernel->print_modsel_params();

CModelSelectionParameters* param_gaussian_kernel=
new CModelSelectionParameters("kernel", gaussian_kernel);

Expand All @@ -65,6 +75,11 @@ CModelSelectionParameters* build_complex_example_tree()
param_gaussian_kernel->append_child(param_gaussian_kernel_width);

CDistantSegmentsKernel* ds_kernel=new CDistantSegmentsKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
ds_kernel->print_modsel_params();

CModelSelectionParameters* param_ds_kernel=new CModelSelectionParameters("kernel",
ds_kernel);

Expand Down Expand Up @@ -125,6 +140,11 @@ CModelSelectionParameters* build_root_sg_object_child_tree()
CModelSelectionParameters* root=new CModelSelectionParameters();

CPowerKernel* power_kernel=new CPowerKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
power_kernel->print_modsel_params();

CModelSelectionParameters* param_power_kernel=
new CModelSelectionParameters("kernel", power_kernel);

Expand All @@ -138,6 +158,11 @@ CModelSelectionParameters* build_root_sg_object_child_value_child_tree()
CModelSelectionParameters* root=new CModelSelectionParameters();

CPowerKernel* power_kernel=new CPowerKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
power_kernel->print_modsel_params();

CModelSelectionParameters* param_power_kernel=
new CModelSelectionParameters("kernel", power_kernel);

Expand Down
20 changes: 20 additions & 0 deletions examples/undocumented/libshogun/modelselection_parameter_tree.cpp
Expand Up @@ -32,6 +32,11 @@ CModelSelectionParameters* create_param_tree()
c->build_values(1, 2, R_EXP);

CPowerKernel* power_kernel=new CPowerKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
power_kernel->print_modsel_params();

CModelSelectionParameters* param_power_kernel=
new CModelSelectionParameters("kernel", power_kernel);

Expand All @@ -43,6 +48,11 @@ CModelSelectionParameters* create_param_tree()
param_power_kernel->append_child(param_power_kernel_degree);

CMinkowskiMetric* m_metric=new CMinkowskiMetric(10);

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
m_metric->print_modsel_params();

CModelSelectionParameters* param_power_kernel_metric1=
new CModelSelectionParameters("distance", m_metric);

Expand All @@ -54,6 +64,11 @@ CModelSelectionParameters* create_param_tree()
param_power_kernel_metric1->append_child(param_power_kernel_metric1_k);

CGaussianKernel* gaussian_kernel=new CGaussianKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
gaussian_kernel->print_modsel_params();

CModelSelectionParameters* param_gaussian_kernel=
new CModelSelectionParameters("kernel", gaussian_kernel);

Expand All @@ -65,6 +80,11 @@ CModelSelectionParameters* create_param_tree()
param_gaussian_kernel->append_child(param_gaussian_kernel_width);

CDistantSegmentsKernel* ds_kernel=new CDistantSegmentsKernel();

/* print all parameter available for modelselection
* Dont worry if yours is not included, simply write to the mailing list */
ds_kernel->print_modsel_params();

CModelSelectionParameters* param_ds_kernel=new CModelSelectionParameters("kernel",
ds_kernel);

Expand Down
@@ -0,0 +1,29 @@
from tools.load import LoadMatrix
from numpy import random
lm=LoadMatrix()

N = 100

random.seed(17)
ground_truth = abs(random.randn(N))
predicted = abs(random.randn(N))

parameter_list = [[ground_truth,predicted]]

def evaluation_meansquarederror_modular(ground_truth, predicted):
from shogun.Features import Labels
from shogun.Evaluation import MeanSquaredLogError

ground_truth_labels = Labels(ground_truth)
predicted_labels = Labels(predicted)

evaluator = MeanSquaredLogError()
mse = evaluator.evaluate(predicted_labels,ground_truth_labels)

return mse


if __name__=='__main__':
print 'MeanSquaredLogError'
evaluation_meansquarederror_modular(*parameter_list[0])

Expand Up @@ -62,17 +62,20 @@ def evaluation_cross_validation_classification(fm_train=traindat,fm_test=testdat
# for this toy example)
cross_validation.set_conf_int_alpha(0.05)

# print all parameter available for modelselection
# Dont worry if yours is not included but, write to the mailing list
predictor.print_modsel_params("\t")

# build parameter tree to select regularization parameter
param_tree_root=create_param_tree()


# model selection instance
model_selection=GridSearchModelSelection(param_tree_root,
cross_validation)

# perform model selection with selected methods
#print "performing model selection of"
print "parameter tree"
print "parameter tree:"
param_tree_root.print_tree()

print "starting model selection"
Expand Down Expand Up @@ -110,6 +113,11 @@ def create_param_tree():

# gaussian kernel with width
gaussian_kernel=GaussianKernel()

# print all parameter available for modelselection
# Dont worry if yours is not included but, write to the mailing list
gaussian_kernel.print_modsel_params()

param_gaussian_kernel=ModelSelectionParameters("kernel", gaussian_kernel)
gaussian_kernel_width=ModelSelectionParameters("width");
gaussian_kernel_width.build_values(5.0, 8.0, R_EXP, 1.0, 2.0)
Expand All @@ -118,6 +126,11 @@ def create_param_tree():

# polynomial kernel with degree
poly_kernel=PolyKernel()

# print all parameter available for modelselection
# Dont worry if yours is not included but, write to the mailing list
poly_kernel.print_modsel_params()

param_poly_kernel=ModelSelectionParameters("kernel", poly_kernel)

root.append_child(param_poly_kernel)
Expand Down

0 comments on commit 1778466

Please sign in to comment.