1 /**
2  *
3  *  Copyright 2016-2020 Netflix, Inc.
4  *
5  *     Licensed under the BSD+Patent License (the "License");
6  *     you may not use this file except in compliance with the License.
7  *     You may obtain a copy of the License at
8  *
9  *         https://opensource.org/licenses/BSDplusPatent
10  *
11  *     Unless required by applicable law or agreed to in writing, software
12  *     distributed under the License is distributed on an "AS IS" BASIS,
13  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *     See the License for the specific language governing permissions and
15  *     limitations under the License.
16  *
17  */
18 
19 #ifndef __VMAF_SRC_MODEL_H__
20 #define __VMAF_SRC_MODEL_H__
21 
22 #include <stdbool.h>
23 
24 #include "dict.h"
25 #include "libvmaf/model.h"
26 
27 enum VmafModelType {
28     VMAF_MODEL_TYPE_UNKNOWN = 0,
29     VMAF_MODEL_TYPE_SVM_NUSVR,
30     VMAF_MODEL_BOOTSTRAP_SVM_NUSVR,
31     VMAF_MODEL_RESIDUE_BOOTSTRAP_SVM_NUSVR,
32 };
33 
34 enum VmafModelNormalizationType {
35     VMAF_MODEL_NORMALIZATION_TYPE_UNKNOWN = 0,
36     VMAF_MODEL_NORMALIZATION_TYPE_NONE,
37     VMAF_MODEL_NORMALIZATION_TYPE_LINEAR_RESCALE,
38 };
39 
40 typedef struct {
41     char *name;
42     double slope, intercept;
43     VmafDictionary *opts_dict;
44 } VmafModelFeature;
45 
46 typedef struct {
47     double x;
48     double y;
49 } VmafPoint;
50 
51 typedef struct VmafModel {
52     char *path;
53     char *name;
54     enum VmafModelType type;
55     double slope, intercept;
56     VmafModelFeature *feature;
57     unsigned n_features;
58     struct {
59         bool enabled;
60         double min, max;
61     } score_clip;
62     enum VmafModelNormalizationType norm_type;
63     struct {
64         bool enabled;
65         struct {
66             bool enabled;
67             double value;
68         } p0, p1, p2;
69         struct {
70             bool enabled;
71             VmafPoint *list;
72             unsigned n_knots;
73         } knots;
74         bool out_lte_in, out_gte_in;
75     } score_transform;
76     struct svm_model *svm;
77 } VmafModel;
78 
79 typedef struct VmafModelCollection {
80     VmafModel **model;
81     unsigned cnt, size;
82     enum VmafModelType type;
83     const char *name;
84 } VmafModelCollection;
85 
86 char *vmaf_model_generate_name(VmafModelConfig *cfg);
87 
88 int vmaf_model_collection_append(VmafModelCollection **model_collection,
89                                  VmafModel *model);
90 
91 #endif /* __VMAF_SRC_MODEL_H__ */
92