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