Line data Source code
1 : /**
2 : * @file gensvm_train.c
3 : * @author G.J.J. van den Burg
4 : * @date 2016-05-01
5 : * @brief Main function for training a GenSVM model.
6 : *
7 : * @copyright
8 : Copyright 2016, G.J.J. van den Burg.
9 :
10 : This file is part of GenSVM.
11 :
12 : GenSVM is free software: you can redistribute it and/or modify
13 : it under the terms of the GNU General Public License as published by
14 : the Free Software Foundation, either version 3 of the License, or
15 : (at your option) any later version.
16 :
17 : GenSVM is distributed in the hope that it will be useful,
18 : but WITHOUT ANY WARRANTY; without even the implied warranty of
19 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 : GNU General Public License for more details.
21 :
22 : You should have received a copy of the GNU General Public License
23 : along with GenSVM. If not, see <http://www.gnu.org/licenses/>.
24 :
25 : */
26 :
27 : #include "gensvm_train.h"
28 :
29 : /**
30 : * @brief Utility function for training a GenSVM model
31 : *
32 : * @details
33 : * This function organizes model allocation, kernel preprocessing, instance
34 : * weight initialization, and model training. It is the function that should
35 : * be used for training a single GenSVM model. Note that optionally a seed
36 : * model can be passed to the function to seed the V matrix with. When no such
37 : * model is used this parameter should be set to NULL.
38 : *
39 : * @param[in] model a GenModel instance
40 : * @param[in] data a GenData instance with the training data
41 : * @param[in] seed_model an optional GenModel to seed the V matrix
42 : *
43 : */
44 2 : void gensvm_train(struct GenModel *model, struct GenData *data,
45 : struct GenModel *seed_model)
46 : {
47 : // copy dataset parameters to model
48 2 : model->n = data->n;
49 2 : model->m = data->m;
50 2 : model->K = data->K;
51 :
52 : // allocate model
53 2 : gensvm_allocate_model(model);
54 :
55 : // initialize the V matrix (potentially with a seed model)
56 2 : gensvm_init_V(seed_model, model, data);
57 :
58 : // preprocess kernel
59 2 : gensvm_kernel_preprocess(model, data);
60 :
61 : // reallocate model for kernels
62 2 : gensvm_reallocate_model(model, data->n, data->r);
63 :
64 : // initialize weights
65 2 : gensvm_initialize_weights(data, model);
66 :
67 : // start training
68 2 : gensvm_optimize(model, data);
69 2 : }
|