SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 }

SHOGUN Machine Learning Toolbox - Documentation