Exemplo n.º 1
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)
Exemplo n.º 2
0
def span(categorized_vec):
    having_nodata_vecs = collections.deque([categorized_vec])
    possible_vecs = []
    while having_nodata_vecs:
        top_vec = having_nodata_vecs.pop()
        if not common.is_certain(top_vec):
            zerovec, onevec = remove_leftmost_nodata(top_vec)
            having_nodata_vecs.appendleft(zerovec)
            having_nodata_vecs.appendleft(onevec)
        else:
            possible_vecs.append(top_vec)
    return possible_vecs
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)