diff --git a/src/imagery/i.pr/Makefile b/src/imagery/i.pr/Makefile index 85de8a65b5..81722faba0 100644 --- a/src/imagery/i.pr/Makefile +++ b/src/imagery/i.pr/Makefile @@ -1,5 +1,7 @@ MODULE_TOPDIR = ../.. +PGM = i.pr + include $(MODULE_TOPDIR)/include/Make/Dir.make SUBDIRS = \ @@ -11,14 +13,15 @@ SUBDIRS = \ i.pr.features_extract \ i.pr.features_selection \ i.pr.model \ - i.pr.statistics \ i.pr.subsets \ - i.pr.training \ i.pr.uxb \ i.pr.sites_aggregate -default: subdirs +# currently unsupported +# i.pr.statistics +# i.pr.training -clean: cleansubdirs +default: subdirs htmldir install: installsubdirs + $(INSTALL_DATA) $(PGM).html $(INST_DIR)/docs/html/ diff --git a/src/imagery/i.pr/PRLIB/blob.c b/src/imagery/i.pr/PRLIB/blob.c index 590367cfca..62ffb5afa0 100644 --- a/src/imagery/i.pr/PRLIB/blob.c +++ b/src/imagery/i.pr/PRLIB/blob.c @@ -13,8 +13,9 @@ #include #include "global.h" -static void add_points_to_blob(); -static int in_blob(); +static void add_points_to_blob(Blob ***, int *, int, double **, int, int, int, + int, double, double); +static int in_blob(int, int, Blob *, int); void extract_sites_from_blob(Blob *blobs, int npoints, int nblobs, struct Cell_head *cellhd, BlobSites *sites, diff --git a/src/imagery/i.pr/PRLIB/bootstrap.c b/src/imagery/i.pr/PRLIB/bootstrap.c index b006db1402..36b15d62b5 100644 --- a/src/imagery/i.pr/PRLIB/bootstrap.c +++ b/src/imagery/i.pr/PRLIB/bootstrap.c @@ -61,16 +61,11 @@ void Bootsamples(int n, double *prob, int *random_labels) G_free(random_labels_flag); } -void Bootsamples_rseed(n, prob, random_labels, idum) - /* - given an array of probabilities of length n, extract a bootstrap sample - of n elements according to the vector of probabilities - */ - int n; -double *prob; -int *random_labels; -int *idum; - +void Bootsamples_rseed(int n, double *prob, int *random_labels, int *idum) +/* + given an array of probabilities of length n, extract a bootstrap sample + of n elements according to the vector of probabilities + */ { int i, j; int *random_labels_flag; diff --git a/src/imagery/i.pr/PRLIB/entropy.c b/src/imagery/i.pr/PRLIB/entropy.c index d16fab8be5..1fe1e50950 100644 --- a/src/imagery/i.pr/PRLIB/entropy.c +++ b/src/imagery/i.pr/PRLIB/entropy.c @@ -6,7 +6,7 @@ Entropy management */ -#include "func.h" +#include "global.h" #include double Entropy(double *data, int n, double zero) diff --git a/src/imagery/i.pr/PRLIB/features.c b/src/imagery/i.pr/PRLIB/features.c index 516108c7f7..fd68412f52 100644 --- a/src/imagery/i.pr/PRLIB/features.c +++ b/src/imagery/i.pr/PRLIB/features.c @@ -31,7 +31,6 @@ void compute_features(Features *features) DCELL *tf; DCELL **matrix; int r, c; - char tempbuf[500]; int *compute_features; int dim; DCELL *mean = NULL, *sd = NULL; @@ -151,10 +150,9 @@ void compute_features(Features *features) } } if (!thisclassok) { - sprintf(tempbuf, - "compute_features-> Class %d for pc not recognized", - features->pca_class[1 + l]); - G_fatal_error(tempbuf); + G_fatal_error( + "compute_features-> Class %d for pc not recognized", + features->pca_class[1 + l]); } } fprintf(stderr, "\n"); @@ -182,18 +180,15 @@ void compute_features(Features *features) fprintf(stdout, "%s\n", features->training.mapnames[i][j]); if ((mapset = (char *)G_find_raster( features->training.mapnames[i][j], "")) == NULL) { - sprintf(tempbuf, - "compute_features-> Can't find raster map <%s>", - features->training.mapnames[i][j]); - G_fatal_error(tempbuf); + G_fatal_error( + "compute_features-> Can't find raster map <%s>", + features->training.mapnames[i][j]); } if ((fp = Rast_open_old(features->training.mapnames[i][j], mapset)) < 0) { - sprintf(tempbuf, - "compute_features-> Can't open raster map <%s> for " - "reading", - features->training.mapnames[i][j]); - G_fatal_error(tempbuf); + G_fatal_error("compute_features-> Can't open raster map " + "<%s> for reading", + features->training.mapnames[i][j]); } Rast_get_cellhd(features->training.mapnames[i][j], mapset, @@ -201,8 +196,7 @@ void compute_features(Features *features) G_set_window(&cellhd); if ((cellhd.rows != features->training.rows) || (cellhd.cols != features->training.cols)) { - sprintf(tempbuf, "compute_features-> Dimension Error"); - G_fatal_error(tempbuf); + G_fatal_error("compute_features-> Dimension Error"); } rowbuf = (DCELL *)G_calloc(dim, sizeof(DCELL)); tf = rowbuf; @@ -225,8 +219,7 @@ void compute_features(Features *features) matrix[i] = features->training.data[i]; break; default: - sprintf(tempbuf, "compute_features-> Format not recognized"); - G_fatal_error(tempbuf); + G_fatal_error("compute_features-> Format not recognized"); break; } } @@ -338,14 +331,11 @@ void write_features(char *file, Features *features) FILE *fp; int i, j, l, k; int dim; - char tempbuf[500]; int write_x; fp = fopen(file, "w"); if (fp == NULL) { - sprintf(tempbuf, "write_features-> Can't open file %s for writing", - file); - G_fatal_error(tempbuf); + G_fatal_error("write_features-> Can't open file %s for writing", file); } fprintf(fp, "#####################\n"); @@ -546,16 +536,13 @@ void standardize_features(Features *features) int j, k; double *tmparray; - char tempbuf[500]; for (j = 2; j < 2 + features->f_standardize[1]; j++) { if ((features->f_standardize[j] < 0) || (features->f_standardize[j] >= features->examples_dim)) { - sprintf(tempbuf, - "standardize_features-> Can't standardize var number %d: " - "no such variable", - features->f_standardize[j] + 1); - G_fatal_error(tempbuf); + G_fatal_error("standardize_features-> Can't standardize var number " + "%d: no such variable", + features->f_standardize[j] + 1); } } @@ -575,11 +562,9 @@ void standardize_features(Features *features) features->sd[j - 2] = sd_of_double_array_given_mean( tmparray, features->nexamples, features->mean[j - 2]); if (features->sd[j - 2] == 0) { - sprintf( - tempbuf, + G_fatal_error( "standardize_features-> Can't standardize var number %d: sd=0", features->f_standardize[j] + 1); - G_fatal_error(tempbuf); } for (k = 0; k < features->nexamples; k++) { features->value[k][features->f_standardize[j]] = @@ -597,7 +582,6 @@ void write_header_features(FILE *fp, Features *features) */ { int i; - int dim; fprintf(fp, "#####################\n"); fprintf(fp, "TRAINING:\n"); @@ -612,8 +596,6 @@ void write_header_features(FILE *fp, Features *features) fprintf(fp, "Training dimensions:\n"); fprintf(fp, "%d\t%d\n", features->training.rows, features->training.cols); - dim = features->training.rows * features->training.cols; - fprintf(fp, "EW-res\tNS-res\n"); fprintf(fp, "%f\t%f\n", features->training.ew_res, features->training.ns_res); @@ -728,7 +710,6 @@ void read_features(char *file, Features *features, int npc) */ { FILE *fp; - char tempbuf[500]; char *line = NULL; int i, j, l, r; int dim; @@ -739,9 +720,7 @@ void read_features(char *file, Features *features, int npc) fp = fopen(file, "r"); if (fp == NULL) { - sprintf(tempbuf, "read_features-> Can't open file %s for reading", - file); - G_fatal_error(tempbuf); + G_fatal_error("read_features-> Can't open file %s for reading", file); } features->file = file; diff --git a/src/imagery/i.pr/PRLIB/features_selection.c b/src/imagery/i.pr/PRLIB/features_selection.c index bc948b6dac..a02038e216 100644 --- a/src/imagery/i.pr/PRLIB/features_selection.c +++ b/src/imagery/i.pr/PRLIB/features_selection.c @@ -15,10 +15,8 @@ #include #include -void compute_valoriDJ(svm, features, H_tot, H_tmp, - valoriDJ) SupportVectorMachine *svm; -Features *features; -double **H_tot, **H_tmp, **valoriDJ; +void compute_valoriDJ(SupportVectorMachine *svm, Features *features, + double **H_tot, double **H_tmp, double **valoriDJ) { double diag, resto; int i, j, t; @@ -69,7 +67,7 @@ double **H_tot, **H_tmp, **valoriDJ; } } -void free_svm(svm) SupportVectorMachine *svm; +void free_svm(SupportVectorMachine *svm) { int j; @@ -84,13 +82,9 @@ void free_svm(svm) SupportVectorMachine *svm; G_free(svm->precomputed_self_dot_product); } -void e_rfe_lin(svm, features, names, selected, i, rimanenti, fp_fs_w, - fp_fs_stats) SupportVectorMachine *svm; -Features *features; -int *names, *selected; -int i; -int *rimanenti; -FILE *fp_fs_w, *fp_fs_stats; +void e_rfe_lin(SupportVectorMachine *svm, Features *features, int *names, + int *selected, int i IPR_UNUSED, int *rimanenti, FILE *fp_fs_w, + FILE *fp_fs_stats) { double *wsquare; int j; @@ -270,15 +264,10 @@ FILE *fp_fs_w, *fp_fs_stats; G_free(wsquare); } -void e_rfe_gauss(valoriDJ, features, names, selected, i, H_tot, H_tmp, - rimanenti, svm_kp, fp_fs_w, fp_fs_stats) double *valoriDJ; -Features *features; -double **H_tot, **H_tmp; -int *names, *selected; -int i; -int *rimanenti; -double svm_kp; -FILE *fp_fs_w, *fp_fs_stats; +void e_rfe_gauss(double *valoriDJ, Features *features, int *names, + int *selected, int i IPR_UNUSED, double **H_tot, + double **H_tmp, int *rimanenti, double svm_kp, FILE *fp_fs_w, + FILE *fp_fs_stats) { int j; int *h; @@ -461,9 +450,8 @@ FILE *fp_fs_w, *fp_fs_stats; G_free(valorieliminati); } -void one_rfe_lin(svm, names, selected, fp_fs_w) SupportVectorMachine *svm; -int *names, *selected; -FILE *fp_fs_w; +void one_rfe_lin(SupportVectorMachine *svm, int *names, int *selected, + FILE *fp_fs_w) { double *wsquare; int i, j; @@ -494,10 +482,8 @@ FILE *fp_fs_w; G_free(sortindex); } -void one_rfe_gauss(valoriDJ, names, selected, n, fp_fs_w) double *valoriDJ; -int *names, *selected; -int n; -FILE *fp_fs_w; +void one_rfe_gauss(double *valoriDJ, int *names, int *selected, int n, + FILE *fp_fs_w) { int i, j; int *sortindex; @@ -521,12 +507,8 @@ FILE *fp_fs_w; G_free(sortindex); } -void rfe_lin(svm, features, names, selected, i, - fp_fs_w) SupportVectorMachine *svm; -Features *features; -int *names, *selected; -int i; -FILE *fp_fs_w; +void rfe_lin(SupportVectorMachine *svm, Features *features, int *names, + int *selected, int i, FILE *fp_fs_w) { double *wsquare; double wmin; @@ -568,14 +550,9 @@ FILE *fp_fs_w; G_free(wsquare); } -void rfe_gauss(valoriDJ, features, names, selected, i, H_tot, H_tmp, svm_kp, - fp_fs_w) Features *features; -double *valoriDJ; -int *names, *selected; -double **H_tot, **H_tmp; -int i; -double svm_kp; -FILE *fp_fs_w; +void rfe_gauss(double *valoriDJ, Features *features, int *names, int *selected, + int i, double **H_tot, double **H_tmp, double svm_kp, + FILE *fp_fs_w) { double wmin; int wmin_index; @@ -618,10 +595,8 @@ FILE *fp_fs_w; } } -void compute_H(matrix, XX, y, ndati, nfeat, sigma) double **matrix, **XX; -int *y; -double sigma; -int ndati, nfeat; +void compute_H(double **matrix, double **XX, int *y, int ndati, int nfeat, + double sigma) { int r, s; @@ -634,12 +609,8 @@ int ndati, nfeat; } } -void compute_H_perdiff(Hvecchia, Hnuova, XX, ndati, sigma, - featdaelim) double **Hvecchia, - **Hnuova, **XX; -double sigma; -int ndati, featdaelim; - +void compute_H_perdiff(double **Hvecchia, double **Hnuova, double **XX, + int ndati, double sigma, int featdaelim) // featdaelim e' la variabile numerata come numera C (0...nfeat-1) { int r, s; @@ -655,8 +626,7 @@ int ndati, featdaelim; } } -void traslo(x, n) double *x; -int n; +void traslo(double *x, int n) { int j; double m, M; diff --git a/src/imagery/i.pr/PRLIB/getline.c b/src/imagery/i.pr/PRLIB/getline.c index a600c1c562..63e3efb836 100644 --- a/src/imagery/i.pr/PRLIB/getline.c +++ b/src/imagery/i.pr/PRLIB/getline.c @@ -10,11 +10,10 @@ #include #include "global.h" -char *GetLine(fp) +char *GetLine(FILE *fp) /* get a line from a buffered stream (pointed from fp) */ -FILE *fp; { char line[BUFFSIZE], *p = NULL; diff --git a/src/imagery/i.pr/PRLIB/gm.c b/src/imagery/i.pr/PRLIB/gm.c index d180a92968..6ed96a9cde 100644 --- a/src/imagery/i.pr/PRLIB/gm.c +++ b/src/imagery/i.pr/PRLIB/gm.c @@ -12,8 +12,8 @@ #include #include -static void compute_covar(); -static void compute_mean(); +static void compute_covar(double ***, GaussianMixture *, int); +static void compute_mean(double ***, GaussianMixture *, int); void compute_gm(GaussianMixture *gm, int nsamples, int nvar, double **data, int *data_class, int nclasses, int *classes) @@ -133,12 +133,10 @@ void write_gm(char *file, GaussianMixture *gm, Features *features) { FILE *fpout; int i, j, k; - char tempbuf[500]; fpout = fopen(file, "w"); if (fpout == NULL) { - sprintf(tempbuf, "write_gm-> Can't open file %s for writing", file); - G_fatal_error(tempbuf); + G_fatal_error("write_gm-> Can't open file %s for writing", file); } write_header_features(fpout, features); @@ -209,7 +207,6 @@ void test_gm(GaussianMixture *gm, Features *features, char *file) int i, j; int *data_in_each_class; FILE *fp; - char tempbuf[500]; int predI; double predD; double *error; @@ -217,8 +214,7 @@ void test_gm(GaussianMixture *gm, Features *features, char *file) fp = fopen(file, "w"); if (fp == NULL) { - sprintf(tempbuf, "test_gm-> Can't open file %s for writing", file); - G_fatal_error(tempbuf); + G_fatal_error("test_gm-> Can't open file %s for writing", file); } data_in_each_class = (int *)G_calloc(features->nclasses, sizeof(int)); @@ -322,7 +318,6 @@ int predict_gm_multiclass(GaussianMixture *gm, double *x) double delta; double max_posterior; int max_posterior_index; - char tempbuf[500]; tmpVect = (double *)G_calloc(gm->nvars, sizeof(double)); distmean = (double *)G_calloc(gm->nvars, sizeof(double)); @@ -347,11 +342,9 @@ int predict_gm_multiclass(GaussianMixture *gm, double *x) posteriors[c] = exp(-0.5 * delta) / sqrt(gm->det[c]); } else { - sprintf( - tempbuf, + G_fatal_error( "predict_gm_multiclass-> det. of cov. matrix of class %d = 0", c); - G_fatal_error(tempbuf); } posteriors[c] = posteriors[c] * gm->priors[c]; } @@ -383,7 +376,6 @@ double predict_gm_2class(GaussianMixture *gm, double *x) double *distmean; double *posteriors; double delta; - char tempbuf[500]; tmpVect = (double *)G_calloc(gm->nvars, sizeof(double)); distmean = (double *)G_calloc(gm->nvars, sizeof(double)); @@ -408,10 +400,8 @@ double predict_gm_2class(GaussianMixture *gm, double *x) posteriors[c] = exp(-0.5 * delta) / sqrt(gm->det[c]); } else { - sprintf(tempbuf, - "predict_gm_2class-> det. of cov. matrix of class %d = 0", - c); - G_fatal_error(tempbuf); + G_fatal_error( + "predict_gm_2class-> det. of cov. matrix of class %d = 0", c); } posteriors[c] = posteriors[c] * gm->priors[c]; } diff --git a/src/imagery/i.pr/PRLIB/integration.c b/src/imagery/i.pr/PRLIB/integration.c index 8d37d4ce62..2504f59e22 100644 --- a/src/imagery/i.pr/PRLIB/integration.c +++ b/src/imagery/i.pr/PRLIB/integration.c @@ -19,14 +19,11 @@ #define EPS 1.0e-5 #define JMAX 1000 -double trapzd(func, a, b, n) +double trapzd(double (*func)(double), double a, double b, int n) /* trapezoidal rule for func=func(x) on interval [a,b] n = steps number */ -double a, b; -double (*func)(); -int n; { double x, tnm, sum, del; double s; @@ -46,16 +43,13 @@ int n; } } -double trapzd1(func, p1, a, b, n) +double trapzd1(double (*func)(double, double), double p1, double a, double b, + int n) /* trapezoidal rule for func=func(x; p1) on interval [a,b] p1 free parameter n = steps number */ -double a, b; -double p1; -double (*func)(); -int n; { double x, tnm, sum, del; double s; @@ -75,16 +69,13 @@ int n; } } -double trapzd2(func, p1, p2, a, b, n) +double trapzd2(double (*func)(double, double, double), double p1, double p2, + double a, double b, int n) /* trapezoidal rule for func=func(x; p1,p2) on interval [a,b] p1 and p2 free parameters n = steps number */ -double a, b; -double p1, p2; -double (*func)(); -int n; { double x, tnm, sum, del; double s; @@ -104,12 +95,10 @@ int n; } } -double qtrap(func, a, b) +double qtrap(double (*func)(double), double a, double b) /* trapezoidal rule for func=func(x) with stopping rule */ -double a, b; -double (*func)(); { int j; double s, olds; @@ -127,15 +116,12 @@ double (*func)(); return s; } -double qtrap1(func, p1, a, b) +double qtrap1(double (*func)(double, double), double p1, double a, double b) /* trapezoidal rule for func=func(x) on interval [a,b] with internal stopping rule p1 free parameter */ -double a, b; -double p1; -double (*func)(); { int j; double s, olds; @@ -143,7 +129,7 @@ double (*func)(); olds = -1.0e-30; for (j = 1; j <= JMAX; j++) { - s = trapzd(func, p1, a, b, j); + s = trapzd1(func, p1, a, b, j); if (fabs(s - olds) < EPS * fabs(olds)) return s; olds = s; @@ -153,15 +139,13 @@ double (*func)(); return s; } -double qtrap2(func, p1, p2, a, b) +double qtrap2(double (*func)(double, double, double), double p1, double p2, + double a, double b) /* trapezoidal rule for func=func(x) on interval [a,b] with internal stopping rule p1 and p2 free parameters */ -double a, b; -double p1, p2; -double (*func)(); { int j; double s, olds; @@ -169,7 +153,7 @@ double (*func)(); olds = -1.0e-30; for (j = 1; j <= JMAX; j++) { - s = trapzd(func, p1, p2, a, b, j); + s = trapzd2(func, p1, p2, a, b, j); if (fabs(s - olds) < EPS * fabs(olds)) return s; olds = s; diff --git a/src/imagery/i.pr/PRLIB/min_quadratic.c b/src/imagery/i.pr/PRLIB/min_quadratic.c index f4b2e672ba..b22488df37 100644 --- a/src/imagery/i.pr/PRLIB/min_quadratic.c +++ b/src/imagery/i.pr/PRLIB/min_quadratic.c @@ -10,7 +10,7 @@ #include #include #include -#include "func.h" +#include "global.h" void mqc(double **M, double *m, int n, double **H, double *h, int mH, double **K, double *k, int mK, double eps, double *x, double *minvalue) diff --git a/src/imagery/i.pr/PRLIB/nn.c b/src/imagery/i.pr/PRLIB/nn.c index 9642c519f7..7613a1f988 100644 --- a/src/imagery/i.pr/PRLIB/nn.c +++ b/src/imagery/i.pr/PRLIB/nn.c @@ -46,12 +46,10 @@ void write_nn(char *file, NearestNeighbor *nn, Features *features) { FILE *fpout; int i, j; - char tempbuf[500]; fpout = fopen(file, "w"); if (fpout == NULL) { - sprintf(tempbuf, "write_nn-> Can't open file <%s> for writing", file); - G_fatal_error(tempbuf); + G_fatal_error("write_nn-> Can't open file <%s> for writing", file); } write_header_features(fpout, features); @@ -210,7 +208,6 @@ void test_nn(NearestNeighbor *nn, Features *features, int k, char *file) int i, j; int *data_in_each_class; FILE *fp; - char tempbuf[500]; int predI; double predD; double *error; @@ -218,8 +215,7 @@ void test_nn(NearestNeighbor *nn, Features *features, int k, char *file) fp = fopen(file, "w"); if (fp == NULL) { - sprintf(tempbuf, "test_nn-> Can't open file %s for writing", file); - G_fatal_error(tempbuf); + G_fatal_error("test_nn-> Can't open file %s for writing", file); } data_in_each_class = (int *)G_calloc(features->nclasses, sizeof(int)); diff --git a/src/imagery/i.pr/PRLIB/open.c b/src/imagery/i.pr/PRLIB/open.c index bca6785ca6..b94947dc7d 100644 --- a/src/imagery/i.pr/PRLIB/open.c +++ b/src/imagery/i.pr/PRLIB/open.c @@ -10,51 +10,39 @@ #include #include -int open_new_CELL(name) +int open_new_CELL(char *name) /* open a new raster map of name name in CELL format */ -char *name; { int fd; - char err[400]; if (G_legal_filename(name) < 0) { - sprintf(err, "open_new_CELL-> %s - ** illegal name **", name); - G_fatal_error(err); - exit(1); + G_fatal_error("open_new_CELL-> %s - ** illegal name **", name); } fd = Rast_open_new(name, CELL_TYPE); if (fd < 0) { - sprintf(err, "open_new_CELL-> failed in attempt to open %s\n", name); - G_fatal_error(err); - exit(1); + G_fatal_error("open_new_CELL-> failed in attempt to open %s\n", name); } return fd; } int open_new_DCELL(char *name) - /* open a new raster map of name name in DELL format */ { int fd; - char err[400]; if (G_legal_filename(name) < 0) { - sprintf(err, "open_new_DCELL-> %s - ** illegal name **", name); - G_fatal_error(err); - exit(1); + G_fatal_error("open_new_DCELL-> %s - ** illegal name **", name); } fd = Rast_open_new(name, DCELL_TYPE); if (fd < 0) { - sprintf(err, "open_new_DCELL-> failed in attempt to open %s\n", name); - G_fatal_error(err); - exit(1); + G_fatal_error("open_new_DCELL-> failed in attempt to open %s\n", name); } return fd; diff --git a/src/imagery/i.pr/PRLIB/read_models.c b/src/imagery/i.pr/PRLIB/read_models.c index 018f5221bb..9aca578ee8 100644 --- a/src/imagery/i.pr/PRLIB/read_models.c +++ b/src/imagery/i.pr/PRLIB/read_models.c @@ -11,12 +11,12 @@ #include #include -static void read_bsvm(); -static void read_btree(); -static void read_tree(); -static void read_svm(); -static void read_gm(); -static void read_nn(); +static void read_bsvm(FILE *fp, BSupportVectorMachine **bsvm); +static void read_btree(FILE *fp, BTree **btree); +static void read_tree(FILE *fp, Tree **tree); +static void read_svm(FILE *fp, SupportVectorMachine **svm); +static void read_gm(FILE *fp, GaussianMixture **gm); +static void read_nn(FILE *fp, NearestNeighbor **nn); int read_model(char *file, Features *features, NearestNeighbor *nn, GaussianMixture *gm, Tree *tree, SupportVectorMachine *svm, @@ -27,14 +27,12 @@ int read_model(char *file, Features *features, NearestNeighbor *nn, { int model_type; FILE *fp; - char tempbuf[500]; char *line = NULL; int i; fp = fopen(file, "r"); if (fp == NULL) { - sprintf(tempbuf, "read_model-> Can't open file %s for reading", file); - G_fatal_error(tempbuf); + G_fatal_error("read_model-> Can't open file %s for reading", file); } read_header_features(fp, features); diff --git a/src/imagery/i.pr/PRLIB/sort.c b/src/imagery/i.pr/PRLIB/sort.c index 73c509338c..d4d712887c 100644 --- a/src/imagery/i.pr/PRLIB/sort.c +++ b/src/imagery/i.pr/PRLIB/sort.c @@ -14,7 +14,7 @@ #define ALN2I 1.442695022 #define TINY 1.0e-5 -static void indexx(); +static void indexx(int, double[], int[]); void shell(int n, double *arr) diff --git a/src/imagery/i.pr/PRLIB/svm.c b/src/imagery/i.pr/PRLIB/svm.c index 28e263f204..c48c4276fc 100644 --- a/src/imagery/i.pr/PRLIB/svm.c +++ b/src/imagery/i.pr/PRLIB/svm.c @@ -12,16 +12,19 @@ #include #include -static void svm_smo(); -static double learned_func_linear(); -static double learned_func_nonlinear(); -static double rbf_kernel(); -static double direct_kernel(); -static double dot_product_func(); -static int examineExample(); -static int takeStep(); -static int distance_from_span_sv(); -double dot_product(); +static void svm_smo(SupportVectorMachine *SVM); +static double learned_func_linear(int k, SupportVectorMachine *SVM); +static double learned_func_nonlinear(int k, SupportVectorMachine *SVM); +static double rbf_kernel(int i1, int i2, SupportVectorMachine *SVM); +// static double direct_kernel(); +static double dot_product_func(int i1, int i2, SupportVectorMachine *SVM); +static int examineExample(int i1, SupportVectorMachine *SVM); +static int takeStep(int i1, int i2, SupportVectorMachine *SVM); +static int distance_from_span_sv(double **M, double *m, int n, double Const, + double **H, double *h, int mH, double **K, + double *k, int mK, double eps, + double threshold); +// double dot_product(); void compute_svm(SupportVectorMachine *svm, int n, int d, double **x, int *y, int svm_kernel, double svm_kp, double svm_C, double svm_tol, @@ -916,7 +919,6 @@ void write_svm(char *file, SupportVectorMachine *svm, Features *features) { FILE *fpout; int i, j; - char tempbuf[500]; int np_weights = 0; for (i = 0; i < svm->N; i++) { @@ -926,8 +928,7 @@ void write_svm(char *file, SupportVectorMachine *svm, Features *features) } if ((fpout = fopen(file, "w")) == NULL) { - sprintf(tempbuf, "write_svm-> Can't open file %s for writing", file); - G_fatal_error(tempbuf); + G_fatal_error("write_svm-> Can't open file %s for writing", file); } write_header_features(fpout, features); @@ -1023,15 +1024,13 @@ void test_svm(SupportVectorMachine *svm, Features *features, char *file) int i, j; int *data_in_each_class; FILE *fp; - char tempbuf[500]; double pred; double *error; double accuracy; fp = fopen(file, "w"); if (fp == NULL) { - sprintf(tempbuf, "test_svm-> Can't open file %s for writing", file); - G_fatal_error(tempbuf); + G_fatal_error("test_svm-> Can't open file %s for writing", file); } data_in_each_class = (int *)G_calloc(features->nclasses, sizeof(int)); @@ -1232,16 +1231,14 @@ void write_bagging_boosting_svm(char *file, BSupportVectorMachine *bsvm, { int i, j; FILE *fp; - char tempbuf[500]; int b; int np_weights; fp = fopen(file, "w"); if (fp == NULL) { - sprintf(tempbuf, - "write_bagging_boosting_svm-> Can't open file %s for writing", - file); - G_fatal_error(tempbuf); + G_fatal_error( + "write_bagging_boosting_svm-> Can't open file %s for writing", + file); } write_header_features(fp, features); @@ -1342,10 +1339,10 @@ void write_bagging_boosting_svm(char *file, BSupportVectorMachine *bsvm, void compute_svm_boosting(BSupportVectorMachine *bsvm, int boosting, double w, int nsamples, int nvar, double **data, - int *data_class, int nclasses, int *classes, - int svm_kernel, double kp, double C, double tol, - double svm_eps, int maxloops, int svm_verbose, - double *svm_W, int weights_boosting) + int *data_class, int nclasses IPR_UNUSED, + int *classes, int svm_kernel, double kp, double C, + double tol, double svm_eps, int maxloops, + int svm_verbose, double *svm_W, int weights_boosting) { int i, b; int *bsamples; @@ -1535,15 +1532,13 @@ void test_bsvm(BSupportVectorMachine *bsvm, Features *features, char *file) int i, j; int *data_in_each_class; FILE *fp; - char tempbuf[500]; double pred; double *error; double accuracy; fp = fopen(file, "w"); if (fp == NULL) { - sprintf(tempbuf, "test_bsvm-> Can't open file %s for writing", file); - G_fatal_error(tempbuf); + G_fatal_error("test_bsvm-> Can't open file %s for writing", file); } data_in_each_class = (int *)G_calloc(features->nclasses, sizeof(int)); @@ -1613,7 +1608,6 @@ void test_bsvm_progressive(BSupportVectorMachine *bsvm, Features *features, int i, j; int *data_in_each_class; FILE *fp; - char tempbuf[500]; double pred; double *error; double accuracy; @@ -1621,8 +1615,7 @@ void test_bsvm_progressive(BSupportVectorMachine *bsvm, Features *features, fp = fopen(file, "w"); if (fp == NULL) { - sprintf(tempbuf, "test_bsvm-> Can't open file %s for writing", file); - G_fatal_error(tempbuf); + G_fatal_error("test_bsvm-> Can't open file %s for writing", file); } data_in_each_class = (int *)G_calloc(features->nclasses, sizeof(int)); @@ -1726,8 +1719,10 @@ double dot_product(double *x, double *y, int n) double out = .0; n--; - while (n >= 0) - out += x[n] * y[n--]; + while (n >= 0) { + out += x[n] * y[n - 1]; + n--; + } return out; } diff --git a/src/imagery/i.pr/PRLIB/test.c b/src/imagery/i.pr/PRLIB/test.c index 16886f3994..dcbcbf8629 100644 --- a/src/imagery/i.pr/PRLIB/test.c +++ b/src/imagery/i.pr/PRLIB/test.c @@ -22,12 +22,6 @@ #define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif -double probks(); -double probks2(); -double betai(); -double gammln(); -double betacf(); - void ksone_normal(double *data, int n, double p1, double p2, double *d, double *prob) @@ -132,14 +126,13 @@ double probks2(double alam, int ndata) return (p); } -double normal_distribution(x, mu, sigma) +double normal_distribution(double x, double mu, double sigma) /* normal distribution with mean mu and standard deviation sigma computed at point x 1/(sigma*sqrt(PIG) exp(-(x-mu)^2/2sigma^2) */ -double x, mu, sigma; { return exp(-1 * (x - mu) * (x - mu) / (2.0 * sigma * sigma)) / (sigma * sqrt(2 * PIG)); @@ -242,9 +235,10 @@ double betai(double a, double b, double x) } } -double sqrarg; - -#define SQR(a) (sqrarg = (a), sqrarg * sqrarg) +static inline double SQR(double a) +{ + return a * a; +} void tutest(double *data1, int n1, double *data2, int n2, double *t, double *prob) diff --git a/src/imagery/i.pr/PRLIB/training.c b/src/imagery/i.pr/PRLIB/training.c index 036467cd06..6d16a97bcc 100644 --- a/src/imagery/i.pr/PRLIB/training.c +++ b/src/imagery/i.pr/PRLIB/training.c @@ -55,13 +55,11 @@ void read_training(char *file, Training *training) fp = fopen(file, "r"); if (fp == NULL) { - sprintf(tempbuf, "read_training-> Can't open file %s for reading", - file); - G_fatal_error(tempbuf); + G_fatal_error("read_training-> Can't open file %s for reading", file); } if (G_getl2(tempbuf, sizeof(tempbuf) - 1, fp) == 0) { - G_fatal_error("read_training-> File %s is empty", file); fclose(fp); + G_fatal_error("read_training-> File %s is empty", file); } training->file = file; @@ -85,10 +83,8 @@ void read_training(char *file, Training *training) line = GetLine(fp); sscanf(line, "%d", &(training->nlayers)); if (training->nlayers > TRAINING_MAX_LAYERS) { - sprintf(tempbuf, - "read_training-> Maximum number of layers is %d", - TRAINING_MAX_LAYERS); - G_fatal_error(tempbuf); + G_fatal_error("read_training-> Maximum number of layers is %d", + TRAINING_MAX_LAYERS); } line = GetLine(fp); line = GetLine(fp); @@ -100,9 +96,8 @@ void read_training(char *file, Training *training) line = GetLine(fp); sscanf(line, "%d", &nlayers); if (nlayers != training->nlayers) { - sprintf(tempbuf, "read_training-> Training files must contain " - "same number of layers"); - G_fatal_error(tempbuf); + G_fatal_error("read_training-> Training files must contain " + "same number of layers"); } line = GetLine(fp); line = GetLine(fp); @@ -171,33 +166,26 @@ void read_training(char *file, Training *training) if (training->nexamples > 0) { if ((tmprow != training->rows) || (tmpcol != training->cols)) { - sprintf(tempbuf, - "read_training-> Example %d: different number of " - "rows or cols", - training->nexamples + 1); - G_fatal_error(tempbuf); + G_fatal_error("read_training-> Example %d: different " + "number of rows or cols", + training->nexamples + 1); } if (fabs((tmpew - training->ew_res) / training->ew_res) > 0.1) { - sprintf(tempbuf, - "read_training-> Example %d: EW-resolution differs " - "more than 10%%", - training->nexamples + 1); - G_warning(tempbuf); + G_warning("read_training-> Example %d: EW-resolution " + "differs more than 10%%", + training->nexamples + 1); } if (fabs((tmpns - training->ns_res) / training->ns_res) > 0.1) { - sprintf(tempbuf, - "read_training-> Example %d: NS-resolution differs " - "more than 10%%", - training->nexamples + 1); - G_warning(tempbuf); + G_warning("read_training-> Example %d: NS-resolution " + "differs more than 10%%", + training->nexamples + 1); } } training->nexamples += 1; if (training->nexamples == TRAINING_MAX_EXAMPLES) { - sprintf(tempbuf, - "read_training-> Maximum number of training data is %d", - TRAINING_MAX_EXAMPLES); - G_fatal_error(tempbuf); + G_fatal_error( + "read_training-> Maximum number of training data is %d", + TRAINING_MAX_EXAMPLES); } } break; @@ -217,9 +205,8 @@ void read_training(char *file, Training *training) line = GetLine(fp); sscanf(line, "%d", &(tmpc)); if (tmpc != training->cols) { - sprintf(tempbuf, "read_training-> training data must have same " - "number of columns"); - G_fatal_error(tempbuf); + G_fatal_error("read_training-> training data must have same " + "number of columns"); } } line = GetLine(fp); @@ -234,18 +221,15 @@ void read_training(char *file, Training *training) sscanf(line, "%d", &(training->class[training->nexamples])); training->nexamples += 1; if (training->nexamples == TRAINING_MAX_EXAMPLES) { - sprintf(tempbuf, - "read_training-> Maximum number of training data is %d", - TRAINING_MAX_EXAMPLES); - G_fatal_error(tempbuf); + G_fatal_error( + "read_training-> Maximum number of training data is %d", + TRAINING_MAX_EXAMPLES); } } break; default: - sprintf(tempbuf, "read_training-> Format not recognized"); - G_fatal_error(tempbuf); - break; + G_fatal_error("read_training-> Format not recognized"); } fclose(fp); } diff --git a/src/imagery/i.pr/PRLIB/tree.c b/src/imagery/i.pr/PRLIB/tree.c index 6996d73e83..e5705fc534 100644 --- a/src/imagery/i.pr/PRLIB/tree.c +++ b/src/imagery/i.pr/PRLIB/tree.c @@ -12,7 +12,7 @@ #include #include -static void split_node(); +static void split_node(Node *, Node *, Node *, int *, int, double *); void compute_tree(Tree *tree, int nsamples, int nvar, double **data, int *data_class, int nclasses, int *classes, int stamps, @@ -328,12 +328,10 @@ void write_tree(char *file, Tree *tree, Features *features) { int i, j; FILE *fp; - char tempbuf[500]; fp = fopen(file, "w"); if (fp == NULL) { - sprintf(tempbuf, "write_tree-> Can't open file %s for writing", file); - G_fatal_error(tempbuf); + G_fatal_error("write_tree-> Can't open file %s for writing", file); } write_header_features(fp, features); @@ -1224,15 +1222,13 @@ void write_bagging_boosting_tree(char *file, BTree *btree, Features *features) { int i, j; FILE *fp; - char tempbuf[500]; int b; fp = fopen(file, "w"); if (fp == NULL) { - sprintf(tempbuf, - "write_bagging_boosting_tree-> Can't open file %s for writing", - file); - G_fatal_error(tempbuf); + G_fatal_error( + "write_bagging_boosting_tree-> Can't open file %s for writing", + file); } write_header_features(fp, features); @@ -1369,7 +1365,6 @@ void test_tree(Tree *tree, Features *features, char *file) int i, j; int *data_in_each_class; FILE *fp; - char tempbuf[500]; int predI; double predD; double *error; @@ -1377,8 +1372,7 @@ void test_tree(Tree *tree, Features *features, char *file) fp = fopen(file, "w"); if (fp == NULL) { - sprintf(tempbuf, "test_tree-> Can't open file %s for writing", file); - G_fatal_error(tempbuf); + G_fatal_error("test_tree-> Can't open file %s for writing", file); } data_in_each_class = (int *)G_calloc(features->nclasses, sizeof(int)); @@ -1513,7 +1507,6 @@ void test_btree(BTree *btree, Features *features, char *file) int i, j; int *data_in_each_class; FILE *fp; - char tempbuf[500]; int predI; double predD; double *error; @@ -1521,8 +1514,7 @@ void test_btree(BTree *btree, Features *features, char *file) fp = fopen(file, "w"); if (fp == NULL) { - sprintf(tempbuf, "test_btree-> Can't open file %s for writing", file); - G_fatal_error(tempbuf); + G_fatal_error("test_btree-> Can't open file %s for writing", file); } data_in_each_class = (int *)G_calloc(features->nclasses, sizeof(int)); @@ -1603,7 +1595,6 @@ void test_btree_progressive(BTree *btree, Features *features, char *file) int i, j; int *data_in_each_class; FILE *fp; - char tempbuf[500]; int predI; double predD; double *error; @@ -1612,8 +1603,7 @@ void test_btree_progressive(BTree *btree, Features *features, char *file) fp = fopen(file, "w"); if (fp == NULL) { - sprintf(tempbuf, "test_btree-> Can't open file %s for writing", file); - G_fatal_error(tempbuf); + G_fatal_error("test_btree-> Can't open file %s for writing", file); } data_in_each_class = (int *)G_calloc(features->nclasses, sizeof(int)); @@ -1758,12 +1748,10 @@ int predict_btree_multiclass_progressive(BTree *btree, double *x, int nclasses, return classes[max_class]; } -void compute_tree_boosting_parallel(BTree *btree, int boosting, - int parallel_boosting, double w, - int nsamples, int nvar, double **data, - int *data_class, int nclasses, int *classes, - int stamps, int minsize, - int weights_boosting, double *costs) +void compute_tree_boosting_parallel( + BTree *btree, int boosting, int parallel_boosting, double w, int nsamples, + int nvar, double **data, int *data_class, int nclasses, int *classes, + int stamps, int minsize, int weights_boosting IPR_UNUSED, double *costs) /* receives in input training data of dimensions nsamples x nvar, diff --git a/src/imagery/i.pr/PRLIB/write_matrix.c b/src/imagery/i.pr/PRLIB/write_matrix.c index d0d9e0c83c..2ca1bfb81c 100644 --- a/src/imagery/i.pr/PRLIB/write_matrix.c +++ b/src/imagery/i.pr/PRLIB/write_matrix.c @@ -5,13 +5,11 @@ void write_matrix(char *outfile, double **matrix, int r, int c) { FILE *fp; int i, j; - char tempbuf[500]; fp = fopen(outfile, "w"); if (fp == NULL) { - sprintf(tempbuf, "write_matrix-> Can't open file <%s> for writing", - outfile); - G_fatal_error(tempbuf); + G_fatal_error("write_matrix-> Can't open file <%s> for writing", + outfile); } for (i = 0; i < r; i++) { diff --git a/src/imagery/i.pr/i.pr.blob/i.pr.blob.html b/src/imagery/i.pr/i.pr.blob/i.pr.blob.html new file mode 100644 index 0000000000..558e6ab133 --- /dev/null +++ b/src/imagery/i.pr/i.pr.blob/i.pr.blob.html @@ -0,0 +1,7 @@ +

