Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/imagery/i.pr/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
MODULE_TOPDIR = ../..

PGM = i.pr

include $(MODULE_TOPDIR)/include/Make/Dir.make

SUBDIRS = \
Expand All @@ -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/
5 changes: 3 additions & 2 deletions src/imagery/i.pr/PRLIB/blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#include <grass/raster.h>
#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,
Expand Down
15 changes: 5 additions & 10 deletions src/imagery/i.pr/PRLIB/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/imagery/i.pr/PRLIB/entropy.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Entropy management
*/

#include "func.h"
#include "global.h"
#include <math.h>

double Entropy(double *data, int n, double zero)
Expand Down
55 changes: 17 additions & 38 deletions src/imagery/i.pr/PRLIB/features.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -182,27 +180,23 @@ 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,
&cellhd);
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;
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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]] =
Expand All @@ -597,7 +582,6 @@ void write_header_features(FILE *fp, Features *features)
*/
{
int i;
int dim;

fprintf(fp, "#####################\n");
fprintf(fp, "TRAINING:\n");
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
78 changes: 24 additions & 54 deletions src/imagery/i.pr/PRLIB/features_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
#include <string.h>
#include <math.h>

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;
Expand Down Expand Up @@ -69,7 +67,7 @@ double **H_tot, **H_tmp, **valoriDJ;
}
}

void free_svm(svm) SupportVectorMachine *svm;
void free_svm(SupportVectorMachine *svm)
{
int j;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/imagery/i.pr/PRLIB/getline.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
#include <stdio.h>
#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;

Expand Down
Loading
Loading