automatic commit
[folded-ctf.git] / loss_machine.h
1
2 ///////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify  //
4 // it under the terms of the version 3 of the GNU General Public License //
5 // as published by the Free Software Foundation.                         //
6 //                                                                       //
7 // This program is distributed in the hope that it will be useful, but   //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of            //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      //
10 // General Public License for more details.                              //
11 //                                                                       //
12 // You should have received a copy of the GNU General Public License     //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>.  //
14 //                                                                       //
15 // Written by Francois Fleuret                                           //
16 // (C) Idiap Research Institute                                          //
17 //                                                                       //
18 // Contact <francois.fleuret@idiap.ch> for comments & bug reports        //
19 ///////////////////////////////////////////////////////////////////////////
20
21 /*
22
23   A LossMachine provides all the methods necessary to do boosting with
24   a certain loss. Note that only the LOSS_EXPONENTIAL has been really
25   tested. Using the others may result in unexpected effects.
26
27  */
28
29 #ifndef LOSS_MACHINE_H
30 #define LOSS_MACHINE_H
31
32 #include "misc.h"
33 #include "sample_set.h"
34
35 class LossMachine {
36   int _loss_type;
37
38 public:
39   LossMachine(int loss_type);
40
41   void get_loss_derivatives(SampleSet *samples,
42                             scalar_t *responses,
43                             scalar_t *derivatives);
44
45   scalar_t loss(SampleSet *samples, scalar_t *responses);
46
47   scalar_t optimal_weight(SampleSet *sample_set,
48                           scalar_t *weak_learner_responses,
49                           scalar_t *current_responses);
50
51   /* This method returns in sample_nb_occurences[k] the number of time
52      the example k was sampled, and in sample_responses[k] the
53      consistent response so that the overall loss remains the same. If
54      allow_duplicates is set to 1, all samples will have an identical
55      response (i.e. weight), but some may have more than one
56      occurence. On the contrary, if allow_duplicates is 0, samples
57      will all have only one occurence (or zero) but the responses may
58      vary to account for the multiple sampling. */
59
60   void subsample(int nb, scalar_t *labels, scalar_t *responses,
61                  int nb_to_sample, int *sample_nb_occurences, scalar_t *sample_responses,
62                  int allow_duplicates);
63 };
64
65 #endif