DESCRIPTION

+ +Module to search for blobs. + +

AUTHORS

+ +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.blob/i.pr.blob.md b/src/imagery/i.pr/i.pr.blob/i.pr.blob.md new file mode 100644 index 0000000000..615f52b7d0 --- /dev/null +++ b/src/imagery/i.pr/i.pr.blob/i.pr.blob.md @@ -0,0 +1,7 @@ +## DESCRIPTION + +Module to search for blobs. + +## AUTHORS + +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.blob/main.c b/src/imagery/i.pr/i.pr.blob/main.c index 455a025dd8..287e9858fc 100644 --- a/src/imagery/i.pr/i.pr.blob/main.c +++ b/src/imagery/i.pr/i.pr.blob/main.c @@ -32,7 +32,6 @@ int main(int argc, char *argv[]) struct Option *opt3; struct Option *opt4; struct Option *opt5; - char tempbuf[500]; char *mapset; struct Cell_head cellhd; double **matrix; @@ -104,14 +103,11 @@ int main(int argc, char *argv[]) sscanf(opt5->answer, "%lf", &maxv); if ((mapset = (char *)G_find_raster2(opt1->answer, "")) == NULL) { - sprintf(tempbuf, "can't open raster map <%s> for reading", - opt1->answer); - G_fatal_error(tempbuf); + G_fatal_error("can't open raster map <%s> for reading", opt1->answer); } if ((fd = Rast_open_old(opt1->answer, mapset)) < 0) { - sprintf(tempbuf, "error opening raster map <%s>", opt1->answer); - G_fatal_error(tempbuf); + G_fatal_error("error opening raster map <%s>", opt1->answer); } G_get_window(&cellhd); diff --git a/src/imagery/i.pr/i.pr.classify/i.pr.classify.html b/src/imagery/i.pr/i.pr.classify/i.pr.classify.html new file mode 100644 index 0000000000..f973b30576 --- /dev/null +++ b/src/imagery/i.pr/i.pr.classify/i.pr.classify.html @@ -0,0 +1,35 @@ +

