📄 multi.h
字号:
#ifndef MULTI_H#define MULTI_H#include <stdio.h>#include "classifier.h"#include "parray.h"#include "vector.h"enum multi_method { /** * One and one. * One classifier per class. * Each classifier is trained with positive examples from the class. * Classification is performed on every classifier and the one with * largest output determines the class. */ ONE_MAX, /** * One against all. * One classifier per class. * Each classifier is trained with positive examples from the class and * negative examples from all other classes. * Classification is performed on every classifier and the one with * largest output determines the class. */ REST_MAX, /** * Linear-Max algorithm. * One classifier per class. * Mistake driven learning. When total classification is correct no * learning is performed. When total classification is incorrect the * true classifier is trained with a positive example and the winning * classifier is trained with a negative example. * Classification is performed on every classifier and the one with * largest output determines the class. */ LIN_MAX, /** * Ultraconservative algorithm. * One classifier per class. * Mistake driven learning. */ UC_MAX, /** * One against one with max-wins. * One classifier per pair of classes. * Each classifier is trained with positive examples from one class and * negative examples from the other class. * Classification is based on a max winning scheme. */ PAIR_MAX_WINS, /** * One against one with DAG. * One classifier per pair of classes. * Each classifier is trained with positive examples from one class and * negative examples from the other class. * Classification is based on a directed acyclic graph scheme. */ PAIR_DAG, /** * Error correcting output codes. */ ECOC};typedef struct { /** * Database creation function. * Must be present. * * @return A new classifier database. */ void *(*new_db) (const char *opts); /** * Free function. * Frees the memory used by the classifier database. * * @param db_data classifier database */ void (*free_db) (void *db); /** * Class creation function. * Must be present. * * @return A new classifier class. */ void *(*new) (void); /** * Copy function. * Must only be present if using multi_method REST_MAX. * * @param class_data class data * @return A copy of the classifier class. */ void *(*copy) (void *class_data); /** * Free function. * Frees the memory used by the classifier class. * * @param class_data class data */ void (*free) (void *class_data); /** * Set parameters. * Sets the parameters of the classifier. * * @param db classifier database * @param s parameter string */ void (*set) (void *db, char *s); /** * Learning function. * Must be present. * * @param db classifier database * @param data class data * @param v vector to learn * @param class Class to learn: 1 or -1 */ int (*learn) (void *db, void *data, vector *v, int class); /** * Unlearning function. * * @param db classifier database * @param data class data * @param v vector to learn * @param class Class to learn: 1 or -1 */ int (*unlearn) (void *db, void *data, vector *v, int class); /** * Feature removal function. * * @param db classifier database * @param data class data * @param v vector of features to remove */ int (*remove) (void *db, void *data, vector *v); int (*remove_db) (void *db, vector *v); /** * Classification function. * Must be present. * * @param db classifier database * @param data class data * @param v vector to classify * @return A positive value if classified to class 1, * a negative value if classified to -1, * 0 if undecided. * The absolute value indicates a relative confidence level. */ double (*classify) (void *db, void *data, vector *v); /** * Loading of classifier global data function. */ void *(*load_db) (FILE *f); /** * Loading of classifier class function. */ void *(*load_class) (FILE *f); /** * Saving of classifier global data function. */ int (*save_db) (FILE *f, void *db); /** * Saving of classifier class function. */ int (*save_class) (FILE *f, void *data); /** * Miscellaneous options. * Should be set and read using the OPTION_* definitions. */ int option;} multi_functions;/** * Copy learning vectors. * Default is to not copy learning vectors. * This must be set if the algorithm saves a reference to the vector. */#define OPTION_COPY_VECTOR 1/** * Binary classification: train with both positive and negative examples. * Default is relative classification: train only with positive examples. * * Binary classification: * -1 if negative, 1 if positive, 0 if no preference. * * Relative classification: * larger values indicates stronger probability, 0 if no preference. */#define OPTION_BINARY 2/** * Mistake driven learning: only update on mistakes. * Default is to update on both correct classifications and mistakes. */#define OPTION_MISTAKE 4/** * Can only handle -1 or 1 as input to training. * Default is to handle a realvalued input, indicating strength of training. * This option is only applicable for binary classifiers. */#define OPTION_BOOLEAN 8/** * Multi classifier database. */typedef struct { multi_functions *funcs; /**< Classifier functions */ void *data; /**< Classifier global data */ parray *classes; /**< Classifiers */ int size; /**< Number of classes */ /** * Method data. * REST_MAX uses this to store an all negatively trained class.\n * ECOC uses this to store an array of the codewords. */ void *method_data;} multi_db;classifier *multi_new (enum multi_method mm, multi_functions *funcs, void *data, int size);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -