Example #1
0
def prepare_dataset(dataset_file, dataset_name, type):
    dataset = pd.read_csv(resource_path + dataset_file, index_col=False)
    for column in dataset.columns[0:-1]:
        if column == "POCT":
            triangular_set = fl.TriangularSet(constant.POCT_MIN,
                                              constant.POCT_MEAN,
                                              constant.POCT_MAX)
            dataset[column] = triangular_set(np.array(dataset[column]))
        elif column == "IGA_totali":
            triangular_set = fl.TriangularSet(constant.MIN_IGA,
                                              constant.MEAN_IGA,
                                              constant.MAX_IGA)
            dataset[column] = triangular_set(np.array(dataset[column]))
        elif column == "TTG_IGG":
            triangular_set = fl.TriangularSet(constant.TTG_IGG_MIN,
                                              constant.TTG_IGG_MEAN,
                                              constant.TTG_IGG_MAX)
            dataset[column] = triangular_set(np.array(dataset[column]))
        elif column == "TTG_IGA":
            triangular_set = fl.TriangularSet(constant.TTG_IGA_MIN,
                                              constant.TTG_IGA_MEAN,
                                              constant.TTG_IGA_MAX)
            dataset[column] = triangular_set(np.array(dataset[column]))
    if type == ETHALONS:
        dataset.to_csv(neuro_networks_path + "ethalons_" + dataset_name +
                       ".csv",
                       index=False)
    elif type == CANDIDATES:
        dataset.to_csv(neuro_networks_path + "candidates_" + dataset_name +
                       ".csv",
                       index=False)
def default_fuzzifier(idx, F):
    # get min/max from data
    v_min = np.nanmin(F)
    v_max = np.nanmax(F)
    # blarg
    return [ Leaf(idx, "low", fl.TriangularSet(v_min - (v_max - v_min) ** 2, v_min, v_max)),
             Leaf(idx, "med", fl.TriangularSet(v_min, v_min + ((v_max - v_min) / 2), v_max)),
             Leaf(idx, "hig", fl.TriangularSet(v_min, v_max, v_max + (v_max - v_min) ** 2)) ]
Example #3
0
def default_fuzzifier(idx, F):
    """Default fuzzifier function.

    Creates three fuzzy sets with triangular membership functions: (low, med, hig) from min and max data points.
    """
    # get min/max from data
    v_min = np.nanmin(F)
    v_max = np.nanmax(F)
    # blarg
    return [
        Leaf(idx, "low",
             fl.TriangularSet(v_min - (v_max - v_min)**2, v_min, v_max)),
        Leaf(idx, "med",
             fl.TriangularSet(v_min, v_min + ((v_max - v_min) / 2), v_max)),
        Leaf(idx, "hig",
             fl.TriangularSet(v_min, v_max, v_max + (v_max - v_min)**2))
    ]
Example #4
0
def fuzzify_mean(A):
    # output for fuzzified values
    R = np.zeros((A.shape[0], A.shape[1] * 3))

    cmin, cmax, cmean = np.nanmin(A, 0), np.nanmax(A, 0), np.nanmean(A, 0)
        
    left = np.array([cmin - (cmax - cmin), cmin, cmax]).T
    middle = np.array([cmin, cmean, cmax]).T
    right = np.array([cmin, cmax, cmax + (cmax - cmin)]).T

    mus = []

    for i in range(A.shape[1]):
        f_l = fl.TriangularSet(*left[i])
        f_m = fl.TriangularSet(*middle[i])
        f_r = fl.TriangularSet(*right[i])
        R[:,(i*3)] = f_l(A[:,i])
        R[:,(i*3)+1] = f_m(A[:,i])
        R[:,(i*3)+2] = f_r(A[:,i])
        mus.extend([(i, f_l), (i, f_m), (i, f_r)])

    return 3, R, mus
Example #5
0
    def fuzzify_p(A):
        R = np.zeros((A.shape[0], A.shape[1] * p))

        cmin, cmax = np.nanmin(A, 0), np.nanmax(A, 0)
        psize = (cmax - cmin) / (p - 1)

        mus = []
        # iterate features
        for i in range(A.shape[1]):
            # iterate partitions
            mu_i = []
            offset = cmin[i]
            for j in range(p):
                f = fl.TriangularSet(offset - psize[i], offset, offset + psize[i])
                R[:, (i * p) + j] = f(A[:, i])
                mu_i.append(f)
                offset += psize[i]
            mus.append(mu_i)
        return p, R, mus
Example #6
0
def build_t_membership(chromosome, idx):
    a, b, c = sorted(chromosome[idx:idx + 3])
    return fl.TriangularSet(a, b, c)
Example #7
0
def t_factory(**k):
    return fl.TriangularSet(k["min"], k["mean"], k["max"])
Example #8
0
def triangular_factory(*args):
    return fl.TriangularSet(args[0], args[1], args[2])