DESCRIPTION

+ +Classifies GRASS raster maps based on a classification model. Given a number +of input GRASS raster maps (input_map), where the order +must be the same as that used for training data extraction (!!!!), and a +classification model (model), a GRASS raster map containing +the classification result is produced. + +Map values ​​by model type: + +
    +
  • Binary Gaussian Mixture: posterior probability of the most likely class + multiplied by the class itself {−1, 1}
  • +
  • Multiclass Gaussian Mixture: most likely class
  • +
  • Binary Nearest Neighbor: proportion of data in the most likely class + multiplied by the class itself {−1, 1}
  • +
  • Multiclass Nearest Neighbor: most likely class
  • +
  • Binary Classification Trees: proportion of data in the most likely + class at the terminal node multiplied by the class itself {−1, 1}
  • +
  • Multiclass Classification Trees: most likely class
  • +
  • Binary Support Vector Machines: output of the support vector machine + itself (−∞, ∞)
  • +
  • Multiclass Bagging Classification Trees: most likely class
  • +
  • Binary Bagging Classification Trees: weighted sum of models (−1, 1)
  • +
  • Boosting Classification Trees (binary only): weighted sum of + models (−1, 1)
  • +
  • Bagging Support Vector machines (binary only): weighted sum of + patterns (−1, 1)
  • +
  • Boosting support vector machines (binary only): weighted sum of + patterns (−1, 1)
  • +
+ +

AUTHORS

+ +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.classify/i.pr.classify.md b/src/imagery/i.pr/i.pr.classify/i.pr.classify.md new file mode 100644 index 0000000000..252215b4c5 --- /dev/null +++ b/src/imagery/i.pr/i.pr.classify/i.pr.classify.md @@ -0,0 +1,32 @@ +## DESCRIPTION + +Classifies GRASS raster maps based on a classification model. Given a number +of input GRASS raster maps (**input\_map**), where the order must be +the same as that used for training data extraction (!!!!), and a +classification model (**model**), a GRASS raster map containing +the classification result is produced. + +Map values ​​by model type: + +- Binary Gaussian Mixture: posterior probability of the most likely class + multiplied by the class itself {−1, 1} +- Multiclass Gaussian Mixture: most likely class +- Binary Nearest Neighbor: proportion of data in the most likely class + multiplied by the class itself {−1, 1} +- Multiclass Nearest Neighbor: most likely class +- Binary Classification Trees: proportion of data in the most likely class + at the terminal node multiplied by the class itself {−1, 1} +- Multiclass Classification Trees: most likely class +- Binary Support Vector Machines: output of the support vector + machine itself (−∞, ∞) +- Multiclass Bagging Classification Trees: most likely class +- Binary Bagging Classification Trees: weighted sum of models (−1, 1) +- Boosting Classification Trees (binary only): weighted sum of models (−1, 1) +- Bagging Support Vector machines (binary only): weighted sum of + patterns (−1, 1) +- Boosting support vector machines (binary only): weighted sum of + patterns (−1, 1) + +## AUTHORS + +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.classify/main.c b/src/imagery/i.pr/i.pr.classify/main.c index 54f9233423..2edf96cbe8 100644 --- a/src/imagery/i.pr/i.pr.classify/main.c +++ b/src/imagery/i.pr/i.pr.classify/main.c @@ -24,7 +24,7 @@ #include #include "global.h" -int extract_array_with_null(); +int extract_array_with_null(int, int, int, int, double **, double *); int main(int argc, char *argv[]) { @@ -39,7 +39,6 @@ int main(int argc, char *argv[]) SupportVectorMachine svm; BTree btree; BSupportVectorMachine bsvm; - char tmpbuf[500]; char *mapset; struct Cell_head cellhd; double ***matrix; @@ -84,7 +83,7 @@ int main(int argc, char *argv[]) opt2->type = TYPE_STRING; opt2->required = YES; opt2->description = - "Input file containing the model (output of i .pr_model).\n\t\tIf the " + "Input file containing the model (output of i .pr.model).\n\t\tIf the " "data used for model development are not GRASS_data the program will " "abort."; @@ -119,12 +118,10 @@ int main(int argc, char *argv[]) &btree, &bsvm); if (features.training.data_type != GRASS_data) { - sprintf(tmpbuf, "Model build using othe than GRASS data\n"); - G_fatal_error(tmpbuf); + G_fatal_error("Model build using othe than GRASS data\n"); } if (model_type == 0) { - sprintf(tmpbuf, "Model not recognized\n"); - G_fatal_error(tmpbuf); + G_fatal_error("Model not recognized\n"); } if (model_type == GM_model) { @@ -135,15 +132,13 @@ int main(int argc, char *argv[]) G_get_window(&cellhd); if (fabs((cellhd.ew_res - features.training.ew_res) / features.training.ew_res) > 0.1) { - sprintf(tmpbuf, "EW resolution of training data and test map differs " - "more than 10%%\n"); - G_warning(tmpbuf); + G_warning("EW resolution of training data and test map differs more " + "than 10%%\n"); } if (fabs((cellhd.ns_res - features.training.ns_res) / features.training.ns_res) > 0.1) { - sprintf(tmpbuf, "NS resolution of training data and test map differs " - "more than 10%%\n"); - G_warning(tmpbuf); + G_warning("NS resolution of training data and test map differs more " + "than 10%%\n"); } /*compute features space */ @@ -207,26 +202,21 @@ int main(int argc, char *argv[]) n_input_map = 0; for (l = 0; opt1->answers[l]; l++) { if ((mapset = (char *)G_find_raster2(opt1->answers[l], "")) == NULL) { - sprintf(tmpbuf, "raster map [%s] not available", opt1->answers[l]); - G_fatal_error(tmpbuf); + G_fatal_error("raster map [%s] not available", opt1->answers[l]); } if ((fd[l] = Rast_open_old(opt1->answers[l], mapset)) < 0) { - sprintf(tmpbuf, "error opening raster map [%s]", opt1->answers[l]); - G_fatal_error(tmpbuf); + G_fatal_error("error opening raster map [%s]", opt1->answers[l]); } n_input_map += 1; } if (n_input_map < features.training.nlayers) { - sprintf(tmpbuf, "Model requires %d input maps\n", - features.training.nlayers); - G_fatal_error(tmpbuf); + G_fatal_error("Model requires %d input maps\n", + features.training.nlayers); } if (n_input_map > features.training.nlayers) { - sprintf(tmpbuf, "Only first %d maps considered\n", - features.training.nlayers); - G_warning(tmpbuf); + G_warning("Only first %d maps considered\n", features.training.nlayers); } /*open the output map */ diff --git a/src/imagery/i.pr/i.pr.features/description.html b/src/imagery/i.pr/i.pr.features/description.html deleted file mode 100644 index beb982f973..0000000000 --- a/src/imagery/i.pr/i.pr.features/description.html +++ /dev/null @@ -1,18 +0,0 @@ -

DESCRIPTION

- -i.pr.features This module is used to preprocess and extract the training features. It is necessary to specify the training file, which contains the names of the raster maps (explanatory variables) to be used in subsequent modules. The training file can either be the output from from i.pr.training (Recommended) or an ascii file containing the names of rasters. -

-This module allows for the calculation of a range of statistics pertaining to the explanatory variables, which include the mean and variance. In addition the features can be normalized to a similar scale. In each case, it is possible to specify the numbers of features for which these statistics should be computed (i.e. number in list). There is also the possibility to compute principal components for the explanatory variables. The default calculates them for all layers, or else only on selected classes specified by 'class_pc'. Variables can be standardised using parameter 'standardize', this is linked to the features previously calculated and not layers in the training file. - -

NOTES

- - -

SEE ALSO

- -i.pr.training
-i.pca
- -

AUTHORS

- -Stefano Merler, FBK, Trento, Italy
-Documentation: Daniel McInerney (daniel.mcinerney ucd.ie) diff --git a/src/imagery/i.pr/i.pr.features/i.pr.features.html b/src/imagery/i.pr/i.pr.features/i.pr.features.html new file mode 100644 index 0000000000..5e41f8a57e --- /dev/null +++ b/src/imagery/i.pr/i.pr.features/i.pr.features.html @@ -0,0 +1,32 @@ +

DESCRIPTION

+ +This module is used to preprocess and extract the training features. It +is necessary to specify the training file, which contains the names of +the raster maps (explanatory variables) to be used in subsequent modules. +The training file can either be the output from from +i.pr.training (Recommended) +or an ascii file containing the names of rasters. +

+This module allows for the calculation of a range of statistics pertaining +to the explanatory variables, which include the mean and variance. In +addition the features can be normalized to a similar scale. In each case, +it is possible to specify the numbers of features for which these statistics +should be computed (i.e. number in list). There is also the possibility to +compute principal components for the explanatory variables. The default +calculates them for all layers, or else only on selected classes specified +by class_pc. Variables can be standardised using parameter +standardize, this is linked to the features previously calculated +and not layers in the training file. + +

NOTES

+ + +

SEE ALSO

+ +i.pr.training
+i.pca
+ +

AUTHORS

+ +Stefano Merler, FBK, Trento, Italy
+Documentation: Daniel McInerney (daniel.mcinerney ucd.ie) diff --git a/src/imagery/i.pr/i.pr.features/description.md b/src/imagery/i.pr/i.pr.features/i.pr.features.md similarity index 54% rename from src/imagery/i.pr/i.pr.features/description.md rename to src/imagery/i.pr/i.pr.features/i.pr.features.md index a647ca51d8..7d9a26318c 100644 --- a/src/imagery/i.pr/i.pr.features/description.md +++ b/src/imagery/i.pr/i.pr.features/i.pr.features.md @@ -1,11 +1,10 @@ ## DESCRIPTION -*i.pr.features* This module is used to preprocess and extract the -training features. It is necessary to specify the training file, which -contains the names of the raster maps (explanatory variables) to be used -in subsequent modules. The training file can either be the output from -from *[i.pr.training](i.pr.training.md)* (Recommended) or an ascii file -containing the names of rasters. +This module is used to preprocess and extract the training features. It is +necessary to specify the training file, which contains the names of the raster +maps (explanatory variables) to be used in subsequent modules. The training +file can either be the output from from *[i.pr.training](i.pr.training.md)* +(Recommended) or an ascii file containing the names of rasters. This module allows for the calculation of a range of statistics pertaining to the explanatory variables, which include the mean and @@ -14,18 +13,18 @@ In each case, it is possible to specify the numbers of features for which these statistics should be computed (i.e. number in list). There is also the possibility to compute principal components for the explanatory variables. The default calculates them for all layers, or -else only on selected classes specified by 'class\_pc'. Variables can be -standardised using parameter 'standardize', this is linked to the +else only on selected classes specified by **class\_pc**. Variables can be +standardised using parameter **standardize**, this is linked to the features previously calculated and not layers in the training file. ## NOTES ## SEE ALSO -*[i.pr.training](i.pr.training.md)* -*[i.pca](https://grass.osgeo.org/grass-stable/manuals/i.pca.html)* +*[i.pr.training](i.pr.training.md)* +*[i.pca](https://grass.osgeo.org/grass-stable/manuals/i.pca.html)* ## AUTHORS -Stefano Merler, FBK, Trento, Italy +Stefano Merler, FBK, Trento, Italy Documentation: Daniel McInerney (daniel.mcinerney ucd.ie) diff --git a/src/imagery/i.pr/i.pr.features/main.c b/src/imagery/i.pr/i.pr.features/main.c index 5a7e2d7bf0..ca4194b6f7 100644 --- a/src/imagery/i.pr/i.pr.features/main.c +++ b/src/imagery/i.pr/i.pr.features/main.c @@ -43,7 +43,6 @@ int main(int argc, char **argv) Features features; char *tmpbuf; int nclasses_for_pca; - char tempbuf[500]; char opt1desc[500]; FILE *fp; @@ -143,9 +142,8 @@ int main(int argc, char **argv) for (i = 0; (training_file[ntraining_file] = opt1->answers[i]); i++) { ntraining_file += 1; if (ntraining_file > TRAINING_MAX_INPUTFILES) { - sprintf(tempbuf, "Maximum nomber of allowed training files is %d", - TRAINING_MAX_INPUTFILES); - G_fatal_error(tempbuf); + G_fatal_error("Maximum nomber of allowed training files is %d", + TRAINING_MAX_INPUTFILES); } } @@ -157,8 +155,7 @@ int main(int argc, char **argv) if (flag_s->answer) { if ((fp = fopen(opt2->answer, "w")) == NULL) { - sprintf(tempbuf, "Can't open file %s for writing", opt2->answer); - G_fatal_error(tempbuf); + G_fatal_error("Can't open file %s for writing", opt2->answer); } for (i = 0; i < features.training.nexamples; i++) { fprintf(fp, "%f|%f|#%d\n", features.training.east[i], @@ -192,8 +189,7 @@ int main(int argc, char **argv) sscanf(opt4->answers[i - 2], "%d", &(features.f_normalize[i])); if ((features.f_normalize[i] <= 0) || (features.f_normalize[i] > features.training.nlayers)) { - sprintf(tempbuf, "nlayers = %d\n", features.training.nlayers); - G_fatal_error(tempbuf); + G_fatal_error("nlayers = %d\n", features.training.nlayers); } features.f_normalize[i] -= 1; } @@ -214,8 +210,7 @@ int main(int argc, char **argv) sscanf(opt6->answers[i - 2], "%d", &(features.f_mean[i])); if ((features.f_mean[i] <= 0) || (features.f_mean[i] > features.training.nlayers)) { - sprintf(tempbuf, "nlayers = %d\n", features.training.nlayers); - G_fatal_error(tempbuf); + G_fatal_error("nlayers = %d\n", features.training.nlayers); } features.f_mean[i] -= 1; } @@ -236,8 +231,7 @@ int main(int argc, char **argv) sscanf(opt7->answers[i - 2], "%d", &(features.f_variance[i])); if ((features.f_variance[i] <= 0) || (features.f_variance[i] > features.training.nlayers)) { - sprintf(tempbuf, "nlayers = %d\n", features.training.nlayers); - G_fatal_error(tempbuf); + G_fatal_error("nlayers = %d\n", features.training.nlayers); } features.f_variance[i] -= 1; } @@ -258,8 +252,7 @@ int main(int argc, char **argv) sscanf(opt8->answers[i - 2], "%d", &(features.f_pca[i])); if ((features.f_pca[i] <= 0) || (features.f_pca[i] > features.training.nlayers)) { - sprintf(tempbuf, "nlayers = %d\n", features.training.nlayers); - G_fatal_error(tempbuf); + G_fatal_error("nlayers = %d\n", features.training.nlayers); } features.f_pca[i] -= 1; } diff --git a/src/imagery/i.pr/i.pr.features_additional/i.pr.features_additional.html b/src/imagery/i.pr/i.pr.features_additional/i.pr.features_additional.html new file mode 100644 index 0000000000..93c45ed740 --- /dev/null +++ b/src/imagery/i.pr/i.pr.features_additional/i.pr.features_additional.html @@ -0,0 +1,9 @@ +

