Last active
July 24, 2017 16:24
-
-
Save geektoni/f376b5c411dca9be884734dae7ee6354 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51 | |
#1 0x00007ffff0ea13fa in __GI_abort () at abort.c:89 | |
#2 0x00007ffff0eddbd0 in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7ffff0fd2dd0 "*** Error in `%s': %s: 0x%s ***\n") | |
at ../sysdeps/posix/libc_fatal.c:175 | |
#3 0x00007ffff0ee3f96 in malloc_printerr (action=3, str=0x7ffff0fd31d8 "malloc(): memory corruption (fast)", ptr=<optimized out>, | |
ar_ptr=<optimized out>) at malloc.c:5049 | |
#4 0x00007ffff0ee6461 in _int_malloc (av=av@entry=0x7ffff1206b00 <main_arena>, bytes=bytes@entry=7) at malloc.c:3424 | |
#5 0x00007ffff0ee7f34 in __GI___libc_malloc (bytes=7) at malloc.c:2928 | |
#6 0x00007ffff5df91da in (anonymous namespace)::sg_malloc (size=7) at /home/geektoni/shogun/src/shogun/lib/memory.cpp:205 | |
#7 0x00007ffff584fe19 in (anonymous namespace)::sg_generic_malloc<unsigned char> (len=7) at /home/geektoni/shogun/src/shogun/lib/memory.h:91 | |
#8 0x00007ffff5e032ca in (anonymous namespace)::get_copy (src=0x7ffff6c15de6, len=7) at /home/geektoni/shogun/src/shogun/lib/memory.cpp:446 | |
#9 0x00007ffff5e0333c in (anonymous namespace)::get_strdup (str=0x7ffff6c15de6 "subset") | |
at /home/geektoni/shogun/src/shogun/lib/memory.cpp:456 | |
#10 0x00007ffff58471ca in (anonymous namespace)::TParameter::TParameter (this=0x5555557fb9c0, datatype=0x7fffffffd5e0, | |
parameter=0x5555557fa410, name=0x7ffff6c15de6 "subset", description=0x7ffff6c15dcd "Vector of subset indices") | |
at /home/geektoni/shogun/src/shogun/base/Parameter.cpp:1788 | |
#11 0x00007ffff584a70e in (anonymous namespace)::Parameter::add_type (this=0x5555557f96e0, type=0x7fffffffd5e0, param=0x5555557fa410, | |
name=0x7ffff6c15de6 "subset", description=0x7ffff6c15dcd "Vector of subset indices") | |
at /home/geektoni/shogun/src/shogun/base/Parameter.cpp:2758 | |
#12 0x00007ffff5843369 in (anonymous namespace)::Parameter::add (this=0x5555557f96e0, param=0x5555557fa3f8, name=0x7ffff6c15de6 "subset", | |
description=0x7ffff6c15dcd "Vector of subset indices") at /home/geektoni/shogun/src/shogun/base/Parameter.cpp:692 | |
#13 0x00007ffff5b63d08 in (anonymous namespace)::CSubset::init (this=0x5555557fa380) at /home/geektoni/shogun/src/shogun/features/Subset.cpp:34 | |
#14 0x00007ffff5b63c23 in (anonymous namespace)::CSubset::CSubset (this=0x5555557fa380, subset_idx=<incomplete type>) | |
at /home/geektoni/shogun/src/shogun/features/Subset.cpp:23 | |
#15 0x00007ffff5b64446 in (anonymous namespace)::CSubsetStack::add_subset (this=0x5555557ab500, subset=<incomplete type>) | |
at /home/geektoni/shogun/src/shogun/features/SubsetStack.cpp:140 | |
#16 0x00007ffff5cb1d36 in (anonymous namespace)::CCustomKernel::add_col_subset (this=0x5555557a9420, subset=<incomplete type>) | |
at /home/geektoni/shogun/src/shogun/kernel/CustomKernel.cpp:416 | |
#17 0x00007ffff5ee904a in (anonymous namespace)::CKernelMachine::train_locked (this=0x5555557a23e0, indices=<incomplete type>) | |
at /home/geektoni/shogun/src/shogun/machine/KernelMachine.cpp:451 | |
#18 0x00007ffff5a31685 in (anonymous namespace)::CCrossValidation::evaluate_one_run (this=0x5555557a8140, index=0, storage=0x7fffffffdf20) | |
at /home/geektoni/shogun/src/shogun/evaluation/CrossValidation.cpp:192 | |
#19 0x00007ffff5a31006 in (anonymous namespace)::CCrossValidation::evaluate (this=0x5555557a8140) | |
at /home/geektoni/shogun/src/shogun/evaluation/CrossValidation.cpp:124 | |
#20 0x000055555555a6f6 in test_cross_validation () at evaluation.cpp:102 | |
#21 0x000055555555ab10 in main (argc=1, argv=0x7fffffffe4c8) at evaluation.cpp:133 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This program is free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* Written (W) 2012 Heiko Strathmann | |
* Copyright (C) 2012 Berlin Institute of Technology and Max-Planck-Society | |
*/ | |
#include <shogun/base/init.h> | |
#include <shogun/features/DenseFeatures.h> | |
#include <shogun/labels/RegressionLabels.h> | |
#include <shogun/kernel/LinearKernel.h> | |
#include <shogun/regression/KernelRidgeRegression.h> | |
#include <shogun/evaluation/CrossValidation.h> | |
#include <shogun/evaluation/CrossValidationSplitting.h> | |
#include <shogun/evaluation/MeanSquaredError.h> | |
#include <shogun/lib/parameter_observers/ParameterObserverCV.h> | |
using namespace shogun; | |
void print_message(FILE* target, const char* str) | |
{ | |
fprintf(target, "%s", str); | |
} | |
void test_cross_validation() | |
{ | |
#ifdef HAVE_LAPACK | |
/* data matrix dimensions */ | |
index_t num_vectors=100; | |
index_t num_features=1; | |
/* training label data */ | |
SGVector<float64_t> lab(num_vectors); | |
/* fill data matrix and labels */ | |
SGMatrix<float64_t> train_dat(num_features, num_vectors); | |
SGVector<float64_t>::range_fill_vector(train_dat.matrix, num_vectors); | |
for (index_t i=0; i<num_vectors; ++i) | |
{ | |
/* labels are linear plus noise */ | |
lab.vector[i]=i+CMath::normal_random(0, 1.0); | |
} | |
/* training features */ | |
CDenseFeatures<float64_t>* features= | |
new CDenseFeatures<float64_t>(train_dat); | |
SG_REF(features); | |
/* training labels */ | |
CRegressionLabels* labels=new CRegressionLabels(lab); | |
/* kernel */ | |
CLinearKernel* kernel=new CLinearKernel(); | |
kernel->init(features, features); | |
/* kernel ridge regression*/ | |
float64_t tau=0.0001; | |
CKernelRidgeRegression* krr=new CKernelRidgeRegression(tau, kernel, labels); | |
/* evaluation criterion */ | |
CMeanSquaredError* eval_crit= | |
new CMeanSquaredError(); | |
/* train and output */ | |
krr->train(features); | |
CRegressionLabels* output= CLabelsFactory::to_regression(krr->apply()); | |
for (index_t i=0; i<num_vectors; ++i) | |
{ | |
SG_SPRINT("x=%f, train=%f, predict=%f\n", train_dat.matrix[i], | |
labels->get_label(i), output->get_label(i)); | |
} | |
/* evaluate training error */ | |
float64_t eval_result=eval_crit->evaluate(output, labels); | |
SG_SPRINT("training error: %f\n", eval_result); | |
SG_UNREF(output); | |
/* assert that regression "works". this is not guaranteed to always work | |
* but should be a really coarse check to see if everything is going | |
* approx. right */ | |
ASSERT(eval_result<2); | |
/* splitting strategy */ | |
index_t n_folds=5; | |
CCrossValidationSplitting* splitting= | |
new CCrossValidationSplitting(labels, n_folds); | |
/* cross validation instance, 100 runs, 95% confidence interval */ | |
CCrossValidation* cross=new CCrossValidation(krr, features, labels, | |
splitting, eval_crit); | |
cross->set_num_runs(100); | |
/* Create the parameter observer */ | |
ParameterObserverCV par; | |
cross->subscribe_to_parameters(&par); | |
/* actual evaluation */ | |
CCrossValidationResult* result=(CCrossValidationResult*)cross->evaluate(); | |
auto obs = par.get_observations(); | |
for (auto i : obs) | |
{ | |
//i.get_train_indices().display_vector(); | |
} | |
if (result->get_result_type() != CROSSVALIDATION_RESULT) | |
SG_SERROR("Evaluation result is not of type CCrossValidationResult!"); | |
SG_SPRINT("cross_validation estimate:\n"); | |
result->print_result(); | |
cross->list_observable_parameters(); | |
/* same crude assertion as for above evaluation */ | |
ASSERT(result->mean<2); | |
/* clean up */ | |
SG_UNREF(result); | |
SG_UNREF(cross); | |
SG_UNREF(features); | |
#endif /* HAVE_LAPACK */ | |
} | |
int main(int argc, char **argv) | |
{ | |
init_shogun(&print_message, &print_message, &print_message); | |
test_cross_validation(); | |
exit_shogun(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment