Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nmap
GitHub Repository: nmap/nmap
Path: blob/master/liblinear/linear.h
4727 views
1
#include <stdbool.h>
2
#ifndef _LIBLINEAR_H
3
#define _LIBLINEAR_H
4
5
#define LIBLINEAR_VERSION 250
6
7
#ifdef __cplusplus
8
extern "C" {
9
#endif
10
11
extern int liblinear_version;
12
13
struct feature_node
14
{
15
int index;
16
double value;
17
};
18
19
struct problem
20
{
21
int l, n;
22
double *y;
23
struct feature_node **x;
24
double bias; /* < 0 if no bias term */
25
};
26
27
enum { L2R_LR, L2R_L2LOSS_SVC_DUAL, L2R_L2LOSS_SVC, L2R_L1LOSS_SVC_DUAL, MCSVM_CS, L1R_L2LOSS_SVC, L1R_LR, L2R_LR_DUAL, L2R_L2LOSS_SVR = 11, L2R_L2LOSS_SVR_DUAL, L2R_L1LOSS_SVR_DUAL, ONECLASS_SVM = 21 }; /* solver_type */
28
29
struct parameter
30
{
31
int solver_type;
32
33
/* these are for training only */
34
double eps; /* stopping tolerance */
35
double C;
36
int nr_weight;
37
int *weight_label;
38
double* weight;
39
double p;
40
double nu;
41
double *init_sol;
42
int regularize_bias;
43
bool w_recalc; /* for -s 1, 3; may be extended to -s 12, 13, 21 */
44
};
45
46
struct model
47
{
48
struct parameter param;
49
int nr_class; /* number of classes */
50
int nr_feature;
51
double *w;
52
int *label; /* label of each class */
53
double bias;
54
double rho; /* one-class SVM only */
55
};
56
57
struct model* train(const struct problem *prob, const struct parameter *param);
58
void cross_validation(const struct problem *prob, const struct parameter *param, int nr_fold, double *target);
59
void find_parameters(const struct problem *prob, const struct parameter *param, int nr_fold, double start_C, double start_p, double *best_C, double *best_p, double *best_score);
60
61
double predict_values(const struct model *model_, const struct feature_node *x, double* dec_values);
62
double predict(const struct model *model_, const struct feature_node *x);
63
double predict_probability(const struct model *model_, const struct feature_node *x, double* prob_estimates);
64
65
int save_model(const char *model_file_name, const struct model *model_);
66
struct model *load_model(const char *model_file_name);
67
68
int get_nr_feature(const struct model *model_);
69
int get_nr_class(const struct model *model_);
70
void get_labels(const struct model *model_, int* label);
71
double get_decfun_coef(const struct model *model_, int feat_idx, int label_idx);
72
double get_decfun_bias(const struct model *model_, int label_idx);
73
double get_decfun_rho(const struct model *model_);
74
75
void free_model_content(struct model *model_ptr);
76
void free_and_destroy_model(struct model **model_ptr_ptr);
77
void destroy_param(struct parameter *param);
78
79
const char *check_parameter(const struct problem *prob, const struct parameter *param);
80
int check_probability_model(const struct model *model);
81
int check_regression_model(const struct model *model);
82
int check_oneclass_model(const struct model *model);
83
void set_print_string_function(void (*print_func) (const char*));
84
85
#ifdef __cplusplus
86
}
87
#endif
88
89
#endif /* _LIBLINEAR_H */
90
91
92