DESCRIPTION

+ +Given a features file (features option), apply the rules that +created those features to a list of training files (training option) +and create a new features file from these (features_out option). + +

AUTHORS

+ +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.features_additional/i.pr.features_additional.md b/src/imagery/i.pr/i.pr.features_additional/i.pr.features_additional.md new file mode 100644 index 0000000000..686994e78b --- /dev/null +++ b/src/imagery/i.pr/i.pr.features_additional/i.pr.features_additional.md @@ -0,0 +1,9 @@ +## DESCRIPTION + +Given a features file (**features** option), apply the rules that created those +features to a list of training files (**training** option) and create a +new features file from these (**features\_out** option). + +## AUTHORS + +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.features_additional/main.c b/src/imagery/i.pr/i.pr.features_additional/main.c index f9acfe1c7f..de6bc5ff1c 100644 --- a/src/imagery/i.pr/i.pr.features_additional/main.c +++ b/src/imagery/i.pr/i.pr.features_additional/main.c @@ -24,7 +24,7 @@ #include #include "global.h" -void generate_features(); +void generate_features(Features *, Features *); int main(int argc, char **argv) { @@ -37,7 +37,6 @@ int main(int argc, char **argv) int ntraining_file; int i; Features features, features_out; - char tempbuf[500]; char opt1desc[500]; /* Initialize the GIS calls */ @@ -57,7 +56,7 @@ int main(int argc, char **argv) sprintf(opt1desc, "Input files (max %d) containing training data.\n\t\t2 formats are " "currently supported:\n\t\t1) GRASS_data (output of " - "i.pr_training)\n\t\t2) TABLE_data.", + "i.pr.training)\n\t\t2) TABLE_data.", TRAINING_MAX_INPUTFILES); /* set up command line */ @@ -89,9 +88,8 @@ int main(int argc, char **argv) for (i = 0; (training_file[ntraining_file] = opt1->answers[i]); i++) { ntraining_file += 1; if (ntraining_file > TRAINING_MAX_INPUTFILES) { - sprintf(tempbuf, "Maximum nomber of allowed training files is %d", - TRAINING_MAX_INPUTFILES); - G_fatal_error(tempbuf); + G_fatal_error("Maximum nomber of allowed training files is %d", + TRAINING_MAX_INPUTFILES); } } @@ -133,7 +131,7 @@ int main(int argc, char **argv) return 0; } -void generate_features(Features *features, Features *features_out) +void generate_features(Features *features IPR_UNUSED, Features *features_out) { int i, j, k, l; char *mapset; @@ -143,7 +141,6 @@ void generate_features(Features *features, Features *features_out) DCELL *tf; DCELL **matrix; int r, c; - char tempbuf[500]; int *compute_features; int dim; DCELL *mean = NULL, *sd = NULL; @@ -246,18 +243,15 @@ void generate_features(Features *features, Features *features_out) case GRASS_data: if ((mapset = (char *)G_find_raster( features_out->training.mapnames[i][j], "")) == NULL) { - sprintf(tempbuf, - "generate_features-> Can't find raster map <%s>", - features_out->training.mapnames[i][j]); - G_fatal_error(tempbuf); + G_fatal_error( + "generate_features-> Can't find raster map <%s>", + features_out->training.mapnames[i][j]); } if ((fp = Rast_open_old(features_out->training.mapnames[i][j], mapset)) < 0) { - sprintf(tempbuf, - "generate_features-> Can't open raster map <%s> " - "for reading", - features_out->training.mapnames[i][j]); - G_fatal_error(tempbuf); + G_fatal_error("generate_features-> Can't open raster map " + "<%s> for reading", + features_out->training.mapnames[i][j]); } Rast_get_cellhd(features_out->training.mapnames[i][j], mapset, @@ -266,8 +260,7 @@ void generate_features(Features *features, Features *features_out) if ((cellhd.rows != features_out->training.rows) || (cellhd.cols != features_out->training.cols)) { /* fprintf(stderr,"map number = %d\n",i); */ - sprintf(tempbuf, "generate_features-> Dimension Error"); - G_fatal_error(tempbuf); + G_fatal_error("generate_features-> Dimension Error"); } rowbuf = (DCELL *)G_calloc(dim, sizeof(DCELL)); tf = rowbuf; @@ -289,8 +282,7 @@ void generate_features(Features *features, Features *features_out) matrix[i] = features_out->training.data[i]; break; default: - sprintf(tempbuf, "generate_features-> Format not recognized"); - G_fatal_error(tempbuf); + G_fatal_error("generate_features-> Format not recognized"); break; } } diff --git a/src/imagery/i.pr/i.pr.features_extract/i.pr.features_extract.html b/src/imagery/i.pr/i.pr.features_extract/i.pr.features_extract.html new file mode 100644 index 0000000000..74268c04ab --- /dev/null +++ b/src/imagery/i.pr/i.pr.features_extract/i.pr.features_extract.html @@ -0,0 +1,7 @@ +

DESCRIPTION

+ +Module for feature extraction. + +

AUTHORS

+ +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.features_extract/i.pr.features_extract.md b/src/imagery/i.pr/i.pr.features_extract/i.pr.features_extract.md new file mode 100644 index 0000000000..a06840a4ca --- /dev/null +++ b/src/imagery/i.pr/i.pr.features_extract/i.pr.features_extract.md @@ -0,0 +1,7 @@ +## DESCRIPTION + +Module for feature extraction. + +## AUTHORS + +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.features_extract/main.c b/src/imagery/i.pr/i.pr.features_extract/main.c index 0842afd259..23cc8f2212 100644 --- a/src/imagery/i.pr/i.pr.features_extract/main.c +++ b/src/imagery/i.pr/i.pr.features_extract/main.c @@ -26,7 +26,7 @@ #define MAXLIMITS 20 -int read_selection(); +int read_selection(char *, int **); int main(int argc, char **argv) { @@ -68,14 +68,14 @@ int main(int argc, char **argv) opt1->type = TYPE_STRING; opt1->required = YES; opt1->description = - "Input file containing the features (output of i.pr_features)."; + "Input file containing the features (output of i.pr.features)."; opt2 = G_define_option(); opt2->key = "selected"; opt2->type = TYPE_STRING; opt2->required = YES; opt2->description = "File containing the results of the features selection " - "procedure\n\t\t(output of i.pr_features_selection)."; + "procedure\n\t\t(output of i.pr.features_selection)."; opt3 = G_define_option(); opt3->key = "nvar"; @@ -156,13 +156,11 @@ int main(int argc, char **argv) int read_selection(char *file, int **selection) { FILE *fp; - char tmpbuf[500]; char *line = NULL; int index = 0; if ((fp = fopen(file, "r")) == NULL) { - sprintf(tmpbuf, "Error opening file %s for reading", file); - G_fatal_error(tmpbuf); + G_fatal_error("Error opening file %s for reading", file); } *selection = (int *)G_calloc(1, sizeof(int)); diff --git a/src/imagery/i.pr/i.pr.features_selection/i.pr.features_selection.html b/src/imagery/i.pr/i.pr.features_selection/i.pr.features_selection.html new file mode 100644 index 0000000000..5f5c3efe82 --- /dev/null +++ b/src/imagery/i.pr/i.pr.features_selection/i.pr.features_selection.html @@ -0,0 +1,7 @@ +

DESCRIPTION

+ +Module for feature selection. + +

AUTHORS

+ +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.features_selection/i.pr.features_selection.md b/src/imagery/i.pr/i.pr.features_selection/i.pr.features_selection.md new file mode 100644 index 0000000000..6351ca3c9e --- /dev/null +++ b/src/imagery/i.pr/i.pr.features_selection/i.pr.features_selection.md @@ -0,0 +1,7 @@ +## DESCRIPTION + +Module for feature selection. + +## AUTHORS + +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.features_selection/main.c b/src/imagery/i.pr/i.pr.features_selection/main.c index 9eb3ab62a9..2088b8f17e 100644 --- a/src/imagery/i.pr/i.pr.features_selection/main.c +++ b/src/imagery/i.pr/i.pr.features_selection/main.c @@ -119,7 +119,7 @@ int main(int argc, char **argv) "are using gaussian kernel)."; opt8 = G_define_option(); - opt8->key = "svm_C"; + opt8->key = "svm_c"; opt8->type = TYPE_DOUBLE; opt8->required = NO; opt8->description = "For svm: optimization parameter (Required parameter)."; @@ -211,19 +211,16 @@ int main(int argc, char **argv) svm_kernel = SVM_KERNEL_GAUSSIAN; } else { - sprintf(tmpbuf, "kernel type not implemended!\n"); - G_fatal_error(tmpbuf); + G_fatal_error("kernel type not implemended!\n"); } if (svm_kernel == SVM_KERNEL_GAUSSIAN) { if (!opt7->answer) { - sprintf(tmpbuf, "Please set kernel parameter\n"); - G_fatal_error(tmpbuf); + G_fatal_error("Please set kernel parameter\n"); } else { sscanf(opt7->answer, "%lf", &svm_kp); if (svm_kp <= 0) { - sprintf(tmpbuf, "kernel parameter must be > 0\n"); - G_fatal_error(tmpbuf); + G_fatal_error("kernel parameter must be > 0\n"); } } } @@ -231,30 +228,25 @@ int main(int argc, char **argv) svm_kp = 0.0; if (!opt8->answer) { - sprintf(tmpbuf, "Please set optimization parameter\n"); - G_fatal_error(tmpbuf); + G_fatal_error("Please set optimization parameter\n"); } else { sscanf(opt8->answer, "%lf", &svm_C); if (svm_C <= 0) { - sprintf(tmpbuf, "optimization parameter must be > 0\n"); - G_fatal_error(tmpbuf); + G_fatal_error("optimization parameter must be > 0\n"); } } sscanf(opt9->answer, "%lf", &svm_tol); if (svm_tol <= 0) { - sprintf(tmpbuf, "tol must be > 0\n"); - G_fatal_error(tmpbuf); + G_fatal_error("tol must be > 0\n"); } sscanf(opt10->answer, "%lf", &svm_eps); if (svm_eps <= 0) { - sprintf(tmpbuf, "eps must be > 0\n"); - G_fatal_error(tmpbuf); + G_fatal_error("eps must be > 0\n"); } sscanf(opt12->answer, "%d", &svm_maxloops); if (svm_maxloops <= 0) { - sprintf(tmpbuf, "maximum number of loops must be > 0\n"); - G_fatal_error(tmpbuf); + G_fatal_error("maximum number of loops must be > 0\n"); } sscanf(opt22->answer, "%d", &svm_verbose); /* read features selection parameters (PLease check consistence!!!!) */ @@ -269,22 +261,18 @@ int main(int argc, char **argv) else if (strcmp(fs_type_string, "sqrt_rfe") == 0) fs_type = FS_SQRT_RFE; else { - sprintf(tmpbuf, "features selection method not recognized!\n"); - G_fatal_error(tmpbuf); + G_fatal_error("features selection method not recognized!\n"); } if (fs_type == FS_E_RFE) { if (!opt24->answer) { - sprintf(tmpbuf, - "You selected e_rfe: please set fs_rfe parameter!\n"); - G_fatal_error(tmpbuf); + G_fatal_error("You selected e_rfe: please set fs_rfe parameter!\n"); } else sscanf(opt24->answer, "%d", &fs_rfe); if (fs_rfe <= 1) { - sprintf(tmpbuf, "fs_rfe must be > 1\n"); - G_fatal_error(tmpbuf); + G_fatal_error("fs_rfe must be > 1\n"); } } @@ -344,8 +332,7 @@ int main(int argc, char **argv) } } if (features.nclasses != 2) { - sprintf(tmpbuf, "svm works only with 2 class problems\n"); - G_fatal_error(tmpbuf); + G_fatal_error("svm works only with 2 class problems\n"); } /*set svm parameters */ diff --git a/src/imagery/i.pr/i.pr.html b/src/imagery/i.pr/i.pr.html new file mode 100644 index 0000000000..35dd0fce88 --- /dev/null +++ b/src/imagery/i.pr/i.pr.html @@ -0,0 +1,42 @@ +

DESCRIPTION

+ +Pattern Recognition environment for image processing. Includes kNN, Decision +Tree and SVM classification techniques. Also includes cross-validation and +bagging methods for model validation. + +The i.pr toolset consists of currently 12 modules: + +
+
i.pr.blob
+
Module to search for blobs.
+
i.pr.classify
+
Module to classify raster map based on model defined in + i.pr.* modules.
+
i.pr.features
+
Module to process training data for feature extration.
+
i.pr.features_additional
+
Module to add new features to existing feature in i.pr.* + modules.
+
i.pr.features_extract
+
Module for feature extraction.
+
i.pr.features_selection
+
Module for feature selection.
+
i.pr.model
+
Module to generate model from features file.
+
i.pr.sites_aggregate
+
Module to aggregate sites.
+
i.pr.statistics
+
Module to calculate feature statistics.
+
i.pr.subsets
+
Module to create features file for experiment using a features file and + applying cross-validation or bootstrap resampling.
+
i.pr.training
+
Module to generate the training samples for use in i.pr.* + modules.
+
i.pr.uxb
+
Module for detection of unexploded bombs.
+
+ +

AUTHORS

+ +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.md b/src/imagery/i.pr/i.pr.md new file mode 100644 index 0000000000..c481d94cae --- /dev/null +++ b/src/imagery/i.pr/i.pr.md @@ -0,0 +1,37 @@ +## DESCRIPTION + +Pattern Recognition environment for image processing. Includes kNN, Decision +Tree and SVM classification techniques. Also includes cross-validation and +bagging methods for model validation. + +The *i.pr* toolset consists of currently 12 modules: + +- [i.pr.blob](i.pr.blob.md) + Module to search for blobs. +- [i.pr.classify](i.pr.classify.md) + Module to classify raster map based on model defined in *i.pr.\** modules. +- [i.pr.features](i.pr.features.md) + Module to process training data for feature extration. +- [i.pr.features_additional](i.pr.features_additional.md) + Module to add new features to existing feature in *i.pr.\** modules. +- [i.pr.features_extract](i.pr.features_extract.md) + Module for feature extraction. +- [i.pr.features_selection](i.pr.features_selection.md) + Module for feature selection. +- [i.pr.model](i.pr.model.md) + Module to generate model from features file. +- [i.pr.sites_aggregate](i.pr.sites_aggregate.md) + Module to aggregate sites. +- [i.pr.statistics](i.pr.statistics.md) + Module to calculate feature statistics. +- [i.pr.subsets](i.pr.subsets.md) + Module to create features file for experiment using a features file and + applying cross-validation or bootstrap resampling. +- [i.pr.training](i.pr.training.md) + Module to generate the training samples for use in *i.pr.\** modules. +- [i.pr.uxb](i.pr.uxb.md) + Module for detection of unexploded bombs. + +## AUTHORS + +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.model/i.pr.model.html b/src/imagery/i.pr/i.pr.model/i.pr.model.html new file mode 100644 index 0000000000..0296ee5ef2 --- /dev/null +++ b/src/imagery/i.pr/i.pr.model/i.pr.model.html @@ -0,0 +1,71 @@ +

DESCRIPTION

+ +

Create a classification model from a feature file. The type of model created +is chosen by setting one of the flags g (gaussian mixture), +n (nearest neighbor), t (classification trees), and s (support +vector machines). There are also general parameters such as the features +file (features), the name of the file produced containing the +model (model), the name of an additional features file +on which to calculate prediction values ​​during the training phase +(validation), the name of an additional features file on which +to calculate prediction values ​​in addition to the training set (test), +and the number of principal components to use in the model (npc) if +these are present in the features.

+ +

Then there are specific model parameters. None for the Gaussian mixture. +The number of neighbors per nearest neighbor (nn_k), although this +parameter is only used for model evaluation since the model itself is +the data itself. For classification trees, you can decide whether to +create single-node trees (stamps) or not (tree_stamps), +or decide how much data at least one node must contain to be split +(tree_minsize parameter). Furthermore, the tree costs parameter +allows you to unbalance the classes (rpart style).

+ +

For support vector machines, the user must set the kernel type +(svm_kernel, which can assume the values ​​linear, +gaussian and 2pbk), the kernel size if it is gaussian +(svm_kp), the regularization parameter (svm_c), the convergence +parameters svm_eps, tolerance (svm_tol) and svm_maxloops. +It is suggested not to modify the first two while the maximum number of +optimization loops can be modified (always with care). For support vector +machines, it is possible to calculate an estimate of the leave-one-out +model error using the parameter svm_l1o. The output of the procedure +is a file containing the selected model. The standard output will +describe the performance of the model on the training set and optionally +on a test set. For support vector machines, an optional cross-validation +estimate is also available.

+ +

For classification trees and support vector machines, model combinations +(bagging and boosting). The number of models is chosen by the user +(bagging and boosting parameters respectively). A cost-sensitive version +is also available for boosting, with the cost boosting parameter. If +boosting is used, it is possible to obtain the dynamics of the boosted +weights using the weights boosting parameter. For tree boosting, it is +also possible to develop (this is experimental) a soft version of the +model with the soft margin boosting parameter.

+ +

A cost-sensitive version for the single support vector machine can be +obtained using the svm cost parameter. It is also possible to use a +regularized version of the AdaBoost algorithm by specifying the number of +intervals (reg) into which to divide the misclassification ratio +(hence the number of training sets generated). In this case, the +validation set is not available. Alternatively, it is possible to +manually choose the misclassification ratio value above which samples +are eliminated from the training set (misclass ratio parameter). For +some models, only binary classifications are implemented according to +the following list:

+ +
+
gaussian mixture:
multiclass
+
nearest neighbor:
multiclass
+
classification trees:
multiclass
+
support vector machines:
binary
+
bagging classification trees:
multiclass
+
boosting classification trees:
binary
+
bagging support vector machines:
binary
+
boosting support vector machines:
binary
+
+ +

AUTHORS

+ +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.model/i.pr.model.md b/src/imagery/i.pr/i.pr.model/i.pr.model.md new file mode 100644 index 0000000000..1c76df51c2 --- /dev/null +++ b/src/imagery/i.pr/i.pr.model/i.pr.model.md @@ -0,0 +1,69 @@ +## DESCRIPTION + +Create a classification model from a feature file. The type of model created +is chosen by setting one of the flags **g** (gaussian mixture), +**n** (nearest neighbor), **t** (classification trees), and **s** (support +vector machines). There are also general parameters such as the features +file (**features**), the name of the file produced containing the +model (**model**), the name of an additional features file +on which to calculate prediction values ​​during the training phase +(**validation**), the name of an additional features file on which +to calculate prediction values ​​in addition to the training set (**test**), +and the number of principal components to use in the model (**npc**) if +these are present in the features. + +Then there are specific model parameters. None for the Gaussian mixture. +The number of neighbors per nearest neighbor (**nn\_k**), although this +parameter is only used for model evaluation since the model itself is +the data itself. For classification trees, you can decide whether to +create single-node trees (stamps) or not (**tree\_stamps**), +or decide how much data at least one node must contain to be split +(**tree\_minsize** parameter). Furthermore, the tree costs parameter +allows you to unbalance the classes (rpart style). + +For support vector machines, the user must set the kernel type +(**svm\_kernel**, which can assume the values ​​*linear*, *gaussian* +and *2pbk*), the kernel size if it is gaussian (**svm\_kp**), the +regularization parameter (**svm\_c**), the convergence parameters +**svm\_eps**, tolerance (**svm\_tol**) and **svm\_maxloops**. +It is suggested not to modify the first two while the maximum number of +optimization loops can be modified (always with care). For support vector +machines, it is possible to calculate an estimate of the leave-one-out +model error using the parameter **svm\_l1o**. The output of the procedure +is a file containing the selected model. The standard output will +describe the performance of the model on the training set and optionally +on a test set. For support vector machines, an optional cross-validation +estimate is also available. + +For classification trees and support vector machines, model combinations +(bagging and boosting). The number of models is chosen by the user +(bagging and boosting parameters respectively). A cost-sensitive version +is also available for boosting, with the cost boosting parameter. If +boosting is used, it is possible to obtain the dynamics of the boosted +weights using the weights boosting parameter. For tree boosting, it is +also possible to develop (this is experimental) a soft version of the +model with the soft margin boosting parameter. + +A cost-sensitive version for the single support vector machine can be +obtained using the svm cost parameter. It is also possible to use a +regularized version of the AdaBoost algorithm by specifying the number of +intervals (**reg**) into which to divide the misclassification ratio +(hence the number of training sets generated). In this case, the +validation set is not available. Alternatively, it is possible to +manually choose the misclassification ratio value above which samples +are eliminated from the training set (misclass ratio parameter). For +some models, only binary classifications are implemented according to +the following list: + +- gaussian mixture: multiclass +- nearest neighbor: multiclass +- classification trees: multiclass +- support vector machines: binary +- bagging classification trees: multiclass +- boosting classification trees: binary +- bagging support vector machines: binary +- boosting support vector machines: binary + +## AUTHORS + +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.model/main.c b/src/imagery/i.pr/i.pr.model/main.c index fc39a296d3..864b6e3803 100644 --- a/src/imagery/i.pr/i.pr.model/main.c +++ b/src/imagery/i.pr/i.pr.model/main.c @@ -70,7 +70,6 @@ int main(int argc, char **argv) BTree btree; BSupportVectorMachine bsvm; - char tmpbuf[500]; int tree_stamps, tree_minsize; char svm_kernel_type[100]; double svm_kp, svm_C, svm_tol, svm_eps; @@ -115,7 +114,7 @@ int main(int argc, char **argv) opt1->type = TYPE_STRING; opt1->required = YES; opt1->description = - "Input file containing the features (output of i.pr_features)."; + "Input file containing the features (output of i.pr.features)."; opt2 = G_define_option(); opt2->key = "model"; @@ -241,8 +240,8 @@ int main(int argc, char **argv) opt21->type = TYPE_INTEGER; opt21->required = NO; opt21->description = "For boosting: if soft_margin_boosting = 1, sof " - "margin of Ababoost\n\t\t\t will bee used. " - "Implemented only with trees. (Sperimental!!!!!!!!!!)"; + "margin of Ababoost\n\t\t\t will be used. " + "Implemented only with trees. (Experimental!!!!!!!!)"; opt21->answer = "0"; opt21->options = "0,1"; @@ -288,7 +287,7 @@ int main(int argc, char **argv) "are using gaussian kernel)."; opt8 = G_define_option(); - opt8->key = "svm_C"; + opt8->key = "svm_c"; opt8->type = TYPE_DOUBLE; opt8->required = NO; opt8->description = "For svm: optimization parameter (Required parameter)."; @@ -310,7 +309,7 @@ int main(int argc, char **argv) opt9->key = "svm_tol"; opt9->type = TYPE_DOUBLE; opt9->required = NO; - opt9->description = "For svm: tollerance parameter."; + opt9->description = "For svm: tolerance parameter."; opt9->answer = "0.001"; opt10 = G_define_option(); @@ -382,25 +381,21 @@ int main(int argc, char **argv) if (flag_n->answer) { sscanf(opt17->answer, "%d", &(nn.k)); if (nn.k <= 0) { - sprintf(tmpbuf, "number of neighbor must be > 0\n"); - G_fatal_error(tmpbuf); + G_fatal_error("number of neighbor must be > 0\n"); } if (nn.k % 2 == 0) { - sprintf(tmpbuf, "number of neighbor must be odd\n"); - G_fatal_error(tmpbuf); + G_fatal_error("number of neighbor must be odd\n"); } } if (flag_t->answer) { sscanf(opt4->answer, "%d", &tree_stamps); if ((tree_stamps != 0) && (tree_stamps != 1)) { - sprintf(tmpbuf, "stamps must be 0 or 1\n"); - G_fatal_error(tmpbuf); + G_fatal_error("stamps must be 0 or 1\n"); } sscanf(opt5->answer, "%d", &tree_minsize); if (tree_minsize < 0) { - sprintf(tmpbuf, "minsize must be >= 0\n"); - G_fatal_error(tmpbuf); + G_fatal_error("minsize must be >= 0\n"); } } @@ -418,19 +413,16 @@ int main(int argc, char **argv) svm_kernel = SVM_KERNEL_DIRECT; } else { - sprintf(tmpbuf, "kernel type not implemended!\n"); - G_fatal_error(tmpbuf); + G_fatal_error("kernel type not implemended!\n"); } if (svm_kernel == SVM_KERNEL_GAUSSIAN) { if (!opt7->answer) { - sprintf(tmpbuf, "Please set kernel parameter\n"); - G_fatal_error(tmpbuf); + G_fatal_error("Please set kernel parameter\n"); } else { sscanf(opt7->answer, "%lf", &svm_kp); if (svm_kp <= 0) { - sprintf(tmpbuf, "kernel parameter must be > 0\n"); - G_fatal_error(tmpbuf); + G_fatal_error("kernel parameter must be > 0\n"); } } } @@ -438,30 +430,25 @@ int main(int argc, char **argv) svm_kp = 0.0; if (!opt8->answer) { - sprintf(tmpbuf, "Please set optimization parameter\n"); - G_fatal_error(tmpbuf); + G_fatal_error("Please set optimization parameter\n"); } else { sscanf(opt8->answer, "%lf", &svm_C); if (svm_C <= 0) { - sprintf(tmpbuf, "optimization parameter must be > 0\n"); - G_fatal_error(tmpbuf); + G_fatal_error("optimization parameter must be > 0\n"); } } sscanf(opt9->answer, "%lf", &svm_tol); if (svm_tol <= 0) { - sprintf(tmpbuf, "tol must be > 0\n"); - G_fatal_error(tmpbuf); + G_fatal_error("tol must be > 0\n"); } sscanf(opt10->answer, "%lf", &svm_eps); if (svm_eps <= 0) { - sprintf(tmpbuf, "eps must be > 0\n"); - G_fatal_error(tmpbuf); + G_fatal_error("eps must be > 0\n"); } sscanf(opt12->answer, "%d", &svm_maxloops); if (svm_maxloops <= 0) { - sprintf(tmpbuf, "maximum number of loops must be > 0\n"); - G_fatal_error(tmpbuf); + G_fatal_error("maximum number of loops must be > 0\n"); } sscanf(opt11->answer, "%d", &svm_l1o); sscanf(opt22->answer, "%d", &svm_verbose); @@ -475,13 +462,11 @@ int main(int argc, char **argv) sscanf(opt28->answer, "%lf", &misclass_ratio); if ((misclass_ratio < 0) || (misclass_ratio > 1)) { - sprintf(tmpbuf, "misclassification ratio must be > 0 and < 1\n"); - G_fatal_error(tmpbuf); + G_fatal_error("misclassification ratio must be > 0 and < 1\n"); } if ((misclass_ratio < 1) && (reg > 0)) { - sprintf(tmpbuf, "Please select only one between shaving the training " - "set and regularized AdaBoost\n"); - G_fatal_error(tmpbuf); + G_fatal_error("Please select only one between shaving the training set " + "and regularized AdaBoost\n"); } if (bagging < 0) { bagging = 0; @@ -496,32 +481,26 @@ int main(int argc, char **argv) } if ((bagging > 0) && (boosting > 0)) { - sprintf(tmpbuf, - "Please select only one between bagging and boosting\n"); - G_fatal_error(tmpbuf); + G_fatal_error("Please select only one between bagging and boosting\n"); } if (boosting > 0) { sscanf(opt15->answer, "%lf", &w); if (w < 0.0 || w > 2.0) { - sprintf(tmpbuf, "boosting cost in [0,2]\n"); - G_fatal_error(tmpbuf); + G_fatal_error("boosting cost in [0,2]\n"); } sscanf(opt19->answer, "%d", &weights_boosting); if ((weights_boosting != 0) && (weights_boosting != 1)) { - sprintf(tmpbuf, "weights_boosting must be 0 or 1\n"); - G_fatal_error(tmpbuf); + G_fatal_error("weights_boosting must be 0 or 1\n"); } sscanf(opt21->answer, "%d", &soft_margin_boosting); if ((soft_margin_boosting != 0) && (soft_margin_boosting != 1)) { - sprintf(tmpbuf, "soft_margin_boosting must be 0 or 1\n"); - G_fatal_error(tmpbuf); + G_fatal_error("soft_margin_boosting must be 0 or 1\n"); } if (opt24->answer) { sscanf(opt24->answer, "%d", ¶llel_boosting); if ((parallel_boosting <= boosting) && (parallel_boosting > 0)) { - sprintf(tmpbuf, "parallel_boosting must be > boosting\n"); - G_fatal_error(tmpbuf); + G_fatal_error("parallel_boosting must be > boosting\n"); } } } @@ -698,8 +677,7 @@ int main(int argc, char **argv) /*svm */ if (features.nclasses != 2) { - sprintf(tmpbuf, "svm works only with 2 class problems\n"); - G_fatal_error(tmpbuf); + G_fatal_error("svm works only with 2 class problems\n"); } /*svm costs */ @@ -746,16 +724,12 @@ int main(int argc, char **argv) /*bagging models */ if (bagging > 0) { if (flag_n->answer) { - sprintf( - tmpbuf, + G_fatal_error( "Sorry, bagging of nearest neighbor not yet implemented\n\n"); - G_fatal_error(tmpbuf); } if (flag_g->answer) { - sprintf( - tmpbuf, + G_fatal_error( "Sorry, bagging of gaussian mixture not yet implemented\n\n"); - G_fatal_error(tmpbuf); } if (flag_t->answer) { /*trees */ @@ -785,8 +759,7 @@ int main(int argc, char **argv) if (flag_s->answer) { /*svm */ if (features.nclasses != 2) { - sprintf(tmpbuf, "svm works only with 2 class problems\n"); - G_fatal_error(tmpbuf); + G_fatal_error("svm works only with 2 class problems\n"); } svm_W = (double *)G_calloc(features.nexamples, sizeof(double)); @@ -822,21 +795,16 @@ int main(int argc, char **argv) /*boosting models */ if (boosting > 0) { if (flag_n->answer) { - sprintf( - tmpbuf, + G_fatal_error( "Sorry, boosting of nearest neighbor not yet implemented\n\n"); - G_fatal_error(tmpbuf); } if (flag_g->answer) { - sprintf( - tmpbuf, + G_fatal_error( "Sorry, boosting of gaussian mixture not yet implemented\n\n"); - G_fatal_error(tmpbuf); } if (features.nclasses != 2) { - sprintf(tmpbuf, "boosting works only with 2 class problems\n"); - G_fatal_error(tmpbuf); + G_fatal_error("boosting works only with 2 class problems\n"); } if (flag_t->answer) { /*trees */ @@ -1068,7 +1036,6 @@ int main(int argc, char **argv) } } - sprintf(tmpbuf, "please select a model\n"); - G_warning(tmpbuf); + G_warning("please select a model\n"); return 0; } diff --git a/src/imagery/i.pr/i.pr.sites_aggregate/Makefile b/src/imagery/i.pr/i.pr.sites_aggregate/Makefile index 70d1708f69..f5f2ba1a55 100644 --- a/src/imagery/i.pr/i.pr.sites_aggregate/Makefile +++ b/src/imagery/i.pr/i.pr.sites_aggregate/Makefile @@ -1,7 +1,7 @@ MODULE_TOPDIR = ../../.. PRINCLUDE = ../include/ -EXTRA_CFLAGS = $(VECT_CFLAGS) -I$(PRINCLUDE) +EXTRA_CFLAGS = $(VECT_CFLAGS) -I$(PRINCLUDE) $(PQINCPATH) PRLIB = -lgrass_pr.$(GRASS_LIB_VERSION_NUMBER) PGM = i.pr.sites_aggregate diff --git a/src/imagery/i.pr/i.pr.sites_aggregate/i.pr.sites_aggregate.html b/src/imagery/i.pr/i.pr.sites_aggregate/i.pr.sites_aggregate.html new file mode 100644 index 0000000000..2a5c502e04 --- /dev/null +++ b/src/imagery/i.pr/i.pr.sites_aggregate/i.pr.sites_aggregate.html @@ -0,0 +1,7 @@ +

DESCRIPTION

+ +Module to aggregate sites. + +

AUTHORS

+ +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.sites_aggregate/i.pr.sites_aggregate.md b/src/imagery/i.pr/i.pr.sites_aggregate/i.pr.sites_aggregate.md new file mode 100644 index 0000000000..8551ff25f5 --- /dev/null +++ b/src/imagery/i.pr/i.pr.sites_aggregate/i.pr.sites_aggregate.md @@ -0,0 +1,7 @@ +## DESCRIPTION + +Module to aggregate sites. + +## AUTHORS + +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.sites_aggregate/main.c b/src/imagery/i.pr/i.pr.sites_aggregate/main.c index ae0377909a..0159f7e04d 100644 --- a/src/imagery/i.pr/i.pr.sites_aggregate/main.c +++ b/src/imagery/i.pr/i.pr.sites_aggregate/main.c @@ -115,10 +115,8 @@ int main(int argc, char *argv[]) while ((line = GetLine(fp)) != NULL) { sscanf(line, "%lf", &(data[npoints][0])); line = (char *)strchr(line, '|'); - *line++; sscanf(line, "%lf", &(data[npoints][1])); line = (char *)strchr(line, '|'); - *line++; sscanf(line, "%lf", &(data[npoints][2])); npoints++; data = (double **)G_realloc(data, (npoints + 1) * sizeof(double *)); diff --git a/src/imagery/i.pr/i.pr.statistics/cell.c b/src/imagery/i.pr/i.pr.statistics/cell.c index bb23d234af..4ba340507e 100644 --- a/src/imagery/i.pr/i.pr.statistics/cell.c +++ b/src/imagery/i.pr/i.pr.statistics/cell.c @@ -6,7 +6,9 @@ /*#include "edit.h" */ #include "localproto.h" -static int cell_draw(char *, char *, struct Colors *, int); +#include "global.h" + +static int cell_draw(char *, const char *, struct Colors *, int); /*! * \brief @@ -22,7 +24,7 @@ static int cell_draw(char *, char *, struct Colors *, int); * \return int */ -int Dcell(char *name, char *mapset, int overlay) +int Dcell(char *name, const char *mapset, int overlay) { struct Cell_head wind; struct Colors colors; @@ -33,8 +35,7 @@ int Dcell(char *name, char *mapset, int overlay) if (D_check_map_window(&wind)) G_fatal_error(_("Setting map window")); - if (G_set_window(&wind) == -1) - G_fatal_error(_("Current window not settable")); + G_set_window(&wind); /* Get existing map window for this graphics window, or save window */ /* cell maps wipe out a picture, so we clear info on the window too */ @@ -70,7 +71,7 @@ int Dcell(char *name, char *mapset, int overlay) } /* I modified this function to read and draw raster cell as doubles */ -static int cell_draw(char *name, char *mapset, struct Colors *colors, +static int cell_draw(char *name, const char *mapset, struct Colors *colors, int overlay) { int cellfile; diff --git a/src/imagery/i.pr/i.pr.statistics/i.pr.statistics.html b/src/imagery/i.pr/i.pr.statistics/i.pr.statistics.html new file mode 100644 index 0000000000..d063a4e34d --- /dev/null +++ b/src/imagery/i.pr/i.pr.statistics/i.pr.statistics.html @@ -0,0 +1,13 @@ +

DESCRIPTION

+ +Calculate feature statistics. Given an input file of features +(features), calculate the Kolgomorov-Smirnov test and t-test for +each class of each feature. If the features contain principal components, +calculate the variance explained by them. If there are multiple principal +component models (for multiple layers), the analysis is performed on +only one layer (layer). The **npc** parameter is used to limit +the analysis to the first npc principal components. + +

AUTHORS

