Ejemplo n.º 1
0
def fuzzify(membership, row_scores, column_scores, num_iterations, iteration_result,
            add_fuzz):
    """Provide an iteration-specific fuzzification"""
    if add_fuzz == 'none':
        logging.debug('DO NOT FUZZIFY !!')
        return row_scores, column_scores

    # truth table maps from add_fuzz parameter to where fuzz should be added
    fuzz_vals = {'both': (True, True), 'rows': (True, False), 'columns': (False, True)}
    fuzz_rows, fuzz_cols = fuzz_vals[add_fuzz]

    iteration = iteration_result['iteration']
    #logging.debug("__fuzzify(), setup...")
    #start_time = util.current_millis()
    fuzzy_coeff = old_fuzzy_coefficient(iteration, num_iterations)
    iteration_result['fuzzy-coeff'] = fuzzy_coeff

    if fuzz_rows:
        num_row_fuzzy_values = row_scores.num_rows * row_scores.num_columns
        row_score_values = row_scores.values
        row_sd_values = []

        # iterate the row names directly
        row_names = row_scores.row_names
        for col in xrange(row_scores.num_columns):
            cluster_rows = membership.rows_for_cluster(col + 1)
            for row in xrange(row_scores.num_rows):
                if row_names[row] in cluster_rows:
                    row_sd_values.append(row_score_values[row, col])

        # Note: If there are no non-NaN values in row_sd_values, row_rnorm
        # will have all NaNs
        row_rnorm = util.sd_rnorm(row_sd_values, num_row_fuzzy_values, fuzzy_coeff)
        row_score_values += np.array(row_rnorm).reshape(row_scores.num_rows,
                                                        row_scores.num_columns)

    if fuzz_cols:
        num_col_fuzzy_values = column_scores.num_rows * column_scores.num_columns
        col_score_values = column_scores.values
        col_sd_values = []
        row_names = column_scores.row_names
        for col in xrange(column_scores.num_columns):
            cluster_cols = membership.columns_for_cluster(col + 1)
            for row in xrange(column_scores.num_rows):
                if row_names[row] in cluster_cols:
                    col_sd_values.append(col_score_values[row, col])

        # Note: If there are no non-NaN values in col_sd_values, col_rnorm
        # will have all NaNs
        col_rnorm = util.sd_rnorm(col_sd_values, num_col_fuzzy_values, fuzzy_coeff)
        # add fuzzy values to the row/column scores
        col_score_values += np.array(col_rnorm).reshape(column_scores.num_rows,
                                                        column_scores.num_columns)

    #elapsed = util.current_millis() - start_time
    #logging.debug("fuzzify() finished in %f s.", elapsed / 1000.0)
    return row_scores, column_scores
Ejemplo n.º 2
0
 def test_sd_rnorm(self):
     result = util.sd_rnorm([1.3, 1.6, 1.2, 1.05], 9, 0.748951)
     # the results are fairly random, make sure we have the right
     # number of values
     self.assertEquals(9, len(result))
Ejemplo n.º 3
0
def fuzzify(membership, row_scores, column_scores, num_iterations,
            iteration_result, add_fuzz):
    """Provide an iteration-specific fuzzification"""
    if add_fuzz == 'none':
        logging.debug('DO NOT FUZZIFY !!')
        return row_scores, column_scores

    # truth table maps from add_fuzz parameter to where fuzz should be added
    fuzz_vals = {
        'both': (True, True),
        'rows': (True, False),
        'columns': (False, True)
    }
    fuzz_rows, fuzz_cols = fuzz_vals[add_fuzz]

    iteration = iteration_result['iteration']
    #logging.debug("__fuzzify(), setup...")
    #start_time = util.current_millis()
    fuzzy_coeff = old_fuzzy_coefficient(iteration, num_iterations)
    iteration_result['fuzzy-coeff'] = fuzzy_coeff

    if fuzz_rows:
        num_row_fuzzy_values = row_scores.num_rows * row_scores.num_columns
        row_score_values = row_scores.values
        row_sd_values = []

        # iterate the row names directly
        row_names = row_scores.row_names
        for col in xrange(row_scores.num_columns):
            cluster_rows = membership.rows_for_cluster(col + 1)
            for row in xrange(row_scores.num_rows):
                if row_names[row] in cluster_rows:
                    row_sd_values.append(row_score_values[row, col])

        # Note: If there are no non-NaN values in row_sd_values, row_rnorm
        # will have all NaNs
        row_rnorm = util.sd_rnorm(row_sd_values, num_row_fuzzy_values,
                                  fuzzy_coeff)
        row_score_values += np.array(row_rnorm).reshape(
            row_scores.num_rows, row_scores.num_columns)

    if fuzz_cols:
        num_col_fuzzy_values = column_scores.num_rows * column_scores.num_columns
        col_score_values = column_scores.values
        col_sd_values = []
        row_names = column_scores.row_names
        for col in xrange(column_scores.num_columns):
            cluster_cols = membership.columns_for_cluster(col + 1)
            for row in xrange(column_scores.num_rows):
                if row_names[row] in cluster_cols:
                    col_sd_values.append(col_score_values[row, col])

        # Note: If there are no non-NaN values in col_sd_values, col_rnorm
        # will have all NaNs
        col_rnorm = util.sd_rnorm(col_sd_values, num_col_fuzzy_values,
                                  fuzzy_coeff)
        # add fuzzy values to the row/column scores
        col_score_values += np.array(col_rnorm).reshape(
            column_scores.num_rows, column_scores.num_columns)

    #elapsed = util.current_millis() - start_time
    #logging.debug("fuzzify() finished in %f s.", elapsed / 1000.0)
    return row_scores, column_scores
Ejemplo n.º 4
0
 def test_sd_rnorm(self):
     result = util.sd_rnorm([1.3, 1.6, 1.2, 1.05], 9, 0.748951)
     # the results are fairly random, make sure we have the right
     # number of values
     self.assertEquals(9, len(result))