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, (C) IDIAP                                //
16 // Contact <francois.fleuret@idiap.ch> for comments & bug reports        //
17 ///////////////////////////////////////////////////////////////////////////
18
19 #ifndef LOSS_MACHINE_H
20 #define LOSS_MACHINE_H
21
22 #include "misc.h"
23 #include "sample_set.h"
24
25 class LossMachine {
26   int _loss_type;
27
28 public:
29   LossMachine(int loss_type);
30
31   void get_loss_derivatives(SampleSet *samples,
32                             scalar_t *responses,
33                             scalar_t *derivatives);
34
35   scalar_t loss(SampleSet *samples, scalar_t *responses);
36
37   scalar_t optimal_weight(SampleSet *sample_set,
38                           scalar_t *weak_learner_responses,
39                           scalar_t *current_responses);
40
41   // This method returns in sample_nb_occurences[k] the number of time
42   // the example k was sampled, and in sample_responses[k] the
43   // consistent response so that the overall loss remains the same. If
44   // allow_duplicates is set to 1, all samples will have an identical
45   // response (i.e. weight), but some may have more than one
46   // occurence. On the contrary, if allow_duplicates is 0, samples
47   // will all have only one occurence (or zero) but the responses may
48   // vary to account for the multiple sampling.
49
50   void subsample(int nb, scalar_t *labels, scalar_t *responses,
51                  int nb_to_sample, int *sample_nb_occurences, scalar_t *sample_responses,
52                  int allow_duplicates);
53 };
54
55 #endif