+ +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.statistics/i.pr.statistics.md b/src/imagery/i.pr/i.pr.statistics/i.pr.statistics.md new file mode 100644 index 0000000000..f4f845fcd3 --- /dev/null +++ b/src/imagery/i.pr/i.pr.statistics/i.pr.statistics.md @@ -0,0 +1,13 @@ +## DESCRIPTION + +Calculate feature statistics. Given an input file of features +(**features**), calculate the Kolgomorov-Smirnov test and t-test for +each class of each feature. If the features contain principal components, +calculate the variance explained by them. If there are multiple principal +component models (for multiple layers), the analysis is performed on +only one layer (**layer**). The **npc** parameter is used to limit +the analysis to the first npc principal components. + +## AUTHORS + +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.statistics/localproto.h b/src/imagery/i.pr/i.pr.statistics/localproto.h index 99251bab43..cf80a4c7a7 100644 --- a/src/imagery/i.pr/i.pr.statistics/localproto.h +++ b/src/imagery/i.pr/i.pr.statistics/localproto.h @@ -1,2 +1,2 @@ /* cell.c */ -int Dcell(char *, char *, int); +int Dcell(char *, const char *, int); diff --git a/src/imagery/i.pr/i.pr.statistics/main.c b/src/imagery/i.pr/i.pr.statistics/main.c index bf66791186..0ed75ee9ac 100644 --- a/src/imagery/i.pr/i.pr.statistics/main.c +++ b/src/imagery/i.pr/i.pr.statistics/main.c @@ -30,8 +30,8 @@ #define TINY 1.0e-20 #define MAXLIMITS 10000 -void pearsn(); -double erfcc(); +void pearsn(double[], double[], int, double *, double *, double *); +double erfcc(double); int main(int argc, char *argv[]) { @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) opt1->type = TYPE_STRING; opt1->required = YES; opt1->description = - "Input file containing the features (output of i.pr_features)."; + "Input file containing the features (output of i.pr.features)."; opt3 = G_define_option(); opt3->key = "layer"; @@ -125,8 +125,7 @@ int main(int argc, char *argv[]) read_features(opt1->answer, &features, -1); if ((layer <= 0) || (layer > features.training.nlayers)) { - sprintf(tempbuf, "Number of layers is %d\n", features.training.nlayers); - G_fatal_error(tempbuf); + G_fatal_error("Number of layers is %d\n", features.training.nlayers); } ncorr = 0; @@ -144,14 +143,12 @@ int main(int argc, char *argv[]) break; } if (corr[i] < 0 || corr[i] > features.examples_dim) { - sprintf(tempbuf, "Negative index of columns or wrong index\n"); - G_fatal_error(tempbuf); + G_fatal_error("Negative index of columns or wrong index\n"); } } if (ncorr == 1) { - sprintf(tempbuf, "Can't do correlation with 1 column!!\n"); - G_fatal_error(tempbuf); + G_fatal_error("Can't do correlation with 1 column!!\n"); } /* calcolo la correlazione tra le varie variabili */ @@ -276,8 +273,7 @@ int main(int argc, char *argv[]) else { sscanf(opt2->answer, "%d", &npca); if (npca <= 0) { - sprintf(tempbuf, "npca must be > 0"); - G_fatal_error(tempbuf); + G_fatal_error("npca must be > 0"); } } if (npca > maxeig) @@ -314,20 +310,16 @@ int main(int argc, char *argv[]) cellhd.south = .0; cellhd.east = (double)(cellhd.cols); cellhd.west = .0; - if (G_set_window(&cellhd) == -1) { - sprintf(tempbuf, "error setting working window"); - G_fatal_error(tempbuf); - } + G_set_window(&cellhd); /*open output raster map */ sprintf(outputmap_name, "%s_tmpimage", opt1->answer); - if (outputmap_name != NULL) + if (outputmap_name[0] != '\0') FD = open_new_CELL(outputmap_name); else { - sprintf(tempbuf, "error setting the output name"); - G_fatal_error(tempbuf); + G_fatal_error("error setting the output name"); } /* alloc memory */ @@ -372,11 +364,9 @@ int main(int argc, char *argv[]) if (max != min) a = (NEWmax - NEWmin) / (max - min); else { - sprintf(tempbuf, - "min of eigenvect %d = max of " - "eigenvect %d", - index, index); - G_fatal_error(tempbuf); + G_fatal_error("min of eigenvect %d = max " + "of eigenvect %d", + index, index); } for (i = 0; i < features.training.rows; i++) @@ -393,14 +383,10 @@ int main(int argc, char *argv[]) /*write output map */ for (i = 0; i < cellhd.rows; i++) if (G_put_map_row(FD, intmat[i]) == -1) { - sprintf(tempbuf, "error writing tmp raster map"); - G_fatal_error(tempbuf); + G_fatal_error("error writing tmp raster map"); } - if (Rast_close(FD) == -1) { - sprintf(tempbuf, "error closing tmp raster map"); - G_fatal_error(tempbuf); - } + Rast_close(FD); /*colors */ sprintf(tempbuf, "r.colors map=%s color=grey", @@ -409,8 +395,7 @@ int main(int argc, char *argv[]) /*graphics */ if (G_put_window(&cellhd) == -1) { - sprintf(tempbuf, "error writing working region"); - G_fatal_error(tempbuf); + G_fatal_error("error writing working region"); } sprintf(tempbuf, "d.frame -e"); system(tempbuf); @@ -419,9 +404,7 @@ int main(int argc, char *argv[]) Dcell(outputmap_name, G_mapset(), 0); R_close_driver(); if (G_put_window(&cellhd_orig) == -1) { - sprintf(tempbuf, - "error writing original working region"); - G_fatal_error(tempbuf); + G_fatal_error("error writing original working region"); } /*remove */ @@ -435,8 +418,7 @@ int main(int argc, char *argv[]) /*xgraph 1 */ outputxgraph_name = G_tempfile(); if ((FP = fopen(outputxgraph_name, "w")) == NULL) { - sprintf(tempbuf, "error opening tmp file for xgraph"); - G_fatal_error(tempbuf); + G_fatal_error("error opening tmp file for xgraph"); } fprintf(stdout, @@ -465,8 +447,7 @@ int main(int argc, char *argv[]) } } else { - sprintf(tempbuf, "divide by 0"); - G_fatal_error(tempbuf); + G_fatal_error("divide by 0"); } fclose(FP); @@ -487,7 +468,6 @@ void pearsn(double x[], double y[], int n, double *r, double *prob, double *z) int j; double yt, xt, t, df; double syy = 0.0, sxy = 0.0, sxx = 0.0, ay = 0.0, ax = 0.0; - double betai(), erfcc(); /*calcolo della media */ diff --git a/src/imagery/i.pr/i.pr.subsets/i.pr.subsets.html b/src/imagery/i.pr/i.pr.subsets/i.pr.subsets.html new file mode 100644 index 0000000000..752f671d93 --- /dev/null +++ b/src/imagery/i.pr/i.pr.subsets/i.pr.subsets.html @@ -0,0 +1,11 @@ +

DESCRIPTION

+ +Create feature files for experiments from a features file (features) +by implementing cross-validation (flag c) or bootstrap resampling +(flag b). The n_sets option sets the number of bootstrap +subsets or folders for cross-validation. The seed option allows you to +create different sets. + +

AUTHORS

+ +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.subsets/i.pr.subsets.md b/src/imagery/i.pr/i.pr.subsets/i.pr.subsets.md new file mode 100644 index 0000000000..14f88e5367 --- /dev/null +++ b/src/imagery/i.pr/i.pr.subsets/i.pr.subsets.md @@ -0,0 +1,11 @@ +## DESCRIPTION + +Create feature files for experiments from a features file (**features**) +by implementing cross-validation (flag **c**) or bootstrap resampling +(flag **b**). The **n\_sets** option sets the number of bootstrap subsets +or folders for cross-validation. The seed option allows you to create +different sets. + +## AUTHORS + +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.subsets/main.c b/src/imagery/i.pr/i.pr.subsets/main.c index 1f22496aee..9844a01af0 100644 --- a/src/imagery/i.pr/i.pr.subsets/main.c +++ b/src/imagery/i.pr/i.pr.subsets/main.c @@ -24,8 +24,6 @@ #include #include "global.h" -void write_matrix(); - int main(int argc, char **argv) { struct GModule *module; @@ -40,7 +38,6 @@ int main(int argc, char **argv) Features *tr_features; Features *ts_features; - char tmpbuf[500]; int n_sets; int i, j, k; char fileout[500], filelab[500]; @@ -115,19 +112,16 @@ int main(int argc, char **argv) /*read parameters */ sscanf(opt2->answer, "%d", &n_sets); if (n_sets <= 0) { - sprintf(tmpbuf, "n_sets must be >0"); - G_fatal_error(tmpbuf); + G_fatal_error("n_sets must be >0"); } sscanf(opt3->answer, "%d", &seed); if (seed < 0) { - sprintf(tmpbuf, "seed must be >=0"); - G_fatal_error(tmpbuf); + G_fatal_error("seed must be >=0"); } if (!flag_b->answer && !flag_c->answer) { - sprintf(tmpbuf, "Neither -b nor -c flag set!\n"); - G_fatal_error(tmpbuf); + G_fatal_error("Neither -b nor -c flag set!\n"); } /*read features */ @@ -482,22 +476,19 @@ int main(int argc, char **argv) ts_features = (Features *)G_calloc(n_sets, sizeof(Features)); if (n_sets > features.nexamples) { - sprintf(tmpbuf, - "n_sets must be <= %d (=number of training data) if " - "you want to use cross-validation", - features.nexamples); - G_fatal_error(tmpbuf); + G_fatal_error("n_sets must be <= %d (=number of training data) " + "if you want to use cross-validation", + features.nexamples); } probok = pow(1. - pow(1. - 1. / n_sets, (double)features.nexamples), (double)n_sets); if (probok < 0.95) { - sprintf(tmpbuf, - "the probability of extracting %d non empty test sets " - "is less than 0.95 (the probability is exactly %e). " - "Sorry but I don't like to take this risk.", - n_sets, probok); - G_fatal_error(tmpbuf); + G_fatal_error( + "the probability of extracting %d non empty test sets is " + "less than 0.95 (the probability is exactly %e). Sorry but " + "I don't like to take this risk.", + n_sets, probok); } random_labels = (int *)G_calloc(features.nexamples, sizeof(int)); diff --git a/src/imagery/i.pr/i.pr.subsets/old/main_orig.c b/src/imagery/i.pr/i.pr.subsets/old/main_orig.c index 41efcec947..e559b36ff8 100644 --- a/src/imagery/i.pr/i.pr.subsets/old/main_orig.c +++ b/src/imagery/i.pr/i.pr.subsets/old/main_orig.c @@ -84,14 +84,12 @@ int main(int argc, char **argv) /*read parameters */ sscanf(opt2->answer, "%d", &n_sets); if (n_sets <= 0) { - sprintf(tmpbuf, "n_sets must be >0"); - G_fatal_error(tmpbuf); + G_fatal_error("n_sets must be >0"); } sscanf(opt3->answer, "%d", &seed); if (seed < 0) { - sprintf(tmpbuf, "seed must be >=0"); - G_fatal_error(tmpbuf); + G_fatal_error("seed must be >=0"); } /*read features */ @@ -269,22 +267,19 @@ int main(int argc, char **argv) ts_features = (Features *)G_calloc(n_sets, sizeof(Features)); if (n_sets > features.nexamples) { - sprintf(tmpbuf, - "n_sets must be <= %d (=number of training data) if " - "you want to use cross-validation", - features.nexamples); - G_fatal_error(tmpbuf); + G_fatal_error("n_sets must be <= %d (=number of training data) " + "if you want to use cross-validation", + features.nexamples); } probok = pow(1. - pow(1. - 1. / n_sets, (double)features.nexamples), (double)n_sets); if (probok < 0.95) { - sprintf(tmpbuf, - "the probability of extracting %d non empty test sets " - "is less than 0.95 (the probability is exactly %e). " - "Sorry but I don't like to take this risk.", - n_sets, probok); - G_fatal_error(tmpbuf); + G_fatal_error( + "the probability of extracting %d non empty test sets is " + "less than 0.95 (the probability is exactly %e). Sorry but " + "I don't like to take this risk.", + n_sets, probok); } random_labels = (int *)G_calloc(features.nexamples, sizeof(int)); diff --git a/src/imagery/i.pr/i.pr.subsets/old/main_orig_2.c b/src/imagery/i.pr/i.pr.subsets/old/main_orig_2.c index fcb0d311cb..13f217b62d 100644 --- a/src/imagery/i.pr/i.pr.subsets/old/main_orig_2.c +++ b/src/imagery/i.pr/i.pr.subsets/old/main_orig_2.c @@ -85,14 +85,12 @@ int main(int argc, char **argv) /*read parameters */ sscanf(opt2->answer, "%d", &n_sets); if (n_sets <= 0) { - sprintf(tmpbuf, "n_sets must be >0"); - G_fatal_error(tmpbuf); + G_fatal_error("n_sets must be >0"); } sscanf(opt3->answer, "%d", &seed); if (seed < 0) { - sprintf(tmpbuf, "seed must be >=0"); - G_fatal_error(tmpbuf); + G_fatal_error("seed must be >=0"); } /*read features */ @@ -292,22 +290,19 @@ int main(int argc, char **argv) ts_features = (Features *)G_calloc(n_sets, sizeof(Features)); if (n_sets > features.nexamples) { - sprintf(tmpbuf, - "n_sets must be <= %d (=number of training data) if " - "you want to use cross-validation", - features.nexamples); - G_fatal_error(tmpbuf); + G_fatal_error("n_sets must be <= %d (=number of training data) " + "if you want to use cross-validation", + features.nexamples); } probok = pow(1. - pow(1. - 1. / n_sets, (double)features.nexamples), (double)n_sets); if (probok < 0.95) { - sprintf(tmpbuf, - "the probability of extracting %d non empty test sets " - "is less than 0.95 (the probability is exactly %e). " - "Sorry but I don't like to take this risk.", - n_sets, probok); - G_fatal_error(tmpbuf); + G_fatal_error( + "the probability of extracting %d non empty test sets is " + "less than 0.95 (the probability is exactly %e). Sorry but " + "I don't like to take this risk.", + n_sets, probok); } random_labels = (int *)G_calloc(features.nexamples, sizeof(int)); diff --git a/src/imagery/i.pr/i.pr.training/defs.h b/src/imagery/i.pr/i.pr.training/defs.h index 9c5315bd7e..206fc3134f 100644 --- a/src/imagery/i.pr/i.pr.training/defs.h +++ b/src/imagery/i.pr/i.pr.training/defs.h @@ -1,3 +1,5 @@ +#pragma once + #include /* this is a graphics structure */ diff --git a/src/imagery/i.pr/i.pr.training/globals.h b/src/imagery/i.pr/i.pr.training/globals.h index ffcb3d2a2e..7934ee19df 100644 --- a/src/imagery/i.pr/i.pr.training/globals.h +++ b/src/imagery/i.pr/i.pr.training/globals.h @@ -1,4 +1,7 @@ +#pragma once + #include "defs.h" +#include "global.h" #ifndef GLOBAL #define GLOBAL extern @@ -7,8 +10,6 @@ #define INIT(x) = x #endif -GLOBAL int G_get_color(); - GLOBAL int SCREEN_TOP; GLOBAL int SCREEN_BOTTOM; GLOBAL int SCREEN_LEFT; @@ -29,15 +30,15 @@ GLOBAL int dotsize INIT(4); GLOBAL int THE_COLORS[10]; -#define BLACK THE_COLORS[0] -#define BLUE THE_COLORS[1] -#define BROWN THE_COLORS[2] -#define GREEN THE_COLORS[3] -#define GREY THE_COLORS[4] -#define ORANGE THE_COLORS[5] -#define PURPLE THE_COLORS[6] -#define RED THE_COLORS[7] -#define WHITE THE_COLORS[8] -#define YELLOW THE_COLORS[9] +#define IPR_BLACK THE_COLORS[0] +#define IPR_BLUE THE_COLORS[1] +#define IPR_BROWN THE_COLORS[2] +#define IPR_GREEN THE_COLORS[3] +#define IPR_GREY THE_COLORS[4] +#define IPR_ORANGE THE_COLORS[5] +#define IPR_PURPLE THE_COLORS[6] +#define IPR_RED THE_COLORS[7] +#define IPR_WHITE THE_COLORS[8] +#define IPR_YELLOW THE_COLORS[9] #undef INIT diff --git a/src/imagery/i.pr/i.pr.training/graphics.c b/src/imagery/i.pr/i.pr.training/graphics.c index 3691968c22..bc911146a0 100644 --- a/src/imagery/i.pr/i.pr.training/graphics.c +++ b/src/imagery/i.pr/i.pr.training/graphics.c @@ -1,3 +1,4 @@ +#include #include "globals.h" #include #include @@ -40,7 +41,7 @@ static View *makeview(double bottom, double top, double left, double right) return view; } -void Init_graphics2() +void Init_graphics2(void) { /* R_color_table_fixed(); @@ -55,18 +56,18 @@ void Init_graphics2() SCREEN_LEFT = R_screen_left(); SCREEN_RIGHT = R_screen_rite(); - BLACK = D_translate_color("black"); - BLUE = D_translate_color("blue"); - BROWN = D_translate_color("brown"); - GREEN = D_translate_color("green"); - GREY = D_translate_color("grey"); - ORANGE = D_translate_color("orange"); - PURPLE = D_translate_color("purple"); - RED = D_translate_color("red"); - WHITE = D_translate_color("white"); - YELLOW = D_translate_color("yellow"); + IPR_BLACK = D_translate_color("black"); + IPR_BLUE = D_translate_color("blue"); + IPR_BROWN = D_translate_color("brown"); + IPR_GREEN = D_translate_color("green"); + IPR_GREY = D_translate_color("grey"); + IPR_ORANGE = D_translate_color("orange"); + IPR_PURPLE = D_translate_color("purple"); + IPR_RED = D_translate_color("red"); + IPR_WHITE = D_translate_color("white"); + IPR_YELLOW = D_translate_color("yellow"); - R_standard_color(WHITE); + R_standard_color(IPR_WHITE); VIEW_TITLE1 = makeview(97.5, 100.0, 0.0, 100.0); VIEW_TITLE_IMAGE = makeview(97.5, 100.0, 50.0, 100.0); @@ -83,7 +84,7 @@ void Init_graphics2() Rast_init_colors(&VIEW_IMAGE->cell.colors); } -void Init_graphics() +void Init_graphics(void) { /* R_color_table_fixed(); @@ -98,18 +99,18 @@ void Init_graphics() SCREEN_LEFT = R_screen_left(); SCREEN_RIGHT = R_screen_rite(); - BLACK = D_translate_color("black"); - BLUE = D_translate_color("blue"); - BROWN = D_translate_color("brown"); - GREEN = D_translate_color("green"); - GREY = D_translate_color("grey"); - ORANGE = D_translate_color("orange"); - PURPLE = D_translate_color("purple"); - RED = D_translate_color("red"); - WHITE = D_translate_color("white"); - YELLOW = D_translate_color("yellow"); + IPR_BLACK = D_translate_color("black"); + IPR_BLUE = D_translate_color("blue"); + IPR_BROWN = D_translate_color("brown"); + IPR_GREEN = D_translate_color("green"); + IPR_GREY = D_translate_color("grey"); + IPR_ORANGE = D_translate_color("orange"); + IPR_PURPLE = D_translate_color("purple"); + IPR_RED = D_translate_color("red"); + IPR_WHITE = D_translate_color("white"); + IPR_YELLOW = D_translate_color("yellow"); - R_standard_color(WHITE); + R_standard_color(IPR_WHITE); VIEW_TITLE1 = makeview(97.5, 100.0, 0.0, 50.0); VIEW_TITLE_IMAGE = makeview(97.5, 100.0, 50.0, 100.0); @@ -126,7 +127,7 @@ void Init_graphics() Rast_init_colors(&VIEW_IMAGE->cell.colors); } -void Outline_box(top, bottom, left, right) +void Outline_box(int top, int bottom, int left, int right) { R_move_abs(left, top); R_cont_abs(left, bottom); @@ -135,8 +136,7 @@ void Outline_box(top, bottom, left, right) R_cont_abs(left, top); } -int Text_width(text) -char *text; +int Text_width(char *text) { int top, bottom, left, right; @@ -148,7 +148,7 @@ char *text; return left - right + 1; } -void Text(text, top, bottom, left, right, edge) char *text; +void Text(char *text, int top, int bottom, int left, int right, int edge) { R_set_window(top, bottom, left, right); R_move_abs(left + edge, bottom - edge); @@ -156,7 +156,7 @@ void Text(text, top, bottom, left, right, edge) char *text; R_set_window(SCREEN_TOP, SCREEN_BOTTOM, SCREEN_LEFT, SCREEN_RIGHT); } -void Uparrow(top, bottom, left, right) +void Uparrow(int top, int bottom, int left, int right) { R_move_abs((left + right) / 2, bottom); R_cont_abs((left + right) / 2, top); @@ -165,7 +165,7 @@ void Uparrow(top, bottom, left, right) R_cont_rel((right - left) / 2, (bottom - top) / 2); } -void Downarrow(top, bottom, left, right) +void Downarrow(int top, int bottom, int left, int right) { R_move_abs((left + right) / 2, top); R_cont_abs((left + right) / 2, bottom); @@ -174,18 +174,14 @@ void Downarrow(top, bottom, left, right) R_cont_rel((right - left) / 2, (top - bottom) / 2); } -void display_map(cellhd, view, name, mapset) struct Cell_head *cellhd; -View *view; -char *name; -char *mapset; +void display_map(struct Cell_head *cellhd, View *view, char *name, char *mapset) { - G_adjust_window_to_box(cellhd, &view->cell.head, view->nrows, view->ncols); Configure_view(view, name, mapset, cellhd->ns_res, cellhd->ew_res); drawcell(view); } -void drawcell(view) View *view; +void drawcell(View *view) { int fd; int left, top; @@ -195,10 +191,9 @@ void drawcell(view) View *view; int repeat; struct Colors *colors; int read_colors; - char msg[100]; if (!view->cell.configured) - return 0; + return; if (view == VIEW_MAP1 || view == VIEW_MAP1_ZOOM) { colors = &VIEW_MAP1->cell.colors; read_colors = view == VIEW_MAP1; @@ -210,7 +205,7 @@ void drawcell(view) View *view; if (read_colors) { Rast_free_colors(colors); if (Rast_read_colors(view->cell.name, view->cell.mapset, colors) < 0) - return 0; + return; } display_title(view); @@ -227,15 +222,13 @@ void drawcell(view) View *view; Outline_box(top, top + nrows - 1, left, left + ncols - 1); { - char *getenv(); - if (getenv("NO_DRAW")) - return 1; + return; } fd = Rast_open_old(view->cell.name, view->cell.mapset); if (fd < 0) - return 0; + return; cell = G_allocate_cell_buf(); /* @@ -255,52 +248,52 @@ void drawcell(view) View *view; /* if(colors != &VIEW_MAP1->cell.colors) D_set_colors(&VIEW_MAP1->cell.colors); */ - return row == nrows; + return; // row == nrows; } -void exit_button() +void exit_button(void) { int size; Erase_view(VIEW_EXIT); - R_standard_color(RED); + R_standard_color(IPR_RED); size = VIEW_EXIT->nrows - 4; R_text_size(size, size); Text("exit", VIEW_EXIT->top, VIEW_EXIT->bottom, VIEW_EXIT->left, VIEW_EXIT->right, 2); - R_standard_color(WHITE); + R_standard_color(IPR_WHITE); } -void info_button() +void info_button(void) { int size; Erase_view(VIEW_INFO); - R_standard_color(GREEN); + R_standard_color(IPR_GREEN); size = VIEW_INFO->nrows / 13; R_text_size(size, size); Text("UPPER LEFT PANEL:", VIEW_INFO->top, VIEW_INFO->top + size, VIEW_INFO->left, VIEW_INFO->right, 1); - R_standard_color(YELLOW); + R_standard_color(IPR_YELLOW); Text("left: mark 1", VIEW_INFO->top + size, VIEW_INFO->top + 2 * size, VIEW_INFO->left, VIEW_INFO->right, 1); Text("left: mark 2", VIEW_INFO->top + 2 * size, VIEW_INFO->top + 3 * size, VIEW_INFO->left, VIEW_INFO->right, 1); Text("", VIEW_INFO->top + 4 * size, VIEW_INFO->top + 5 * size, VIEW_INFO->left, VIEW_INFO->right, 1); - R_standard_color(GREEN); + R_standard_color(IPR_GREEN); Text("LOWER LEFT PANEL:", VIEW_INFO->top + 5 * size, VIEW_INFO->top + 6 * size, VIEW_INFO->left, VIEW_INFO->right, 1); - R_standard_color(YELLOW); + R_standard_color(IPR_YELLOW); Text("left(double): select", VIEW_INFO->top + 6 * size, VIEW_INFO->top + 7 * size, VIEW_INFO->left, VIEW_INFO->right, 1); Text("", VIEW_INFO->top + 8 * size, VIEW_INFO->top + 9 * size, VIEW_INFO->left, VIEW_INFO->right, 1); - R_standard_color(GREEN); + R_standard_color(IPR_GREEN); Text("UPPER RIGHT PANEL:", VIEW_INFO->top + 9 * size, VIEW_INFO->top + 10 * size, VIEW_INFO->left, VIEW_INFO->right, 1); - R_standard_color(YELLOW); + R_standard_color(IPR_YELLOW); Text("right(double): save", VIEW_INFO->top + 10 * size, VIEW_INFO->top + 11 * size, VIEW_INFO->left, VIEW_INFO->right, 1); - R_standard_color(WHITE); + R_standard_color(IPR_WHITE); } diff --git a/src/imagery/i.pr/i.pr.training/description.html b/src/imagery/i.pr/i.pr.training/i.pr.training.html similarity index 100% rename from src/imagery/i.pr/i.pr.training/description.html rename to src/imagery/i.pr/i.pr.training/i.pr.training.html diff --git a/src/imagery/i.pr/i.pr.training/description.md b/src/imagery/i.pr/i.pr.training/i.pr.training.md similarity index 100% rename from src/imagery/i.pr/i.pr.training/description.md rename to src/imagery/i.pr/i.pr.training/i.pr.training.md diff --git a/src/imagery/i.pr/i.pr.training/loc_func.h b/src/imagery/i.pr/i.pr.training/loc_func.h index ac6aad0ad7..b178fdba5a 100644 --- a/src/imagery/i.pr/i.pr.training/loc_func.h +++ b/src/imagery/i.pr/i.pr.training/loc_func.h @@ -1,37 +1,45 @@ -void Mouse_pointer(); -void display_one_point(); -int point_in_view(); -void rectangle(); -void point(); -int read_points_from_file(); -void display_title(); -void Configure_view(); -int In_view(); -void Erase_view(); -double magnification(); -void write_map(); -void compute_temp_region2(); -void compute_temp_region(); -void Outline_box(); -void Init_graphics2(); -void Init_graphics(); +#pragma once -int Text_width(); -void Text(); -void Uparrow(); -void Downarrow(); -void display_map(); -void drawcell(); -void exit_button(); -void info_button(); +#include -void row_to_northing(); -void col_to_easting(); -void northing_to_row(); -void easting_to_col(); -void from_screen_to_geo(); -int view_to_col(); -int view_to_row(); -int col_to_view(); -int row_to_view(); -void dot(); +#include "global.h" + +void Mouse_pointer(int *, int *, int *); +void display_one_point(View *, double, double); +int point_in_view(View *, double, double); +void rectangle(int, int, int, int); +void point(int, int); +int read_points_from_file(Training *, char *); +void display_title(View *); +void Configure_view(View *, char *, char *, double, double); +int In_view(View *, int, int); +void Erase_view(View *); +double magnification(View *view); +void write_map(struct Cell_head *, char *, const char *, char *); +void compute_temp_region2(struct Cell_head *, struct Cell_head *, double, + double, int, int); +void compute_temp_region(struct Cell_head *, struct Cell_head *, double, double, + double, double); +void Outline_box(int, int, int, int); +void Init_graphics2(void); +void Init_graphics(void); + +int Text_width(char *); +void Text(char *, int, int, int, int, int); +void Uparrow(int, int, int, int); +void Downarrow(int, int, int, int); +void display_map(struct Cell_head *, View *, char *, char *); +void drawcell(View *); +void exit_button(void); +void info_button(void); + +void row_to_northing(struct Cell_head *, int, double, double *); +void col_to_easting(struct Cell_head *, int, double, double *); +void northing_to_row(struct Cell_head *, double, int *); +void easting_to_col(struct Cell_head *, double, int *); +void from_screen_to_geo(View *, int, int, double *, double *); +int view_to_col(View *, int); +int view_to_row(View *, int); +int col_to_view(View *, int); +int row_to_view(View *, int); +void dot(int, int); diff --git a/src/imagery/i.pr/i.pr.training/main.c b/src/imagery/i.pr/i.pr.training/main.c index 45d860068e..b7422cd763 100644 --- a/src/imagery/i.pr/i.pr.training/main.c +++ b/src/imagery/i.pr/i.pr.training/main.c @@ -23,7 +23,6 @@ int main(int argc, char **argv) char *mapset[TRAINING_MAX_LAYERS]; char *name[TRAINING_MAX_LAYERS]; int nmaps; - char buf[256]; int window_rows, window_cols; FILE *fp; int num_class; @@ -42,8 +41,6 @@ int main(int argc, char **argv) char *vis_map; char *vis_mapset; - char gisrc[500]; - /* Initialize the GIS calls */ G_gisinit(argv[0]); @@ -123,17 +120,15 @@ int main(int argc, char **argv) /* informations from command line */ nmaps = 0; - for (i = 0; name[nmaps] = opt1->answers[i]; i++) { + for (i = 0; (name[nmaps] = opt1->answers[i]); i++) { mapset[i] = (char *)G_find_raster2(name[i], ""); if (mapset[i] == NULL) { - sprintf(buf, "Can't find raster map <%s>", name[i]); - G_fatal_error(buf); + G_fatal_error("Can't find raster map <%s>", name[i]); } nmaps += 1; if (nmaps > TRAINING_MAX_LAYERS) { - sprintf(buf, "Too many raster maps\nMaximum number allowed = %d", - TRAINING_MAX_LAYERS); - G_fatal_error(buf); + G_fatal_error("Too many raster maps\nMaximum number allowed = %d", + TRAINING_MAX_LAYERS); } } @@ -141,8 +136,7 @@ int main(int argc, char **argv) vis_map = opt7->answer; vis_mapset = (char *)G_find_raster2(vis_map, ""); if (vis_mapset == NULL) { - sprintf(buf, "Can't find raster map <%s>", vis_map); - G_fatal_error(buf); + G_fatal_error("Can't find raster map <%s>", vis_map); } } else { @@ -151,30 +145,26 @@ int main(int argc, char **argv) } if (!opt6->answer && !opt5->answer) { - sprintf(buf, "Please select a class for the examples\n"); - G_fatal_error(buf); + G_fatal_error("Please select a class for the examples\n"); } if (!opt6->answer) { sscanf(opt5->answer, "%d", &num_class); } if (opt6->answer && opt5->answer) { - sprintf(buf, "Option class ignored\nLabels will be directlly read from " - "site file\n"); - G_warning(buf); + G_warning("Option class ignored\nLabels will be directlly read from " + "site file\n"); } sscanf(opt2->answer, "%d", &window_rows); sscanf(opt3->answer, "%d", &window_cols); if (window_rows % 2 == 0 || window_cols % 2 == 0) { - sprintf(buf, "Number of rows and columns must be odd\n"); - G_fatal_error(buf); + G_fatal_error("Number of rows and columns must be odd\n"); } /*open output file and read/initialize training */ inizialize_training(&training); if (fopen(opt4->answer, "r") == NULL) { if ((fp = fopen(opt4->answer, "w")) == NULL) { - sprintf(buf, "Can't open file %s for writing\n", opt4->answer); - G_fatal_error(buf); + G_fatal_error("Can't open file %s for writing\n", opt4->answer); } fprintf(fp, "Data type:\n"); fprintf(fp, "GrassTraining\n"); @@ -190,8 +180,7 @@ int main(int argc, char **argv) } else { if ((fp = fopen(opt4->answer, "a")) == NULL) { - sprintf(buf, "Can't open file %s for appending\n", opt4->answer); - G_fatal_error(buf); + G_fatal_error("Can't open file %s for appending\n", opt4->answer); } read_training(opt4->answer, &training); } @@ -211,7 +200,7 @@ int main(int argc, char **argv) /*plot map */ display_map(&cellhd, VIEW_MAP1, vis_map, vis_mapset); - R_standard_color(RED); + R_standard_color(IPR_RED); for (i = 0; i < training.nexamples; i++) { display_one_point(VIEW_MAP1, training.east[i], training.north[i]); } @@ -221,7 +210,7 @@ int main(int argc, char **argv) while (other == TRUE) { Mouse_pointer(&x_screen1, &y_screen1, &button1); if (In_view(VIEW_MAP1, x_screen1, y_screen1) && button1 == 1) { - R_standard_color(GREEN); + R_standard_color(IPR_GREEN); point(x_screen1, y_screen1); R_flush(); } @@ -239,9 +228,9 @@ int main(int argc, char **argv) if (In_view(VIEW_MAP1, x_screen1, y_screen1) && In_view(VIEW_MAP1, x_screen2, y_screen2) && button1 == 1 && button2 == 1) { - R_standard_color(GREEN); + R_standard_color(IPR_GREEN); rectangle(x_screen1, y_screen1, x_screen2, y_screen2); - R_standard_color(GREY); + R_standard_color(IPR_GREY); point(X1, Y1); rectangle(X1, Y1, X2, Y2); R_flush(); @@ -275,7 +264,7 @@ int main(int argc, char **argv) Erase_view(VIEW_MAP1_ZOOM); display_map(&zoomed_cellhd, VIEW_MAP1_ZOOM, vis_map, vis_mapset); - R_standard_color(RED); + R_standard_color(IPR_RED); for (i = 0; i < training.nexamples; i++) { display_one_point(VIEW_MAP1_ZOOM, training.east[i], training.north[i]); @@ -290,7 +279,7 @@ int main(int argc, char **argv) &east, &north); compute_temp_region2(&map_cellhd, &zoomed_cellhd, east, north, window_rows, window_cols); - R_standard_color(BLUE); + R_standard_color(IPR_BLUE); display_one_point(VIEW_MAP1, east, north); display_one_point(VIEW_MAP1_ZOOM, east, north); display_map(&map_cellhd, VIEW_IMAGE, vis_map, vis_mapset); @@ -306,7 +295,7 @@ int main(int argc, char **argv) training.east[training.nexamples] = east; training.north[training.nexamples] = north; - R_standard_color(RED); + R_standard_color(IPR_RED); display_one_point(VIEW_MAP1, training.east[training.nexamples], @@ -340,14 +329,13 @@ int main(int argc, char **argv) R_flush(); orig_nexamples = training.nexamples; if (read_points_from_file(&training, opt6->answer) == 0) { - sprintf(buf, "Error readining site file <%s>", opt6->answer); - G_fatal_error(buf); + G_fatal_error("Error readining site file <%s>", opt6->answer); } - R_standard_color(BLUE); + R_standard_color(IPR_BLUE); for (i = 0; i < orig_nexamples; i++) { display_one_point(VIEW_MAP1, training.east[i], training.north[i]); } - R_standard_color(RED); + R_standard_color(IPR_RED); for (i = orig_nexamples; i < training.nexamples; i++) { display_one_point(VIEW_MAP1, training.east[i], training.north[i]); R_flush(); diff --git a/src/imagery/i.pr/i.pr.training/points.c b/src/imagery/i.pr/i.pr.training/points.c index bc9397af4d..ecc04fdfcb 100644 --- a/src/imagery/i.pr/i.pr.training/points.c +++ b/src/imagery/i.pr/i.pr.training/points.c @@ -13,7 +13,7 @@ void display_one_point(View *view, double east, double north) dot(x, y); } -void dot(x, y) +void dot(int x, int y) { int vx[5], vy[5]; @@ -31,9 +31,7 @@ void dot(x, y) R_polygon_abs(vx, vy, 5); } -int point_in_view(view, east, north) -View *view; -double north, east; +int point_in_view(View *view, double east, double north) { if ((north <= view->cell.head.north) && (north >= view->cell.head.south) && (east <= view->cell.head.east) && (east >= view->cell.head.west)) @@ -42,7 +40,7 @@ double north, east; return 0; } -void rectangle(x_screen1, y_screen1, x_screen2, y_screen2) +void rectangle(int x_screen1, int y_screen1, int x_screen2, int y_screen2) { R_move_abs(x_screen1, y_screen1); R_cont_abs(x_screen1, y_screen2); @@ -51,7 +49,7 @@ void rectangle(x_screen1, y_screen1, x_screen2, y_screen2) R_cont_abs(x_screen1, y_screen1); } -void point(x, y) +void point(int x, int y) { int vx[5], vy[5]; diff --git a/src/imagery/i.pr/i.pr.training/sites.c b/src/imagery/i.pr/i.pr.training/sites.c index 5818aa24bb..39bffb5cd9 100644 --- a/src/imagery/i.pr/i.pr.training/sites.c +++ b/src/imagery/i.pr/i.pr.training/sites.c @@ -5,30 +5,26 @@ int read_points_from_file(Training *training, char *site_file) { - char msg[256]; char *mapset; - FILE *out; + struct Map_info *out; Site *site; int dims = 0, cat = 0, strs = 0, dbls = 0; int code; mapset = G_find_sites(site_file, ""); if (mapset == NULL) { - sprintf(msg, - "read_points_from_file-> Can't find vector points map <%s>", - site_file); - G_fatal_error(msg); + G_fatal_error( + "read_points_from_file-> Can't find vector points map <%s>", + site_file); } out = G_fopen_sites_old(site_file, mapset); if (out == NULL) { - sprintf(msg, - "read_points_from_file-> Can't open vector points map <%s>", - site_file); - G_fatal_error(msg); + G_fatal_error( + "read_points_from_file-> Can't open vector points map <%s>", + site_file); } if (G_site_describe(out, &dims, &cat, &strs, &dbls) != 0) { - sprintf(msg, "read_points_from_file-> Error in G_site_describe"); - G_warning(msg); + G_warning("read_points_from_file-> Error in G_site_describe"); return 0; } site = (Site *)G_calloc(1, sizeof(Site)); @@ -41,8 +37,7 @@ int read_points_from_file(Training *training, char *site_file) } G_sites_close(out); if (code != -1) { - sprintf(msg, "read_points_from_file-> Error in G_site_get"); - G_warning(msg); + G_warning("read_points_from_file-> Error in G_site_get"); return 0; } return 1; diff --git a/src/imagery/i.pr/i.pr.training/title.c b/src/imagery/i.pr/i.pr.training/title.c index 8d0f60f0c2..15a43e88dc 100644 --- a/src/imagery/i.pr/i.pr.training/title.c +++ b/src/imagery/i.pr/i.pr.training/title.c @@ -7,7 +7,6 @@ void display_title(View *view) View *title; char center[100]; int size; - double magnification(); *center = 0; @@ -30,10 +29,10 @@ void display_title(View *view) size = title->nrows - 4; R_text_size(size, size); if (*center) { - R_standard_color(YELLOW); + R_standard_color(IPR_YELLOW); Text(center, title->top, title->bottom, (title->left + title->right - Text_width(center)) / 2, title->right, 2); } - R_standard_color(WHITE); + R_standard_color(IPR_WHITE); } diff --git a/src/imagery/i.pr/i.pr.training/view.c b/src/imagery/i.pr/i.pr.training/view.c index 96bb193c0b..fe675319e5 100644 --- a/src/imagery/i.pr/i.pr.training/view.c +++ b/src/imagery/i.pr/i.pr.training/view.c @@ -36,7 +36,7 @@ int In_view(View *view, int x, int y) void Erase_view(View *view) { - R_standard_color(BLACK); + R_standard_color(IPR_BLACK); R_box_abs(view->left, view->top, view->right, view->bottom); } diff --git a/src/imagery/i.pr/i.pr.training/write_map.c b/src/imagery/i.pr/i.pr.training/write_map.c index 0786caf939..e1dce99b34 100644 --- a/src/imagery/i.pr/i.pr.training/write_map.c +++ b/src/imagery/i.pr/i.pr.training/write_map.c @@ -4,12 +4,14 @@ #include "globals.h" #include -void write_map(struct Cell_head *cellhd, char *name, char *mapset, char *dest) +void write_map(struct Cell_head *cellhd, char *name, const char *mapset, + char *dest) { - int fd_to, fd_from, row, nrows, ncols; + int fd_to, fd_from, row, nrows; CELL *buf; char command[500]; - char *lp, *lm; + char *lp; + const char *lm; char *coldir; struct stat statdir; @@ -27,7 +29,6 @@ void write_map(struct Cell_head *cellhd, char *name, char *mapset, char *dest) buf = Rast_allocate_buf(CELL_TYPE); - ncols = Rast_window_cols(); nrows = Rast_window_rows(); for (row = 0; row < nrows; row++) { diff --git a/src/imagery/i.pr/i.pr.uxb/i.pr.uxb.html b/src/imagery/i.pr/i.pr.uxb/i.pr.uxb.html new file mode 100644 index 0000000000..221c574c5c --- /dev/null +++ b/src/imagery/i.pr/i.pr.uxb/i.pr.uxb.html @@ -0,0 +1,7 @@ +

