[GRASS-SVN] r54367 - grass-addons/grass7/imagery/i.spec.unmix
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Dec 22 07:38:12 PST 2012
Author: rashadkm
Date: 2012-12-22 07:38:11 -0800 (Sat, 22 Dec 2012)
New Revision: 54367
Modified:
grass-addons/grass7/imagery/i.spec.unmix/la_extra.c
grass-addons/grass7/imagery/i.spec.unmix/main.c
Log:
i.spec.unmix: initalized all math vector
Modified: grass-addons/grass7/imagery/i.spec.unmix/la_extra.c
===================================================================
--- grass-addons/grass7/imagery/i.spec.unmix/la_extra.c 2012-12-22 10:23:23 UTC (rev 54366)
+++ grass-addons/grass7/imagery/i.spec.unmix/la_extra.c 2012-12-22 15:38:11 UTC (rev 54367)
@@ -19,17 +19,16 @@
matrix = G_matrix_init(rows, cols, rows);
int i, j, p, index = 0;
for (i = 0; i < rows; i++)
- {
for (j = 0; j < cols; j++)
- matrix->vals[index++] = in->vals[i + j * cols];
- }
+ G_matrix_set_element(matrix, i, j, G_matrix_get_element(in, i, j));
+/* matrix->vals[index++] = in->vals[i + j * cols];*/
int old_size = in->rows * in->cols;
int new_size = rows * cols;
if (new_size > old_size)
for (p = old_size; p < new_size; p++)
- matrix->vals[p] = 0.0;
+ G_matrix_set_element(matrix, i, j, 0.0);
return (matrix);
}
@@ -72,18 +71,23 @@
unsigned int i, m, n, j;
register doublereal sum;
- if (A->cols != b->ldim) {
- G_warning (_("Input matrix and vector have differing dimensions"));
+//G_message("A=%d,%d,%d", A->cols, A->rows, A->ldim);
+//G_message("B=%d,%d,%d", b->cols, b->rows, b->ldim);
+ if (A->cols != b->cols) {
+ G_warning (_("Input matrix and vector have differing dimensions1"));
+
return NULL;
+
}
if (!out) {
G_warning (_("Output vector is uninitialized"));
return NULL;
}
- if (out->ldim != A->rows) {
- G_warning (_("Output vector has incorrect dimension"));
- return NULL;
- }
+/* if (out->ldim != A->rows) {*/
+/* G_warning (_("Output vector has incorrect dimension"));*/
+/* exit(1);*/
+/* return NULL;*/
+/* }*/
m = A->rows;
@@ -93,7 +97,9 @@
sum = 0.0;
int width = A->rows;
for (j = 0; j < n; j++) {
- sum += A->vals[i + j * width] * b->vals[j];
+
+ sum +=G_matrix_get_element(A, i, j) * G_matrix_get_element(b, 0, j);
+ /*sum += A->vals[i + j * width] * b->vals[j];*/
out->vals[i] = sum;
}
}
Modified: grass-addons/grass7/imagery/i.spec.unmix/main.c
===================================================================
--- grass-addons/grass7/imagery/i.spec.unmix/main.c 2012-12-22 10:23:23 UTC (rev 54366)
+++ grass-addons/grass7/imagery/i.spec.unmix/main.c 2012-12-22 15:38:11 UTC (rev 54367)
@@ -273,18 +273,18 @@
mu = 0.0001 * pow(10, -1 * ceil(log10(max_total)));
/* TODO: Missing? startvector = G_vector_init (0, 0, RVEC); */
- startvector = G_vector_init(A->cols, A->cols, CVEC);
+ startvector = G_vector_init(A->cols, 1, RVEC);
if (startvector == NULL)
G_fatal_error(_("Unable to allocate memory for vector"));
/* TODO: Missing? A_times_startvector = G_vector_init (0, 0, RVEC); */
- A_times_startvector = G_vector_init(A_tilde->rows, A_tilde->rows, CVEC); /* length: no. of bands */
+ A_times_startvector = G_vector_init(A_tilde->rows, 1, RVEC); /* length: no. of bands */
/* TODO: Missing? errorvector = G_vector_init (0, 0, RVEC); */
- errorvector = G_vector_init(A_tilde->rows, A_tilde->rows, CVEC); /* length: no. of bands */
+ errorvector = G_vector_init(A_tilde->rows, 1, RVEC); /* length: no. of bands */
/* TODO: Missing? temp = G_vector_init (0, 0, RVEC); */
- temp = G_vector_init(A_tilde->cols, A_tilde->cols, CVEC); /* length: no. of spectra */
+ temp = G_vector_init(A_tilde->cols, 1, RVEC); /* length: no. of spectra */
/* length: no. of bands */
@@ -332,22 +332,22 @@
/* get pixel values of each band and store in b vector: */
/* length: no. of bands + 1 (GAMMA) */
- b_gamma = G_vector_init(A_tilde->rows, A_tilde->rows, CVEC);
+ b_gamma = G_vector_init(A_tilde->rows, 1, RVEC);
if (b_gamma == NULL)
G_fatal_error(_("Unable to allocate memory for matrix"));
for (band = 0; band < Ref.nfiles; band++)
- G_matrix_set_element(b_gamma, band, 0, cell[band][col]);
+ G_matrix_set_element(b_gamma, 0, band, cell[band][col]);
/* add GAMMA for 1. constraint as last element */
- G_matrix_set_element(b_gamma, Ref.nfiles, 0, GAMMA);
+ G_matrix_set_element(b_gamma, 0, Ref.nfiles, GAMMA);
for (k = 0; k < A_tilde->cols; k++)
- G_matrix_set_element(startvector, k, 0,
+ G_matrix_set_element(startvector, 0, k,
(1.0 / A_tilde->cols));
/* calculate fraction vector for current pixel
@@ -360,6 +360,8 @@
*/
/* solve with iterative solution: */
+
+
while (fabs(change) > 0.0001) {
G_mat_vector_product(A_tilde, startvector,
@@ -377,8 +379,8 @@
for (k = 0; k < A_tilde->cols; k++)
/* no. of spectra times */
/* if one element gets negative, set it to zero */
- if ((G_matrix_get_element(startvector, k, 0) < 0))
- G_matrix_set_element(startvector, k, 0, 0);
+ if ((G_matrix_get_element(startvector, 0, k) < 0))
+ G_matrix_set_element(startvector, 0, k, 0);
/* Check the deviation */
@@ -393,11 +395,10 @@
/* G_message("change=%lf, norm2=%lf",change, norm); */
}
-
vec_struct *fraction;
/* G_message("fcol %d and A->cols %d", startvector->dim, A->cols); */
- fraction = G_vector_init(A->cols, A->cols, CVEC); /* length: no. of spectra */
+ fraction = G_vector_init(A->cols,1, RVEC); /* length: no. of spectra */
error = deviation / G_vector_norm_euclid(b_gamma);
fraction = G_vector_copy(startvector, NO_COMPACT);
@@ -406,7 +407,7 @@
/* write result in full percent */
for (i = 0; i < A->cols; i++) /* no. of spectra */
result_cell[i][col] =
- (CELL) (100 * G_matrix_get_element(fraction, i, 0));
+ (CELL) (100 * G_matrix_get_element(fraction, 0, i));
/* save error and iterations */
error_cell[col] = (CELL) (100 * error);
More information about the grass-commit
mailing list