解决如下的优化问题有现成的C++的库么
谢邀。GSL:GNU Scientific Library应该可以。
■网友
liblinear: LIBLINEAR -- A Library for Large Linear Classification在computer vision和machine learning领域里适用性很高的一个开源库。有C, C++, python和matlab版;我最近也在用,我的X是十几万维的二值稀疏特征。所以对于你的问题应该能够很好的解决;////////////////////////////////linlinear的说明//////////////////////////////////////////////////////////////////LIBLINEAR is a simple package for solving large-scale regularized linear classification and regression. It currently supports - L2-regularized logistic regression/L2-loss support vector classification/L1-loss support vector classification- L1-regularized L2-loss support vector classification/L1-regularized logistic regression- L2-regularized L2-loss support vector regression/L1-loss support vector regression. This document explains the usage of LIBLINEAR.To get started, please read the ``Quick Start\u0026#39;\u0026#39; section first.For developers, please check the ``Library Usage\u0026#39;\u0026#39; section to learnhow to integrate LIBLINEAR in your software.Table of Contents=================- When to use LIBLINEAR but not LIBSVM- Quick Start- Installation- `train\u0026#39; Usage- `predict\u0026#39; Usage- Examples- Library Usage- Building Windows Binaries- Additional Information- MATLAB/OCTAVE interface- PYTHON interfaceWhen to use LIBLINEAR but not LIBSVM====================================There are some large data for which with/without nonlinear mappingsgives similar performances. Without using kernels, one canefficiently train a much larger set via linear classification/regression. These data usually have a large number of features. Document classificationis an example.Warning: While generally liblinear is very fast, its default solvermay be slow under certain situations (e.g., data not scaled or C islarge). See Appendix B of our SVM guide about how to handle suchcases.http://www.csie.ntu.edu.tw/~cjlin/papers/guide/guide.pdfWarning: If you are a beginner and your data sets are not large, youshould consider LIBSVM first.LIBSVM page:LIBSVM -- A Library for Support Vector MachinesQuick Start===========See the section ``Installation\u0026#39;\u0026#39; for installing LIBLINEAR.After installation, there are programs `train\u0026#39; and `predict\u0026#39; fortraining and testing, respectively.About the data format, please check the README file of LIBSVM. Notethat feature index must start from 1 (but not 0).A sample classification data included in this package is `heart_scale\u0026#39;.Type `train heart_scale\u0026#39;, and the program will read the trainingdata and output the model file `heart_scale.model\u0026#39;. If you have a testset called heart_scale.t, then type `predict heart_scale.theart_scale.model output\u0026#39; to see the prediction accuracy. The `output\u0026#39;file contains the predicted class labels.For more information about `train\u0026#39; and `predict\u0026#39;, see the sections`train\u0026#39; Usage and `predict\u0026#39; Usage.To obtain good performances, sometimes one needs to scale thedata. Please check the program `svm-scale\u0026#39; of LIBSVM. For large andsparse data, use `-l 0\u0026#39; to keep the sparsity.Installation============On Unix systems, type `make\u0026#39; to build the `train\u0026#39; and `predict\u0026#39;programs. Run them without arguments to show the usages.On other systems, consult `Makefile\u0026#39; to build them (e.g., see\u0026#39;Building Windows binaries\u0026#39; in this file) or use the pre-builtbinaries (Windows binaries are in the directory `windows\u0026#39;).This software uses some level-1 BLAS subroutines. The needed functions areincluded in this package. If a BLAS library is available on yourmachine, you may use it by modifying the Makefile: Unmark the following line #LIBS ?= -lblasand mark LIBS ?= blas/blas.a`train\u0026#39; Usage=============Usage: train training_set_file options:-s type : set type of solver (default 1) for multi-class classification\t 0 -- L2-regularized logistic regression (primal)\t 1 -- L2-regularized L2-loss support vector classification (dual)\t 2 -- L2-regularized L2-loss support vector classification (primal)\t 3 -- L2-regularized L1-loss support vector classification (dual)\t 4 -- support vector classification by Crammer and Singer\t 5 -- L1-regularized L2-loss support vector classification\t 6 -- L1-regularized logistic regression\t 7 -- L2-regularized logistic regression (dual) for regression\t11 -- L2-regularized L2-loss support vector regression (primal)\t12 -- L2-regularized L2-loss support vector regression (dual)\t13 -- L2-regularized L1-loss support vector regression (dual)-c cost : set the parameter C (default 1)-p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)-e epsilon : set tolerance of termination criterion\t-s 0 and 2\t\t|f\u0026#39;(w)|_2 \u0026lt;= eps*min(pos,neg)/l*|f\u0026#39;(w0)|_2,\t\twhere f is the primal function and pos/neg are # of\t\tpositive/negative data (default 0.01)\t-s 11\t\t|f\u0026#39;(w)|_2 \u0026lt;= eps*|f\u0026#39;(w0)|_2 (default 0.001) \t-s 1, 3, 4 and 7\t\tDual maximal violation \u0026lt;= eps; similar to libsvm (default 0.1)\t-s 5 and 6\t\t|f\u0026#39;(w)|_1 \u0026lt;= eps*min(pos,neg)/l*|f\u0026#39;(w0)|_1,\t\twhere f is the primal function (default 0.01)\t-s 12 and 13\"\t\t|f\u0026#39;(alpha)|_1 \u0026lt;= eps |f\u0026#39;(alpha0)|,\t\twhere f is the dual function (default 0.1)-B bias : if bias \u0026gt;= 0, instance x becomes ; if \u0026lt; 0, no bias term added (default -1)-wi weight: weights adjust the parameter C of different classes (see README for details)-v n: n-fold cross validation mode-q : quiet mode (no outputs)Option -v randomly splits the data into n parts and calculates crossvalidation accuracy on them.Formulations:For L2-regularized logistic regression (-s 0), we solvemin_w w^Tw/2 + C \\sum log(1 + exp(-y_i w^Tx_i))For L2-regularized L2-loss SVC dual (-s 1), we solvemin_alpha 0.5(alpha^T (Q + I/2/C) alpha) - e^T alpha s.t. 0 \u0026lt;= alpha_i,For L2-regularized L2-loss SVC (-s 2), we solvemin_w w^Tw/2 + C \\sum max(0, 1- y_i w^Tx_i)^2For L2-regularized L1-loss SVC dual (-s 3), we solvemin_alpha 0.5(alpha^T Q alpha) - e^T alpha s.t. 0 \u0026lt;= alpha_i \u0026lt;= C,For L1-regularized L2-loss SVC (-s 5), we solvemin_w \\sum |w_j| + C \\sum max(0, 1- y_i w^Tx_i)^2For L1-regularized logistic regression (-s 6), we solvemin_w \\sum |w_j| + C \\sum log(1 + exp(-y_i w^Tx_i))For L2-regularized logistic regression (-s 7), we solvemin_alpha 0.5(alpha^T Q alpha) + \\sum alpha_i*log(alpha_i) + \\sum (C-alpha_i)*log(C-alpha_i) - a constant s.t. 0 \u0026lt;= alpha_i \u0026lt;= C,whereQ is a matrix with Q_ij = y_i y_j x_i^T x_j.For L2-regularized L2-loss SVR (-s 11), we solvemin_w w^Tw/2 + C \\sum max(0, |y_i-w^Tx_i|-epsilon)^2For L2-regularized L2-loss SVR dual (-s 12), we solvemin_beta 0.5(beta^T (Q + lambda I/2/C) beta) - y^T beta + \\sum |beta_i|For L2-regularized L1-loss SVR dual (-s 13), we solvemin_beta 0.5(beta^T Q beta) - y^T beta + \\sum |beta_i| s.t. -C \u0026lt;= beta_i \u0026lt;= C,whereQ is a matrix with Q_ij = x_i^T x_j.If bias \u0026gt;= 0, w becomes and x becomes .The primal-dual relationship implies that -s 1 and -s 2 give the samemodel, -s 0 and -s 7 give the same, and -s 11 and -s 12 give the same.We implement 1-vs-the rest multi-class strategy for classification. In training i vs. non_i, their C parameters are (weight from -wi)*C and C, respectively. If there are only two classes, we train only onemodel. Thus weight1*C vs. weight2*C is used. See examples below.We also implement multi-class SVM by Crammer and Singer (-s 4):min_{w_m, \\xi_i} 0.5 \\sum_m ||w_m||^2 + C \\sum_i \\xi_i s.t. w^T_{y_i} x_i - w^T_m x_i \u0026gt;= \\e^m_i - \\xi_i \\forall m,iwhere e^m_i = 0 if y_i = m, e^m_i = 1 if y_i != m,Here we solve the dual problem:min_{\\alpha} 0.5 \\sum_m ||w_m(\\alpha)||^2 + \\sum_i \\sum_m e^m_i alpha^m_i s.t. \\alpha^m_i \u0026lt;= C^m_i \\forall m,i , \\sum_m \\alpha^m_i=0 \\forall iwhere w_m(\\alpha) = \\sum_i \\alpha^m_i x_i,and C^m_i = C if m = y_i, C^m_i = 0 if m != y_i.`predict\u0026#39; Usage===============Usage: predict test_file model_file output_fileoptions:-b probability_estimates: whether to output probability estimates, 0 or 1 (default 0); currently for logistic regression only-q : quiet mode (no outputs)Note that -b is only needed in the prediction phase. This is differentfrom the setting of LIBSVM.Examples========\u0026gt; train data_fileTrain linear SVM with L2-loss function.\u0026gt; train -s 0 data_fileTrain a logistic regression model.\u0026gt; train -v 5 -e 0.001 data_fileDo five-fold cross-validation using L2-loss svm.Use a smaller stopping tolerance 0.001 than the default0.1 if you want more accurate solutions.\u0026gt; train -c 10 -w1 2 -w2 5 -w3 2 four_class_data_fileTrain four classifiers:positive negative Cp Cnclass 1 class 2,3,4. 20 10class 2 class 1,3,4. 50 10class 3 class 1,2,4. 20 10class 4 class 1,2,3. 10 10\u0026gt; train -c 10 -w3 1 -w2 5 two_class_data_fileIf there are only two classes, we train ONE model.The C values for the two classes are 10 and 50.\u0026gt; predict -b 1 test_file data_file.model output_fileOutput probability estimates (for logistic regression only).Library Usage=============- Function: model* train(const struct problem *prob, const struct parameter *param); This function constructs and returns a linear classification or regression model according to the given training data and parameters. struct problem describes the problem: struct problem { int l, n; int *y; struct feature_node **x; double bias; }; where `l\u0026#39; is the number of training data. If bias \u0026gt;= 0, we assume that one additional feature is added to the end of each data instance. `n\u0026#39; is the number of feature (including the bias feature if bias \u0026gt;= 0). `y\u0026#39; is an array containing the target values. (integers in classification, real numbers in regression) And `x\u0026#39; is an array of pointers, each of which points to a sparse representation (array of feature_node) of one training vector. For example, if we have the following training data: LABEL ATTR1 ATTR2 ATTR3 ATTR4 ATTR5 ----- ----- ----- ----- ----- ----- 1 0 0.1 0.2 0 0 2 0 0.1 0.3 -1.2 0 1 0.4 0 0 0 0 2 0 0.1 0 1.4 0.5 3 -0.1 -0.2 0.1 1.1 0.1 and bias = 1, then the components of problem are: l = 5 n = 6 y -\u0026gt; 1 2 1 2 3 x -\u0026gt; -\u0026gt; (2,0.1) (3,0.2) (6,1) (-1,?) -\u0026gt; (2,0.1) (3,0.3) (4,-1.2) (6,1) (-1,?) -\u0026gt; (1,0.4) (6,1) (-1,?) -\u0026gt; (2,0.1) (4,1.4) (5,0.5) (6,1) (-1,?) -\u0026gt; (1,-0.1) (2,-0.2) (3,0.1) (4,1.1) (5,0.1) (6,1) (-1,?) struct parameter describes the parameters of a linear classification or regression model: struct parameter { int solver_type; /* these are for training only */ double eps; /* stopping criteria */ double C; int nr_weight; int *weight_label; double* weight; double p; }; solver_type can be one of 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, L2R_L2LOSS_SVR_DUAL, L2R_L1LOSS_SVR_DUAL. for classification L2R_LR L2-regularized logistic regression (primal) L2R_L2LOSS_SVC_DUAL L2-regularized L2-loss support vector classification (dual) L2R_L2LOSS_SVC L2-regularized L2-loss support vector classification (primal) L2R_L1LOSS_SVC_DUAL L2-regularized L1-loss support vector classification (dual) MCSVM_CS support vector classification by Crammer and Singer L1R_L2LOSS_SVC L1-regularized L2-loss support vector classification L1R_LR L1-regularized logistic regression L2R_LR_DUAL L2-regularized logistic regression (dual) for regression L2R_L2LOSS_SVR L2-regularized L2-loss support vector regression (primal) L2R_L2LOSS_SVR_DUAL L2-regularized L2-loss support vector regression (dual) L2R_L1LOSS_SVR_DUAL L2-regularized L1-loss support vector regression (dual) C is the cost of constraints violation. p is the sensitiveness of loss of support vector regression. eps is the stopping criterion. nr_weight, weight_label, and weight are used to change the penalty for some classes (If the weight for a class is not changed, it is set to 1). This is useful for training classifier using unbalanced input data or with asymmetric misclassification cost. nr_weight is the number of elements in the array weight_label and weight. Each weight corresponds to weight_label, meaning that the penalty of class weight_label is scaled by a factor of weight. If you do not want to change penalty for any of the classes, just set nr_weight to 0. *NOTE* To avoid wrong parameters, check_parameter() should be called before train(). struct model stores the model obtained from the training procedure: struct model { struct parameter param; int nr_class; /* number of classes */ int nr_feature; double *w; int *label; /* label of each class */ double bias; }; param describes the parameters used to obtain the model. nr_class and nr_feature are the number of classes and features, respectively. nr_class = 2 for regression. The nr_feature*nr_class array w gives feature weights. We use one against the rest for multi-class classification, so each feature index corresponds to nr_class weight values. Weights are organized in the following way +------------------+------------------+------------+ | nr_class weights | nr_class weights | ... | for 1st feature | for 2nd feature | +------------------+------------------+------------+ If bias \u0026gt;= 0, x becomes . The number of features is increased by one, so w is a (nr_feature+1)*nr_class array. The value of bias is stored in the variable bias. The array label stores class labels.- Function: void cross_validation(const problem *prob, const parameter *param, int nr_fold, double *target); This function conducts cross validation. Data are separated to nr_fold folds. Under given parameters, sequentially each fold is validated using the model from training the remaining. Predicted labels in the validation process are stored in the array called target. The format of prob is same as that for train().- Function: double predict(const model *model_, const feature_node *x); For a classification model, the predicted class for x is returned. For a regression model, the function value of x calculated using the model is returned. - Function: double predict_values(const struct model *model_, const struct feature_node *x, double* dec_values); This function gives nr_w decision values in the array dec_values. nr_w=1 if regression is applied or the number of classes is two. An exception is multi-class svm by Crammer and Singer (-s 4), where nr_w = 2 if there are two classes. For all other situations, nr_w is the number of classes. We implement one-vs-the rest multi-class strategy (-s 0,1,2,3,5,6,7) and multi-class svm by Crammer and Singer (-s 4) for multi-class SVM. The class with the highest decision value is returned.- Function: double predict_probability(const struct model *model_, const struct feature_node *x, double* prob_estimates); This function gives nr_class probability estimates in the array prob_estimates. nr_class can be obtained from the function get_nr_class. The class with the highest probability is returned. Currently, we support only the probability outputs of logistic regression.- Function: int get_nr_feature(const model *model_); The function gives the number of attributes of the model.- Function: int get_nr_class(const model *model_); The function gives the number of classes of the model. For a regression model, 2 is returned.- Function: void get_labels(const model *model_, int* label); This function outputs the name of labels into an array called label. For a regression model, label is unchanged.- Function: double get_decfun_coef(const struct model *model_, int feat_idx, int label_idx); This function gives the coefficient for the feature with feature index = feat_idx and the class with label index = label_idx. Note that feat_idx starts from 1, while label_idx starts from 0. If feat_idx is not in the valid range (1 to nr_feature), then a zero value will be returned. For classification models, if label_idx is not in the valid range (0 to nr_class-1), then a zero value will be returned; for regression models, label_idx is ignored.- Function: double get_decfun_bias(const struct model *model_, int label_idx); This function gives the bias term corresponding to the class with the label_idx. For classification models, if label_idx is not in a valid range (0 to nr_class-1), then a zero value will be returned; for regression models, label_idx is ignored.- Function: const char *check_parameter(const struct problem *prob, const struct parameter *param); This function checks whether the parameters are within the feasible range of the problem. This function should be called before calling train() and cross_validation(). It returns NULL if the parameters are feasible, otherwise an error message is returned.- Function: int check_probability_model(const struct model *model); This function returns 1 if the model supports probability output; otherwise, it returns 0.- Function: int check_regression_model(const struct model *model); This function returns 1 if the model is a regression model; otherwise it returns 0.- Function: int save_model(const char *model_file_name, const struct model *model_); This function saves a model to a file; returns 0 on success, or -1 if an error occurs.- Function: struct model *load_model(const char *model_file_name); This function returns a pointer to the model read from the file, or a null pointer if the model could not be loaded.- Function: void free_model_content(struct model *model_ptr); This function frees the memory used by the entries in a model structure.- Function: void free_and_destroy_model(struct model **model_ptr_ptr); This function frees the memory used by a model and destroys the model structure.- Function: void destroy_param(struct parameter *param); This function frees the memory used by a parameter set.- Function: void set_print_string_function(void (*print_func)(const char *)); Users can specify their output format by a function. Use set_print_string_function(NULL); for default printing to stdout.Building Windows Binaries=========================Windows binaries are in the directory `windows\u0026#39;. To build them viaVisual C++, use the following steps:1. Open a dos command box and change to liblinear directory. Ifenvironment variables of VC++ have not been set, type"C:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\bin\\vcvars32.bat"You may have to modify the above command according which version ofVC++ or where it is installed.2. Typenmake -f Makefile.win clean all2. (Optional) To build 64-bit windows binaries, you must\t(1) Setup vcvars64.bat instead of vcvars32.bat\t(2) Change CFLAGS in Makefile.win: /D _WIN32 to /D _WIN64MATLAB/OCTAVE Interface=======================Please check the file README in the directory `matlab\u0026#39;.PYTHON Interface================Please check the file README in the directory `python\u0026#39;.Additional Information======================If you find LIBLINEAR helpful, please cite it asR.-E. Fan, K.-W. Chang, C.-J. Hsieh, X.-R. Wang, and C.-J. Lin.LIBLINEAR: A Library for Large Linear Classification, Journal ofMachine Learning Research 9(2008), 1871-1874. Software available atLIBLINEAR -- A Library for Large Linear ClassificationFor any questions and comments, please send your email tocjlin@csie.ntu.edu.tw
推荐阅读
- 蟹爪兰叶子软塌,难复花,“根源”在这里,解决后开花一茬接一茬
- 贵州在建骨干水源工程达到465座有效解决工程性区域性缺水问题
- 长春社区开设助老餐厅探索解决老人“吃饭难”
- 互联网怎样解决“家政服务上门速度慢”的问题
- |徐州市出台《关于优化创新创业生态系统 提升区域科技创新活力的实施意见》及实施细则
- 咋解决电信营业厅对http网址的污染
- 汽车|多项功能进行优化 吉利星瑞推出第二次FOTA升级
- 封面新闻|耀出行:滴滴解决你代步的“温饱”问题,我来满足你出行的仪式感需求
- 植物|花卉生长不好,这样养轻松解决!夏天温度高
- 营销型外贸网站用哪种建站程序和语言比较好呢主要是适合优化,可扩展兼容性,安全性,后期网站扩展升级