assign5/mat.cpp
// returns new matrix for a matrix of min and max of each column
// normalizes within each column according to the min and max in that column
// so the range is now between 0 and 1 in each column
// NOTE: it will not rescale a column that is a constant!!
// WARNING: allocates new matrix for answer and alters matrix self
returns new matrix for a matrix of min and max of each column
normalizes within each column according to the min and max in that column
so the range is now between 0 and 1 in each column
NOTE: it will not rescale a column that is a constant
WARNING: allocates new matrix for answer and alters matrix self
returns new matrix for a matrix of min and max of each column normalizes within each column according to the min and max in that column so the range is now between 0 and 1 in each column NOTE : it will not rescale a column that is a constant WARNING : allocates new matrix for answer and alters matrix self
Matrix Matrix::normalizeCols()
{
    double min, max;
    assertDefined("normalize");
    Matrix minMax(2, maxc, "minMax for " + name);
    for (int c=0; c<maxc; c++) {
        min = max = m[0][c];
        for (int r=0; r<maxr; r++) {
            if (m[r][c] < min) min = m[r][c];
            if (m[r][c] > max) max = m[r][c];
        }
        minMax.m[0][c] = min;
        minMax.m[1][c] = max;
        if (max!=min) {
            for (int r=0; r<maxr; r++) {
                m[r][c] = (m[r][c] - min)/(max - min);
            }
        }
    }
    minMax.defined = true;
    return minMax;
}
Matrix Matrix :: normalizeCols ( ) { double min , max ; assertDefined ( " " ) ; Matrix minMax ( 2 , maxc , " " + name ) ; for ( int c = 0 ; c < maxc ; c ++ ) { min = max = m [ 0 ] [ c ] ; for ( int r = 0 ; r < maxr ; r ++ ) { if ( m [ r ] [ c ] < min ) min = m [ r ] [ c ] ; if ( m [ r ] [ c ] > max ) max = m [ r ] [ c ] ; } minMax . m [ 0 ] [ c ] = min ; minMax . m [ 1 ] [ c ] = max ; if ( max != min ) { for ( int r = 0 ; r < maxr ; r ++ ) { m [ r ] [ c ] = ( m [ r ] [ c ] - min ) / ( max - min ) ; } } } minMax . defined = true ; return minMax ; }
returns new matrix for a matrix of min and max of each column
normalizes within each column according to the min and max in that column
so the range is now between 0 and 1 in each column
NOTE: it will not rescale a column that is a constant!!
returns new matrix for a matrix of min and max of each column normalizes within each column according to the min and max in that column so the range is now between 0 and 1 in each column NOTE : it will not rescale a column that is a constant!!
// find min and max // remember it // rescale column