SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CrossValidationPrintOutput.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2012 Sergey Lisitsyn
8  * Written (W) 2012 Heiko Strathmann
9  */
10 
19 
20 using namespace shogun;
21 
23  const char* prefix)
24 {
25  SG_PRINT("%scross validation number of runs %d\n", prefix, num_runs)
26 }
27 
30  const char* prefix)
31 {
32  SG_PRINT("%scross validation number of folds %d\n", prefix, num_folds)
33 }
34 
36  const char* prefix)
37 {
38  SG_PRINT("%scross validation run %d\n", prefix, run_index)
39 }
40 
42  const char* prefix)
43 {
44  SG_PRINT("%sfold %d\n", prefix, fold_index)
45 }
46 
48  SGVector<index_t> indices, const char* prefix)
49 {
50  indices.display_vector("train_indices", prefix);
51 }
52 
54  SGVector<index_t> indices, const char* prefix)
55 {
56  indices.display_vector("test_indices", prefix);
57 }
58 
60  CMachine* machine, const char* prefix)
61 {
62  if (dynamic_cast<CLinearMachine*>(machine))
63  {
64  CLinearMachine* linear_machine=(CLinearMachine*)machine;
65  linear_machine->get_w().display_vector("learned_w", prefix);
66  SG_PRINT("%slearned_bias=%f\n", prefix, linear_machine->get_bias())
67  }
68 
69  if (dynamic_cast<CKernelMachine*>(machine))
70  {
71  CKernelMachine* kernel_machine=(CKernelMachine*)machine;
72  kernel_machine->get_alphas().display_vector("learned_alphas", prefix);
73  SG_PRINT("%slearned_bias=%f\n", prefix, kernel_machine->get_bias())
74  }
75 
76  if (dynamic_cast<CLinearMulticlassMachine*>(machine)
77  || dynamic_cast<CKernelMulticlassMachine*>(machine))
78  {
79  /* append one tab to prefix */
80  char* new_prefix=append_tab_to_string(prefix);
81 
82  CMulticlassMachine* mc_machine=(CMulticlassMachine*)machine;
83  for (int i=0; i<mc_machine->get_num_machines(); i++)
84  {
85  CMachine* sub_machine=mc_machine->get_machine(i);
86  //SG_PRINT("%smulti-class machine %d:\n", i, sub_machine)
87  this->update_trained_machine(sub_machine, new_prefix);
88  SG_UNREF(sub_machine);
89  }
90 
91  /* clean up */
92  SG_FREE(new_prefix);
93  }
94 
95  if (dynamic_cast<CMKL*>(machine))
96  {
97  CMKL* mkl=(CMKL*)machine;
98  CCombinedKernel* kernel=dynamic_cast<CCombinedKernel*>(
99  mkl->get_kernel());
100  kernel->get_subkernel_weights().display_vector("MKL sub-kernel weights",
101  prefix);
102  SG_UNREF(kernel);
103  }
104 
105  if (dynamic_cast<CMKLMulticlass*>(machine))
106  {
107  CMKLMulticlass* mkl=(CMKLMulticlass*)machine;
108  CCombinedKernel* kernel=dynamic_cast<CCombinedKernel*>(
109  mkl->get_kernel());
110  kernel->get_subkernel_weights().display_vector("MKL sub-kernel weights",
111  prefix);
112  SG_UNREF(kernel);
113  }
114 }
115 
117  const char* prefix)
118 {
119  results->get_values().display_vector("test_labels", prefix);
120 }
121 
123  const char* prefix)
124 {
125  results->get_values().display_vector("true_labels", prefix);
126 }
127 
129  const char* prefix)
130 {
131  SG_PRINT("%sevaluation result=%f\n", prefix, result)
132 }
133 
135 {
136  /* allocate memory, concatenate and add termination character */
137  index_t len=strlen(string);
138  char* new_prefix=SG_MALLOC(char, len+2);
139  memcpy(new_prefix, string, sizeof(char)*len);
140  new_prefix[len]='\t';
141  new_prefix[len+1]='\0';
142 
143  return new_prefix;
144 }
CMachine * get_machine(int32_t num) const
MKLMulticlass is a class for L1-norm Multiclass MKL.
Definition: MKLMulticlass.h:40
virtual void update_test_result(CLabels *results, const char *prefix="")
int32_t index_t
Definition: common.h:62
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual void update_test_true_result(CLabels *results, const char *prefix="")
virtual const float64_t * get_subkernel_weights(int32_t &num_weights)
A generic KernelMachine interface.
Definition: KernelMachine.h:51
A generic learning machine interface.
Definition: Machine.h:143
void display_vector(const char *name="vector", const char *prefix="") const
Definition: SGVector.cpp:354
virtual void update_test_indices(SGVector< index_t > indices, const char *prefix="")
#define SG_PRINT(...)
Definition: SGIO.h:137
virtual void update_train_indices(SGVector< index_t > indices, const char *prefix="")
double float64_t
Definition: common.h:50
experimental abstract generic multiclass machine class
The Combined kernel is used to combine a number of kernels into a single CombinedKernel object by lin...
Class LinearMachine is a generic interface for all kinds of linear machines like classifiers.
Definition: LinearMachine.h:63
Multiple Kernel Learning.
Definition: MKL.h:95
virtual void update_run_index(index_t run_index, const char *prefix="")
virtual SGVector< float64_t > get_w() const
virtual void init_num_folds(index_t num_folds, const char *prefix="")
virtual SGVector< float64_t > get_values()
Definition: Labels.cpp:90
virtual void update_fold_index(index_t fold_index, const char *prefix="")
SGVector< float64_t > get_alphas()
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual void update_trained_machine(CMachine *machine, const char *prefix="")
virtual float64_t get_bias()
virtual void init_num_runs(index_t num_runs, const char *prefix="")
virtual void update_evaluation_result(float64_t result, const char *prefix="")

SHOGUN Machine Learning Toolbox - Documentation