DESCRIPTION

+ +Module for detection of unexploded bombs. + +

AUTHORS

+ +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.uxb/i.pr.uxb.md b/src/imagery/i.pr/i.pr.uxb/i.pr.uxb.md new file mode 100644 index 0000000000..9904e2fbb1 --- /dev/null +++ b/src/imagery/i.pr/i.pr.uxb/i.pr.uxb.md @@ -0,0 +1,7 @@ +## DESCRIPTION + +Module for detection of unexploded bombs. + +## AUTHORS + +Stefano Merler, FBK, Trento, Italy diff --git a/src/imagery/i.pr/i.pr.uxb/main.c b/src/imagery/i.pr/i.pr.uxb/main.c index 2316143cb7..a573b72055 100644 --- a/src/imagery/i.pr/i.pr.uxb/main.c +++ b/src/imagery/i.pr/i.pr.uxb/main.c @@ -25,7 +25,7 @@ #include #include "global.h" -int extract_array_with_null(); +int extract_array_with_null(int, int, int, int, double **, double *); int main(int argc, char *argv[]) { @@ -39,7 +39,6 @@ int main(int argc, char *argv[]) SupportVectorMachine svm; BTree btree; BSupportVectorMachine bsvm; - char tmpbuf[500]; char *mapset; struct Cell_head cellhd; double ***matrix; @@ -83,7 +82,7 @@ int main(int argc, char *argv[]) opt2->type = TYPE_STRING; opt2->required = YES; opt2->description = - "Input file containing the model (output of i .pr_model).\n\t\tIf the " + "Input file containing the model (output of i.pr.model).\n\t\tIf the " "data used for model development are not GRASS_data the program will " "abort."; @@ -109,12 +108,10 @@ int main(int argc, char *argv[]) &btree, &bsvm); if (features.training.data_type != GRASS_data) { - sprintf(tmpbuf, "Model build using othe than GRASS data\n"); - G_fatal_error(tmpbuf); + G_fatal_error("Model build using othe than GRASS data\n"); } if (model_type == 0) { - sprintf(tmpbuf, "Model not recognized\n"); - G_fatal_error(tmpbuf); + G_fatal_error("Model not recognized\n"); } if (model_type == GM_model) { @@ -125,15 +122,13 @@ int main(int argc, char *argv[]) G_get_window(&cellhd); if (fabs((cellhd.ew_res - features.training.ew_res) / features.training.ew_res) > 0.1) { - sprintf(tmpbuf, "EW resolution of training data and test map differs " - "more than 10%%\n"); - G_warning(tmpbuf); + G_warning("EW resolution of training data and test map differs more " + "than 10%%\n"); } if (fabs((cellhd.ns_res - features.training.ns_res) / features.training.ns_res) > 0.1) { - sprintf(tmpbuf, "NS resolution of training data and test map differs " - "more than 10%%\n"); - G_warning(tmpbuf); + G_warning("NS resolution of training data and test map differs more " + "than 10%%\n"); } /*compute features space */ @@ -195,26 +190,21 @@ int main(int argc, char *argv[]) n_input_map = 0; for (l = 0; opt1->answers[l]; l++) { if ((mapset = (char *)G_find_raster2(opt1->answers[l], "")) == NULL) { - sprintf(tmpbuf, "raster map [%s] not available", opt1->answers[l]); - G_fatal_error(tmpbuf); + G_fatal_error("raster map [%s] not available", opt1->answers[l]); } if ((fd[l] = Rast_open_old(opt1->answers[l], mapset)) < 0) { - sprintf(tmpbuf, "error opening raster map [%s]", opt1->answers[l]); - G_fatal_error(tmpbuf); + G_fatal_error("error opening raster map [%s]", opt1->answers[l]); } n_input_map += 1; } if (n_input_map < features.training.nlayers) { - sprintf(tmpbuf, "Model requires %d input maps\n", - features.training.nlayers); - G_fatal_error(tmpbuf); + G_fatal_error("Model requires %d input maps\n", + features.training.nlayers); } if (n_input_map > features.training.nlayers) { - sprintf(tmpbuf, "Only first %d maps considered\n", - features.training.nlayers); - G_warning(tmpbuf); + G_warning("Only first %d maps considered\n", features.training.nlayers); } /*useful vars */ @@ -368,8 +358,8 @@ int main(int argc, char *argv[]) predict_tree_multiclass(&tree, X); break; case BCT_model: - output_cell[r - borderR][c] = - predict_btree_multiclass(&btree, X); + output_cell[r - borderR][c] = predict_btree_multiclass( + &btree, X, features.nclasses, features.p_classes); break; default: break; diff --git a/src/imagery/i.pr/include/func.h b/src/imagery/i.pr/include/func.h index 17669267a4..8df3e6b7cf 100644 --- a/src/imagery/i.pr/include/func.h +++ b/src/imagery/i.pr/include/func.h @@ -1,274 +1,306 @@ +#pragma once + /* tree.c */ -void compute_tree(); -void write_tree(); -void compute_tree_boosting(); -void compute_tree_boosting_reg(); -void regularized_boosting(); -double test_regularized_boosting(); -void test_btree_reg(); -void shaving_and_compute(); -void compute_tree_bagging(); -void write_bagging_boosting_tree(); -int predict_tree_multiclass(); -double predict_tree_2class(); -void test_tree(); -double predict_btree_2class(); -int predict_btree_multiclass(); -void test_btree(); -void test_btree_progressive(); -double predict_btree_2class_progressive(); -int predict_btree_multiclass_progressive(); -void compute_tree_boosting_parallel(); +void compute_tree(Tree *, int, int, double **, int *, int, int *, int, int, + double *); +void write_tree(char *, Tree *, Features *); +void compute_tree_boosting(BTree *, int, double, int, int, double **, int *, + int, int *, int, int, int, double *); +void compute_tree_boosting_reg(BTree *, int, double, int, int, double **, int *, + int, int *, int, int, int, double *, double *); +void regularized_boosting(int, double, int, int, double **, int *, int, int *, + int, int, int, double *, double *, int, Features, + char *, Features, int, char[150], char[150], + char[150], Features, int); +double test_regularized_boosting(BTree *, Features *); +void test_btree_reg(BTree *, Features *, char *, double *); +void shaving_and_compute(int, double, int, int, double **, int *, int, int *, + int, int, int, double *, double *, int, double, char *, + char[150], Features, Features, char *, int); +void compute_tree_bagging(BTree *, int, int, int, double **, int *, int, int *, + int, int, double *); +void write_bagging_boosting_tree(char *, BTree *, Features *); +int predict_tree_multiclass(Tree *, double *); +double predict_tree_2class(Tree *, double *); +void test_tree(Tree *, Features *, char *); +double predict_btree_2class(BTree *, double *); +int predict_btree_multiclass(BTree *, double *, int, int *); +void test_btree(BTree *, Features *, char *); +void test_btree_progressive(BTree *, Features *, char *); +double predict_btree_2class_progressive(BTree *, double *, int); +int predict_btree_multiclass_progressive(BTree *, double *, int, int *, int); +void compute_tree_boosting_parallel(BTree *, int, int, double, int, int, + double **, int *, int, int *, int, int, int, + double *); /* features_selection.c */ -void compute_valoriDJ(); -void free_svm(); -void e_rfe_lin(); -void e_rfe_gauss(); -void one_rfe_lin(); -void one_rfe_gauss(); -void rfe_lin(); -void rfe_gauss(); -void write_matrix(); -void compute_H(); -void compute_H_perdiff(); -void traslo(); +void compute_valoriDJ(SupportVectorMachine *, Features *, double **, double **, + double **); +void free_svm(SupportVectorMachine *); +void e_rfe_lin(SupportVectorMachine *, Features *, int *, int *, int, int *, + FILE *, FILE *); +void e_rfe_gauss(double *, Features *, int *, int *, int, double **, double **, + int *, double, FILE *, FILE *); +void one_rfe_lin(SupportVectorMachine *, int *, int *, FILE *); +void one_rfe_gauss(double *, int *, int *, int, FILE *); +void rfe_lin(SupportVectorMachine *, Features *, int *, int *, int, FILE *); +void rfe_gauss(double *, Features *, int *, int *, int, double **, double **, + double, FILE *); +void compute_H(double **, double **, int *, int, int, double); +void compute_H_perdiff(double **, double **, double **, int, double, int); +void traslo(double *, int); /* soft_margin_boosting.c */ -void maximize(); +void maximize(double *, int, double *, int, double **); /* write_matrix.c */ -void write_matrix(); +void write_matrix(char *, double **, int, int); /* entropy.c */ -double Entropy(); -double Clog(); -void histo(); -void histo1(); +double Entropy(double *, int, double); +double Clog(double, double); +void histo(double *, int, double *, int); +void histo1(double *, int, int *, int); /* min_quadratic.c */ -void mqc(); +void mqc(double **, double *, int, double **, double *, int, double **, + double *, int, double, double *, double *); /* blob.c */ -void extract_sites_from_blob(); -void find_blob(); +void extract_sites_from_blob(Blob *, int, int, struct Cell_head *, BlobSites *, + double **); +void find_blob(double **, int, int, Blob **, int *, int *, double, double); /* test.c */ -void ksone_normal(); -void kstwo(); -double probks(); -double probks2(); -double normal_distribution(); -double cumulative_normal_distribution(); -double gammln(); -double betacf(); -double betai(); -void tutest(); +void ksone_normal(double *, int, double, double, double *, double *); +void kstwo(double *, int, double *, int, double *, double *); +double probks(double); +double probks2(double, int); +double normal_distribution(double, double, double); +double cumulative_normal_distribution(double, double, double); +double gammln(double); +double betacf(double, double, double); +double betai(double, double, double); +void tutest(double *, int, double *, int, double *, double *); /* read_models.c */ -int read_model(); +int read_model(char *, Features *, NearestNeighbor *, GaussianMixture *, Tree *, + SupportVectorMachine *, BTree *, BSupportVectorMachine *); /* nn.c */ -void compute_nn(); -void write_nn(); -int predict_nn_multiclass(); -double predict_nn_2class(); -void test_nn(); +void compute_nn(NearestNeighbor *, int, int, double **, int *); +void write_nn(char *, NearestNeighbor *, Features *); +int predict_nn_multiclass(NearestNeighbor *, double *, int, int, int *); +double predict_nn_2class(NearestNeighbor *, double *, int, int, int *); +void test_nn(NearestNeighbor *, Features *, int, char *); /* svm.c */ -void compute_svm(); -void estimate_cv_error(); -void write_svm(); -void test_svm(); -double predict_svm(); -void compute_svm_bagging(); -void write_bagging_boosting_svm(); -void compute_svm_boosting(); -double predict_bsvm(); -void test_bsvm(); -void test_bsvm_progressive(); -double predict_bsvm_progressive(); -double dot_product(); +void compute_svm(SupportVectorMachine *, int, int, double **, int *, int, + double, double, double, double, int, int, double *); +void estimate_cv_error(SupportVectorMachine *); +void write_svm(char *file, SupportVectorMachine *, Features *); +void test_svm(SupportVectorMachine *, Features *, char *); +double predict_svm(SupportVectorMachine *, double *); +void compute_svm_bagging(BSupportVectorMachine *, int, int, int, double **, + int *, int, double, double, double, double, int, int, + double *); +void write_bagging_boosting_svm(char *, BSupportVectorMachine *, Features *); +void compute_svm_boosting(BSupportVectorMachine *, int, double, int, int, + double **, int *, int, int *, int, double, double, + double, double, int, int, double *, int); +double predict_bsvm(BSupportVectorMachine *, double *); +void test_bsvm(BSupportVectorMachine *, Features *, char *); +void test_bsvm_progressive(BSupportVectorMachine *, Features *, char *); +double predict_bsvm_progressive(BSupportVectorMachine *, double *, int); +double dot_product(double *, double *, int); /* features.c */ -void compute_features(); -void write_features(); -void standardize_features(); -void write_header_features(); -void read_features(); -void read_header_features(); +void compute_features(Features *); +void write_features(char *, Features *); +void standardize_features(Features *); +void write_header_features(FILE *, Features *); +void read_features(char *, Features *, int); +void read_header_features(FILE *, Features *); /* gm.c */ -void compute_gm(); -void write_gm(); -void test_gm(); -void compute_test_gm(); -int predict_gm_multiclass(); -double predict_gm_2class(); +void compute_gm(GaussianMixture *, int, int, double **, int *, int, int *); +void write_gm(char *, GaussianMixture *, Features *); +void test_gm(GaussianMixture *, Features *, char *); +void compute_test_gm(GaussianMixture *); +int predict_gm_multiclass(GaussianMixture *, double *); +double predict_gm_2class(GaussianMixture *, double *); /* training.c */ -void inizialize_training(); -void read_training(); +void inizialize_training(Training *); +void read_training(char *, Training *); /* matrix.c */ -void product_double_matrix_double_matrix(); -void product_double_matrix_double_vector(); -void product_double_vector_double_matrix(); -void transpose_double_matrix(); -void double_matrix_to_vector(); -void extract_portion_of_double_matrix(); -void transpose_double_matrix_rectangular(); +void product_double_matrix_double_matrix(double **, double **, int, int, int, + double **); +void product_double_matrix_double_vector(double **, double *, int, int, + double *); +void product_double_vector_double_matrix(double **, double *, int, int, + double *); +void transpose_double_matrix(double **, int); +void double_matrix_to_vector(double **, int, int, double *); +void extract_portion_of_double_matrix(int, int, int, int, double **, double **); +void transpose_double_matrix_rectangular(double **, int, int, double ***); /* pca.c */ -void inizialize_pca(); -void write_pca(); -void read_pca(); +void inizialize_pca(Pca *, int); +void write_pca(FILE *, Pca *); +void read_pca(FILE *, Pca *); /* random.c */ -double ran1(); -double gasdev(); -double gamdev(); -double expdev(); +double ran1(int *); +double gasdev(int *); +double gamdev(double, double, int *); +double expdev(int *); /* bootstrap.c */ -void Bootsamples(); -void Bootsamples_rseed(); +void Bootsamples(int, double *, int *); +void Bootsamples_rseed(int, double *, int *, int *); /* dist.c */ -double squared_distance(); -double euclidean_distance(); -double scalar_product(); -double euclidean_norm(); +double squared_distance(double *, double *, int); +double euclidean_distance(double *, double *, int); +double scalar_product(double *, double *, int); +double euclidean_norm(double *, int); /* open.c */ -int open_new_CELL(); -int open_new_DCELL(); +int open_new_CELL(char *); +int open_new_DCELL(char *); /* percent.c */ -void percent(); +void percent(int, int, int); /* getline.c */ -char *GetLine(); +char *GetLine(FILE *); /* sort.c */ -void shell(); -void indexx_1(); +void shell(int, double *); +void indexx_1(int, double[], int[]); /* integration.c */ -double trapzd(); -double trapzd1(); -double trapzd2(); -double qtrap(); -double qtrap1(); -double qtrap2(); +double trapzd(double (*)(double), double, double, int); +double trapzd1(double (*)(double, double), double, double, double, int); +double trapzd2(double (*)(double, double, double), double, double, double, + double, int); +double qtrap(double (*)(double), double, double); +double qtrap1(double (*)(double), double, double, double); +double qtrap2(double (*)(double), double, double, double, double); /* eigen.c */ -void tred2(); -int tqli(); -void eigen_of_double_matrix(); -void eigsrt(); +void tred2(double **, int, double[], double[]); +int tqli(double[], double[], int, double **); +void eigen_of_double_matrix(double **, double **, double *, int); +void eigsrt(double *, double **, int); /* stats.c */ -double mean_of_double_array(); -double var_of_double_array(); -double sd_of_double_array(); -double var_of_double_array_given_mean(); -double sd_of_double_array_given_mean(); -void mean_and_var_of_double_matrix_by_row(); -void mean_and_sd_of_double_matrix_by_row(); -void mean_and_var_of_double_matrix_by_col(); -void mean_and_sd_of_double_matrix_by_col(); -double auto_covariance_of_2_double_array(); -void covariance_of_double_matrix(); -double entropy(); -double gaussian_kernel(); -double squared_gaussian_kernel(); -double min(); -double max(); +double mean_of_double_array(double *, int); +double var_of_double_array(double *, int); +double sd_of_double_array(double *, int); +double var_of_double_array_given_mean(double *, int, double); +double sd_of_double_array_given_mean(double *, int, double); +void mean_and_var_of_double_matrix_by_row(double **, int, int, double *, + double *); +void mean_and_sd_of_double_matrix_by_row(double **, int, int, double *, + double *); +void mean_and_var_of_double_matrix_by_col(double **, int, int, double *, + double *); +void mean_and_sd_of_double_matrix_by_col(double **, int, int, double *, + double *); +double auto_covariance_of_2_double_array(double *, double *, int); +void covariance_of_double_matrix(double **, int, int, double **); +double entropy(double *, int); +double gaussian_kernel(double *, double *, int, double); +double squared_gaussian_kernel(double *, double *, int, double); +double min(double *, int); +double max(double *, int); /* lu.c */ -void ludcmp(); -void lubksb(); -void inverse_of_double_matrix(); -double determinant_of_double_matrix(); +void ludcmp(double **, int, int *, double *); +void lubksb(double **, int, int *, double[]); +void inverse_of_double_matrix(double **, double **, int); +double determinant_of_double_matrix(double **, int); diff --git a/src/imagery/i.pr/include/global.h b/src/imagery/i.pr/include/global.h index 7877ca0842..1e83244469 100644 --- a/src/imagery/i.pr/include/global.h +++ b/src/imagery/i.pr/include/global.h @@ -1,5 +1,16 @@ +#pragma once + #include -#include "func.h" +#include + +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif +#if __has_attribute(unused) +#define IPR_UNUSED __attribute__((unused)) +#else +#define IPR_UNUSED +#endif #define PIG M_PI @@ -154,7 +165,7 @@ typedef struct { double b; } SVM_direct_kernel; -typedef struct { +typedef struct SupportVectorMachine { int N; /*number of examples */ int d; /*number of features */ int orig_d; @@ -171,9 +182,10 @@ typedef struct { int *target; /*class labels */ int kernel_type; /*kernel type:1 linear, 2 gaussian, 3 squared gaussian */ int end_support_i; /*set to N, never changed */ - double (*learned_func)(); /*the SVM */ - double (*kernel_func)(); /*the kernel */ - double delta_b; /*gap between old and updated offset */ + double (*learned_func)(int, struct SupportVectorMachine *); /*the SVM */ + double (*kernel_func)(int, int, + struct SupportVectorMachine *); /*the kernel */ + double delta_b; /*gap between old and updated offset */ double *precomputed_self_dot_product; /*squared norm of the training data */ double *Cw; /*weighted bias/variance parameter (sen/spe tuning) */ SVM_direct_kernel *models; @@ -216,3 +228,5 @@ typedef struct double max; /*minimum value of the blob */ int n; /*number of points whitin the blob */ } BlobSites; + +#include "func.h"