Example #1
0
def get_encoded_codes(fullset):
    result = []
    for row in fullset:
        disaster_prob_vec = row[:common.N_DISASTER]
        categorized_vec = common.categorize(disaster_prob_vec, 0.4, 0.6)
        result.append('"' + ''.join(map(str, categorized_vec)) + '"')
    return result
Example #2
0
def get_clust_samples(fullset):
    result = []
    for row in fullset:
        disaster_prob_vec = row[:common.N_DISASTER]
        categorized_vec = common.categorize(disaster_prob_vec, 0.4, 0.6)
        if common.is_certain(categorized_vec) and sum(categorized_vec) != 0:
            result.append(categorized_vec)
    return np.array(result)
Example #3
0
def check_and_decide(disaster_prob_vec, probs):
    categorized_vec = common.categorize(disaster_prob_vec,
                                        0.4,
                                        0.6,
                                        nodata_to_uncertain=True)
    possible_vecs = span(np.array(categorized_vec))
    possible_labels = list(map(common.classify, possible_vecs))
    decrease_idx = np.argsort(-np.array(probs))
    for i, idx in enumerate(decrease_idx):
        if idx in possible_labels:
            return idx, i
    print('error')
Example #4
0
def get_uncertain_count_map(fullset):
    result = []
    for row in fullset:
        disaster_prob_vec = row[:common.N_DISASTER]
        feature_vec = row[common.N_DISASTER:]

        categorized_vec = np.array(common.categorize(disaster_prob_vec, 0.4, 0.6))

        if np.count_nonzero(categorized_vec == 9) == 5:
            result.append(-99)
        else:
            result.append(np.count_nonzero(np.logical_or(categorized_vec == 1, categorized_vec == 0)))
    return np.array(result)
Example #5
0
def get_codes(fullset):
    results = []
    for i, row in enumerate(fullset):
        disaster_prob_vec = row[:common.N_DISASTER]
        feature_vec = row[common.N_DISASTER:]

        categorized_vec = common.categorize(disaster_prob_vec, 0.4, 0.6)
        if common.is_certain(categorized_vec):
            label = common.classify(categorized_vec)
            results.append(label)
        elif -99 in feature_vec:
            results.append(-99)
        else:
            results.append(common.N_CLASS)

    return np.array(results)
Example #6
0
def get_types(fullset):
    results = []
    for row in fullset:
        disaster_prob_vec = row[:common.N_DISASTER]
        feature_vec = row[common.N_DISASTER:]

        categorized_vec = common.categorize(disaster_prob_vec, 0.4, 0.6)
        if common.is_certain(categorized_vec):
            label = common.classify(categorized_vec)
            results.append(label)
        elif -99 in feature_vec:
            results.append(-99)
        else:
            results.append(UNCERTAIN_LABEL)

    return np.array(results)
Example #7
0
def get_trainset(fullset, upward=False, with_id=False):
    result = []

    if upward:
        fullset = np.flipud(fullset.reshape(common.N_ROWS, common.N_COLS, -1)).reshape(-1, fullset.shape[-1])

    for row in fullset:
        disaster_prob_vec = row[:common.N_DISASTER]
        feature_vec = row[common.N_DISASTER:]

        categorized_vec = common.categorize(disaster_prob_vec, 0.4, 0.6)

        if common.is_certain(categorized_vec) and -99 not in feature_vec:
            label = common.classify(categorized_vec)
            result.append(feature_vec.tolist() + [label])

    if with_id:
        return np.concatenate((np.arange(len(result))[:, np.newaxis], result), axis=1)
    else:
        return np.array(result)