[pktools] 267/375: simplify options for pksvm
Bas Couwenberg
sebastic at xs4all.nl
Wed Dec 3 21:54:20 UTC 2014
This is an automated email from the git hooks/post-receive script.
sebastic-guest pushed a commit to branch upstream-master
in repository pktools.
commit 63d89ad22328dab5e04d421689b86ac27be1e18e
Author: Pieter Kempeneers <kempenep at gmail.com>
Date: Mon May 12 22:57:58 2014 +0200
simplify options for pksvm
---
src/apps/pkann.cc | 17 ++++++++++++-----
src/apps/pkextract.cc | 2 +-
src/apps/pkoptsvm.cc | 22 ++++++++++++----------
src/apps/pkstatascii.cc | 2 +-
src/apps/pkstatogr.cc | 2 +-
src/apps/pksvm.cc | 20 ++++++++++++++------
6 files changed, 41 insertions(+), 24 deletions(-)
diff --git a/src/apps/pkann.cc b/src/apps/pkann.cc
index 341eec9..bc9980a 100644
--- a/src/apps/pkann.cc
+++ b/src/apps/pkann.cc
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
Optionpk<double> scale_opt("\0", "scale", "scale value for each spectral band input features: refl=(DN[band]-offset[band])/scale[band] (use 0 if scale min and max in each band to -1.0 and 1.0)", 0.0);
Optionpk<unsigned short> aggreg_opt("a", "aggreg", "how to combine aggregated classifiers, see also rc option (1: sum rule, 2: max rule).",1);
Optionpk<double> priors_opt("p", "prior", "prior probabilities for each class (e.g., -p 0.3 -p 0.3 -p 0.2 )", 0.0);
- Optionpk<string> priorimg_opt("pim", "priorimg", "prior probability image (multi-band img with band for each class");
+ Optionpk<string> priorimg_opt("pim", "priorimg", "prior probability image (multi-band img with band for each class","",2);
Optionpk<unsigned short> cv_opt("cv", "cv", "n-fold cross validation mode",0);
Optionpk<unsigned int> nneuron_opt("n", "nneuron", "number of neurons in hidden layers in neural network (multiple hidden layers are set by defining multiple number of neurons: -n 15 -n 1, default is one hidden layer with 5 neurons)", 5);
Optionpk<float> connection_opt("\0", "connection", "connection reate (default: 1.0 for a fully connected network)", 1.0);
@@ -72,9 +72,9 @@ int main(int argc, char *argv[])
Optionpk<string> option_opt("co", "co", "Creation option for output file. Multiple options can be specified.");
Optionpk<string> colorTable_opt("ct", "ct", "colour table in ascii format having 5 columns: id R G B ALFA (0: transparent, 255: solid)");
Optionpk<string> prob_opt("\0", "prob", "probability image. Default is no probability image");
- Optionpk<string> entropy_opt("entropy", "entropy", "entropy image (measure for uncertainty of classifier output");
- Optionpk<string> active_opt("active", "active", "ogr output for active training sample.");
- Optionpk<string> ogrformat_opt("f", "f", "Output ogr format for active training sample","ESRI Shapefile");
+ Optionpk<string> entropy_opt("entropy", "entropy", "entropy image (measure for uncertainty of classifier output","",2);
+ Optionpk<string> active_opt("active", "active", "ogr output for active training sample.","",2);
+ Optionpk<string> ogrformat_opt("f", "f", "Output ogr format for active training sample","SQLite");
Optionpk<unsigned int> nactive_opt("na", "nactive", "number of active training points",1);
Optionpk<string> classname_opt("c", "class", "list of class names.");
Optionpk<short> classvalue_opt("r", "reclass", "list of class values (use same order as in class opt).");
@@ -133,6 +133,13 @@ int main(int argc, char *argv[])
exit(0);//help was invoked, stop processing
}
+ if(entropy_opt[0]=="")
+ entropy_opt.clear();
+ if(active_opt[0]=="")
+ active_opt.clear();
+ if(priorimg_opt[0]=="")
+ priorimg_opt.clear();
+
if(verbose_opt[0]>=1){
if(input_opt.size())
cout << "image filename: " << input_opt[0] << endl;
@@ -372,7 +379,7 @@ int main(int argc, char *argv[])
++mapit;
}
if(classname_opt.empty()){
- std::cerr << "Warning: no class name and value pair provided for all " << nclass << " classes, using string2type<int> instead!" << std::endl;
+ //std::cerr << "Warning: no class name and value pair provided for all " << nclass << " classes, using string2type<int> instead!" << std::endl;
for(int iclass=0;iclass<nclass;++iclass){
if(verbose_opt[0])
std::cout << iclass << " " << cm.getClass(iclass) << " -> " << string2type<short>(cm.getClass(iclass)) << std::endl;
diff --git a/src/apps/pkextract.cc b/src/apps/pkextract.cc
index ffd6a2d..56231e5 100644
--- a/src/apps/pkextract.cc
+++ b/src/apps/pkextract.cc
@@ -48,7 +48,7 @@ int main(int argc, char *argv[])
Optionpk<string> output_opt("o", "output", "Output sample file (image file)");
Optionpk<int> class_opt("c", "class", "Class(es) to extract from input sample image. Leave empty to extract all valid data pixels from sample file. Make sure to set classes if rule is set to maxvote or proportion");
Optionpk<float> threshold_opt("t", "threshold", "threshold for selecting samples (randomly). Provide probability in percentage (>0) or absolute (<0). Use a single threshold for vector sample files. If using raster land cover maps as a sample file, you can provide a threshold value for each class (e.g. -t 80 -t 60). Use value 100 to select all pixels for selected class(es)", 100);
- Optionpk<string> ogrformat_opt("f", "f", "Output sample file format","ESRI Shapefile");
+ Optionpk<string> ogrformat_opt("f", "f", "Output sample file format","SQLite");
Optionpk<string> ftype_opt("ft", "ftype", "Field type (only Real or Integer)", "Real");
Optionpk<string> ltype_opt("lt", "ltype", "Label type: In16 or String", "Integer");
Optionpk<bool> polygon_opt("polygon", "polygon", "create OGRPolygon as geometry instead of OGRPoint. Only if sample option is also of polygon type.", false);
diff --git a/src/apps/pkoptsvm.cc b/src/apps/pkoptsvm.cc
index 8980d0a..864ccaf 100644
--- a/src/apps/pkoptsvm.cc
+++ b/src/apps/pkoptsvm.cc
@@ -230,8 +230,8 @@ int main(int argc, char *argv[])
{
map<short,int> reclassMap;
vector<int> vreclass;
- Optionpk<string> input_opt("i", "input", "input image");
- Optionpk<string> training_opt("t", "training", "training vector file. A single vector file contains all training features (must be set as: B0, B1, B2,...) for all classes (class numbers identified by label option).");
+ Optionpk<string> training_opt("t", "training", "training vector file. A single vector file contains all training features (must be set as: b0, b1, b2,...) for all classes (class numbers identified by label option).");
+ Optionpk<string> input_opt("i", "input", "input test vectro file");
Optionpk<string> tlayer_opt("tln", "tln", "training layer name(s)");
Optionpk<string> label_opt("\0", "label", "identifier for class label in training vector file.","label");
// Optionpk<unsigned short> reclass_opt("\0", "rc", "reclass code (e.g. --rc=12 --rc=23 to reclass first two classes to 12 and 23 resp.).", 0);
@@ -248,12 +248,13 @@ int main(int argc, char *argv[])
Optionpk<unsigned int> maxit_opt("maxit","maxit","maximum number of iterations",500);
Optionpk<string> algorithm_opt("a", "algorithm", "GRID, or any optimization algorithm from http://ab-initio.mit.edu/wiki/index.php/NLopt_Algorithms","GRID");
Optionpk<double> tolerance_opt("tol","tolerance","relative tolerance for stopping criterion",0.0001);
- Optionpk<double> step_opt("step","step","multiplicative step for GRID search (-step cost -step gamma)",2);
+ Optionpk<double> stepcc_opt("stepcc","stepcc","multiplicative step for ccost in GRID search",2);
+ Optionpk<double> stepg_opt("stepg","stepg","multiplicative step for gamma in GRID search",2);
bool doProcess;//stop process when program was invoked with help option (-h --help)
try{
- doProcess=input_opt.retrieveOption(argc,argv);
- training_opt.retrieveOption(argc,argv);
+ doProcess=training_opt.retrieveOption(argc,argv);
+ input_opt.retrieveOption(argc,argv);
tlayer_opt.retrieveOption(argc,argv);
label_opt.retrieveOption(argc,argv);
// reclass_opt.retrieveOption(argc,argv);
@@ -281,7 +282,8 @@ int main(int argc, char *argv[])
costfunction_opt.retrieveOption(argc,argv);
maxit_opt.retrieveOption(argc,argv);
tolerance_opt.retrieveOption(argc,argv);
- step_opt.retrieveOption(argc,argv);
+ stepcc_opt.retrieveOption(argc,argv);
+ stepg_opt.retrieveOption(argc,argv);
algorithm_opt.retrieveOption(argc,argv);
classname_opt.retrieveOption(argc,argv);
classvalue_opt.retrieveOption(argc,argv);
@@ -594,8 +596,8 @@ int main(int argc, char *argv[])
std::vector<double> x(2);
if(algorithm_opt[0]=="GRID"){
- if(step_opt.size()<2)//[0] for cost, [1] for gamma
- step_opt.push_back(step_opt.back());
+ // if(step_opt.size()<2)//[0] for cost, [1] for gamma
+ // step_opt.push_back(step_opt.back());
double minError=1000;
double minCost=0;
double minGamma=0;
@@ -607,8 +609,8 @@ int main(int argc, char *argv[])
pfnProgress(progress,pszMessage,pProgressArg);
double ncost=log(ccost_opt[1])/log(10.0)-log(ccost_opt[0])/log(10.0);
double ngamma=log(gamma_opt[1])/log(10.0)-log(gamma_opt[0])/log(10.0);
- for(double ccost=ccost_opt[0];ccost<=ccost_opt[1];ccost*=step_opt[0]){
- for(double gamma=gamma_opt[0];gamma<=gamma_opt[1];gamma*=step_opt[1]){
+ for(double ccost=ccost_opt[0];ccost<=ccost_opt[1];ccost*=stepcc_opt[0]){
+ for(double gamma=gamma_opt[0];gamma<=gamma_opt[1];gamma*=stepg_opt[0]){
x[0]=ccost;
x[1]=gamma;
std::vector<double> theGrad;
diff --git a/src/apps/pkstatascii.cc b/src/apps/pkstatascii.cc
index 7950758..69a1137 100644
--- a/src/apps/pkstatascii.cc
+++ b/src/apps/pkstatascii.cc
@@ -56,7 +56,7 @@ int main(int argc, char *argv[])
Optionpk<bool> histogram2d_opt("hist2d","hist2d","calculate 2-dimensional histogram based on two columns",false);
Optionpk<short> nbin_opt("nbin","nbin","number of bins to calculate histogram");
Optionpk<bool> relative_opt("rel","relative","use percentiles for histogram to calculate histogram",false);
- Optionpk<bool> kde_opt("kde","kde","Use Kernel density estimation when producing histogram. The standard deviation is estimated based on Silverman's rule of thumb.",false);
+ Optionpk<bool> kde_opt("kde","kde","Use Kernel density estimation when producing histogram. The standard deviation is estimated based on Silverman's rule of thumb",false);
Optionpk<bool> correlation_opt("cor","correlation","calculate Pearson produc-moment correlation coefficient between two columns (defined by -c <col1> -c <col2>",false);
Optionpk<bool> rmse_opt("rmse","rmse","calculate root mean square error between two columns (defined by -c <col1> -c <col2>",false);
Optionpk<bool> reg_opt("reg","regression","calculate linear regression error between two columns (defined by -c <col1> -c <col2>",false);
diff --git a/src/apps/pkstatogr.cc b/src/apps/pkstatogr.cc
index c7b9b5c..074d291 100644
--- a/src/apps/pkstatogr.cc
+++ b/src/apps/pkstatogr.cc
@@ -45,7 +45,7 @@ int main(int argc, char *argv[])
Optionpk<bool> histogram_opt("hist","hist","calculate histogram",false);
Optionpk<unsigned int> nbin_opt("nbin", "nbin", "number of bins");
Optionpk<bool> relative_opt("rel","relative","use percentiles for histogram to calculate histogram",false);
- Optionpk<bool> kde_opt("kde","kde","Use Kernel density estimation when producing histogram. The standard deviation is estimated based on Silverman's rule of thumb.",false);
+ Optionpk<bool> kde_opt("kde","kde","Use Kernel density estimation when producing histogram. The standard deviation is estimated based on Silverman's rule of thumb",false);
Optionpk<short> verbose_opt("v", "verbose", "verbose mode if > 0", 0);
bool doProcess;//stop process when program was invoked with help option (-h --help)
diff --git a/src/apps/pksvm.cc b/src/apps/pksvm.cc
index 19b83b8..4ca05b9 100644
--- a/src/apps/pksvm.cc
+++ b/src/apps/pksvm.cc
@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
//--------------------------- command line options ------------------------------------
Optionpk<string> input_opt("i", "input", "input image");
- Optionpk<string> training_opt("t", "training", "training vector file. A single vector file contains all training features (must be set as: B0, B1, B2,...) for all classes (class numbers identified by label option). Use multiple training files for bootstrap aggregation (alternative to the bag and bsize options, where a random subset is taken from a single training file)");
+ Optionpk<string> training_opt("t", "training", "training vector file. A single vector file contains all training features (must be set as: b0, b1, b2,...) for all classes (class numbers identified by label option). Use multiple training files for bootstrap aggregation (alternative to the bag and bsize options, where a random subset is taken from a single training file)");
Optionpk<string> tlayer_opt("tln", "tln", "training layer name(s)");
Optionpk<string> label_opt("label", "label", "identifier for class label in training vector file.","label");
Optionpk<unsigned int> balance_opt("bal", "balance", "balance the input data to this number of samples for each class", 0);
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
Optionpk<double> offset_opt("\0", "offset", "offset value for each spectral band input features: refl[band]=(DN[band]-offset[band])/scale[band]", 0.0);
Optionpk<double> scale_opt("\0", "scale", "scale value for each spectral band input features: refl=(DN[band]-offset[band])/scale[band] (use 0 if scale min and max in each band to -1.0 and 1.0)", 0.0);
Optionpk<double> priors_opt("p", "prior", "prior probabilities for each class (e.g., -p 0.3 -p 0.3 -p 0.2 ). Used for input only (ignored for cross validation)", 0.0);
- Optionpk<string> priorimg_opt("pim", "priorimg", "prior probability image (multi-band img with band for each class");
+ Optionpk<string> priorimg_opt("pim", "priorimg", "prior probability image (multi-band img with band for each class","",2);
Optionpk<unsigned short> cv_opt("cv", "cv", "n-fold cross validation mode",0);
Optionpk<std::string> svm_type_opt("svmt", "svmtype", "type of SVM (C_SVC, nu_SVC,one_class, epsilon_SVR, nu_SVR)","C_SVC");
Optionpk<std::string> kernel_type_opt("kt", "kerneltype", "type of kernel function (linear,polynomial,radial,sigmoid) ","radial");
@@ -88,9 +88,9 @@ int main(int argc, char *argv[])
Optionpk<string> option_opt("co", "co", "Creation option for output file. Multiple options can be specified.");
Optionpk<string> colorTable_opt("ct", "ct", "colour table in ascii format having 5 columns: id R G B ALFA (0: transparent, 255: solid)");
Optionpk<string> prob_opt("prob", "prob", "probability image.");
- Optionpk<string> entropy_opt("entropy", "entropy", "entropy image (measure for uncertainty of classifier output");
- Optionpk<string> active_opt("active", "active", "ogr output for active training sample.");
- Optionpk<string> ogrformat_opt("f", "f", "Output ogr format for active training sample","ESRI Shapefile");
+ Optionpk<string> entropy_opt("entropy", "entropy", "entropy image (measure for uncertainty of classifier output","",2);
+ Optionpk<string> active_opt("active", "active", "ogr output for active training sample.","",2);
+ Optionpk<string> ogrformat_opt("f", "f", "Output ogr format for active training sample","SQLite");
Optionpk<unsigned int> nactive_opt("na", "nactive", "number of active training points",1);
Optionpk<string> classname_opt("c", "class", "list of class names.");
Optionpk<short> classvalue_opt("r", "reclass", "list of class values (use same order as in class opt).");
@@ -154,6 +154,14 @@ int main(int argc, char *argv[])
exit(0);//help was invoked, stop processing
}
+ if(entropy_opt[0]=="")
+ entropy_opt.clear();
+ if(active_opt[0]=="")
+ active_opt.clear();
+ if(priorimg_opt[0]=="")
+ priorimg_opt.clear();
+
+
std::map<std::string, svm::SVM_TYPE> svmMap;
svmMap["C_SVC"]=svm::C_SVC;
@@ -429,7 +437,7 @@ int main(int argc, char *argv[])
exit(1);
}
if(classname_opt.empty()){
- std::cerr << "Warning: no class name and value pair provided for all " << nclass << " classes, using string2type<int> instead!" << std::endl;
+ //std::cerr << "Warning: no class name and value pair provided for all " << nclass << " classes, using string2type<int> instead!" << std::endl;
for(int iclass=0;iclass<nclass;++iclass){
if(verbose_opt[0])
std::cout << iclass << " " << cm.getClass(iclass) << " -> " << string2type<short>(cm.getClass(iclass)) << std::endl;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/pktools.git
More information about the Pkg-grass-devel
mailing list