コード例 #1
0
def rodar(patterns, metodos, radical, sinais, occupancy, lock):
    u = Utiliters()
    info = u.setup_logger('information', radical + 'info.log')
    startedI = datetime.datetime.now()
    print('Started Nu Test with occupancy %d at %s' % (occupancy, startedI.strftime("%H:%M:%S %d/%m/%Y")))
    info.info('Started Nu Test with occupancy %d' % occupancy)
    algo = Algorithms()
    matrizes = Matrizes()
    matrix = matrizes.matrix()
    samples = 1820
    iterations = 331

    for pattern in patterns:
        nome = radical + pattern + '_' + str(occupancy)
        bunch = pattern.rsplit('b', 1)
        empty = bunch[1].rsplit('e', 1)
        b = int(bunch[0])
        e = int(empty[0])
        halfA = e - int(math.ceil(e / 2))
        fillAd = np.zeros(halfA)
        fillAe = np.zeros(e - halfA)
        try:
            signalT = np.genfromtxt(sinais + 'signalT_' + pattern + '_' + str(occupancy) + '.csv', delimiter=',')
            signalN = np.genfromtxt(sinais + 'signalN_' + pattern + '_' + str(occupancy) + '.csv', delimiter=',')
        except:
            print('Error get saved signals')
            signalT, signalN, signalTf, signalNf = u.sgen(pattern, samples, b, fillAd, fillAe, matrix, sinais)

        const = {'iterations': iterations, 'occupancy': occupancy, 'pattern': pattern, 'signalT': signalT,
                 'signalN': signalN}

        itens = np.arange(0)
        constantes = {}
        for i in range(1, 101):
            for j in range(1, 101):
                if i != j:
                    aux = float('%.6g' % (i / j))
                    if not (aux in itens):
                        itens = np.append(itens, aux)
                        constantes.update({aux: str(i) + '#' + str(j)})

        colunas = ['Nu', 'i', 'j']
        for metodo in metodos:
            colunas.append(metodo + ':' + str(occupancy) + ':RMS')
        data = panda.DataFrame([], columns=colunas)
        for nu in itens:
            opt = {'nu': nu, 'mi': .25}
            row = [nu]
            row.extend(constantes.get(nu).split('#'))
            for metodo in metodos:
                const['metodo'] = metodo
                row.append(algo.getRMSfloat(const, opt)['rms'])
            l = len(data)
            data.loc[l] = row
            with lock:
                data.to_csv(nome + '.csv', index=False)
    ended = datetime.datetime.now()
    print('Ended Nu Test with occupancy %d at  %s after %s' % (
        occupancy, ended.strftime("%H:%M:%S %d/%m/%Y"), u.totalTime(startedI)))
    info.info('Ended Nu Test with occupancy %d after %s' % (occupancy, u.totalTime(startedI)))
コード例 #2
0
def rodar(patterns, metodos, conf, radical, sinais, occupancy, lock):
    u = Utiliters()
    info = u.setup_logger('information', radical + 'info.log')
    startedI = datetime.datetime.now()
    print('Started Lambda Test with occupancy %d at %s' %
          (occupancy, startedI.strftime("%H:%M:%S %d/%m/%Y")))
    info.info('Started Lambda Test with occupancy %d' % occupancy)
    algo = Algorithms()
    matrizes = Matrizes()
    matrix = matrizes.matrix()
    samples = 1820
    iterations = conf['iterations']

    for pattern in patterns:
        nome = radical + pattern + '_' + str(occupancy)
        bunch = pattern.rsplit('b', 1)
        empty = bunch[1].rsplit('e', 1)
        b = int(bunch[0])
        e = int(empty[0])
        halfA = e - int(math.ceil(e / 2))
        fillAd = np.zeros(halfA)
        fillAe = np.zeros(e - halfA)
        try:
            signalT = np.genfromtxt(sinais + 'signalT_' + pattern + '_' +
                                    str(occupancy) + '.csv',
                                    delimiter=',')
            signalN = np.genfromtxt(sinais + 'signalN_' + pattern + '_' +
                                    str(occupancy) + '.csv',
                                    delimiter=',')
        except:
            print('Error get saved signals')
            signalT, signalN, signalTf, signalNf = u.sgen(
                pattern, samples, b, fillAd, fillAe, matrix, sinais)

        const = {
            'iterations': iterations,
            'occupancy': occupancy,
            'pattern': pattern,
            'signalT': signalT,
            'signalN': signalN
        }

        colunas = ['Lambda']
        for metodo in metodos:
            for ite in range(1, iterations):
                colunas.append(metodo + ':' + str(occupancy) + ':RMS:' +
                               str(ite))

        data = panda.DataFrame([], columns=colunas)
        for lam in range(conf['sL'], conf['eL']):
            if lam != 0:
                lamb = lam / 10
            else:
                lamb = 0
            opt = {'lambda': lamb}
            row = [lamb]
            for metodo in metodos:
                const['metodo'] = metodo
                for ite in range(1, iterations):
                    const['iterations'] = ite
                    row.append(algo.getRMSfloat(const, opt)['rms'])
            l = len(data)
            data.loc[l] = row
            with lock:
                data.to_csv(nome + '.csv', index=False)
    ended = datetime.datetime.now()
    print('Ended Lambda Test with occupancy %d at  %s after %s' %
          (occupancy, ended.strftime("%H:%M:%S %d/%m/%Y"),
           u.totalTime(startedI)))
    info.info('Ended Lambda Test with occupancy %d after %s' %
              (occupancy, u.totalTime(startedI)))
コード例 #3
0
def rodar(patterns, radical, sinais, occupancy, lock, metodos, load=None):
    u = Utiliters()
    info = u.setup_logger('information', radical + 'info.log')
    startedI = datetime.now()
    print('Started ROC generate for occupancy %d at  %s' %
          (occupancy, startedI.strftime("%H:%M:%S %d/%m/%Y")))
    info.info('Started ROC generate for occupancy %d' % (occupancy))
    algo = Algorithms()
    gerador = Signal()
    matrizes = Matrizes()
    matrix = matrizes.matrix()
    samples = 1820

    for pattern in patterns:
        if load is None:
            data = panda.DataFrame([])
            nome = radical + pattern + '_' + str(occupancy) + '.csv'
        else:
            nome = load + pattern + '_' + str(occupancy) + '.csv'
            data = panda.read_csv(nome)

        bunch = pattern.rsplit('b', 1)
        empty = bunch[1].rsplit('e', 1)
        b = int(bunch[0])
        e = int(empty[0])
        bwindow = b + 6
        window = b + e
        halfA = e - int(math.ceil(e / 2))
        halfCd = int(math.ceil((bwindow - window) / 2))
        halfCe = int(bwindow - window - halfCd)
        if halfCd > 0:
            fillCd = np.zeros(halfCd)
        else:
            fillCd = np.arange(0)
        if halfCe > 0:
            fillCe = np.zeros(halfCe)
        else:
            fillCe = np.arange(0)
        fillAd = np.zeros(halfA)
        fillAe = np.zeros(e - halfA)
        fill = [fillAd, fillAe, fillCd, fillCe]
        H, A, B = matrizes.generate(b)
        h = matrix[0:7, 5]
        try:
            signalT = np.genfromtxt(sinais + 'signalT_' + pattern + '_' +
                                    str(occupancy) + '.csv',
                                    delimiter=',')
            signalN = np.genfromtxt(sinais + 'signalN_' + pattern + '_' +
                                    str(occupancy) + '.csv',
                                    delimiter=',')
            signalTf = np.genfromtxt(sinais + 'fir/signalT_' + pattern + '_' +
                                     str(occupancy) + '.csv',
                                     delimiter=',')
            signalNf = np.genfromtxt(sinais + 'fir/signalN_' + pattern + '_' +
                                     str(occupancy) + '.csv',
                                     delimiter=',')
        except:
            print('Error get saved signals')
            signalT, signalN, signalTf, signalNf = u.sgen(
                pattern, samples, b, fillAd, fillAe, matrix, sinais)
        const = {
            'iterations': 331,
            'occupancy': occupancy,
            'pattern': pattern,
            'signalT': signalT,
            'signalN': signalN
        }
        opt = {'samples': samples}
        nnzST = np.count_nonzero(signalT)
        nzST = len(signalT) - nnzST
        pike = int(np.max(signalN) + 1)

        if ('FDIP' in metodos) or ('MF' in metodos):
            started = datetime.now()
            print('Started ROC generate for old with occupancy %d at  %s' %
                  (occupancy, started.strftime("%H:%M:%S %d/%m/%Y")))
            info.info('Started ROC generate for old with occupancy %d' %
                      (occupancy))
            metodo = 'FDIP'
            if metodo in metodos:
                const['metodo'] = metodo
                constf = const
                constf['signalNf'] = signalNf
                constf['signalTf'] = signalTf
                roc = gerador.roc(algo.getRMSfloat(constf)['signal'], signalT)
                roc = roc.rename(
                    columns={
                        s: metodo + ':' + str(occupancy) + ':' + s
                        for s in list(roc.columns.values)
                    })
                data = panda.concat([data, roc], axis=1, sort=False)
                with lock:
                    data.to_csv(nome, index=False)

            metodo = 'MF'
            if metodo in metodos:
                signalMf, roc = algo.MatchedFw_roc(signalN, h, samples, b, e,
                                                   fill, signalT)
                roc = roc.rename(
                    columns={
                        s: 'MF:' + str(occupancy) + ':' + s
                        for s in list(roc.columns.values)
                    })
                data = panda.concat([data, roc], axis=1, sort=False)
                with lock:
                    data.to_csv(nome, index=False)

            ended = datetime.now()
            print(
                'Ended ROC generate for old with occupancy %d at  %s after %s'
                % (occupancy, ended.strftime("%H:%M:%S %d/%m/%Y"),
                   u.totalTime(started)))
            info.info('Ended ROC generate for old with occupancy %d after %s' %
                      (occupancy, u.totalTime(started)))

        if (' MF ' in metodos) or ('OMP ' in metodos) or ('LS-OMP' in metodos):
            started = datetime.now()
            print('Started ROC generate for Greedy with occupancy %d at  %s' %
                  (occupancy, started.strftime("%H:%M:%S %d/%m/%Y")))
            info.info('Started ROC generate for Greedy with occupancy %d' %
                      (occupancy))

            metodo = ' MP '
            if metodo in metodos:
                threshold, pdr, far = 0, 5, 5
                res = []
                while (float('{:.2f}'.format(pdr)) > 0.01) or (float(
                        '{:.2f}'.format(far)) > 0.01):
                    faA, pdA = 0, 0
                    signalA = np.zeros(window * samples)
                    for i in range(samples):
                        step = (i * window)
                        paso = step + window
                        if (e > 6):
                            paso = paso - (e - 6)
                        signalTw = np.concatenate(
                            (fillCd, signalT[step:paso], fillCe))
                        signalSw = np.concatenate(
                            (fillCd, signalN[step:paso], fillCe))

                        step += halfA
                        paso = step + b

                        x, fa, pd = algo.MP_roc(threshold, signalSw, signalTw,
                                                b, H)
                        signalA[step:paso] = x
                        faA += fa
                        pdA += pd
                    far = (faA / nzST)
                    pdr = (pdA / nnzST)
                    tmp = '%d,%.6f,%.6f,%.6f' % (
                        threshold, gerador.rms(signalA - signalT), far, pdr)
                    if threshold < pike:
                        threshold += 1
                    else:
                        if threshold == pike:
                            threshold = math.ceil(pike / 100) * 100
                        else:
                            threshold += 100
                    res.append([float(s) for s in tmp.split(',')])
                roc = panda.DataFrame(
                    res,
                    columns=[
                        'MP:' + str(occupancy) + ':threshold',
                        'MP:' + str(occupancy) + ':RMS',
                        'MP:' + str(occupancy) + ':FA',
                        'MP:' + str(occupancy) + ':DP'
                    ])

                data = panda.concat([data, roc], axis=1, sort=False)
                with lock:
                    data.to_csv(nome, index=False)

            metodo = 'OMP '
            if metodo in metodos:
                threshold, pdr, far = 0, 5, 5
                res = []
                while (float('{:.2f}'.format(pdr)) > 0.01) or (float(
                        '{:.2f}'.format(far)) > 0.01):
                    faA, pdA = 0, 0
                    signalA = np.zeros(window * samples)
                    for i in range(samples):
                        step = (i * window)
                        paso = step + window
                        if (e > 6):
                            paso = paso - (e - 6)
                        signalTw = np.concatenate(
                            (fillCd, signalT[step:paso], fillCe))
                        signalSw = np.concatenate(
                            (fillCd, signalN[step:paso], fillCe))

                        step += halfA
                        paso = step + b

                        x, fa, pd = algo.OMP_roc(threshold, signalSw, signalTw,
                                                 b, H)
                        signalA[step:paso] = x
                        faA += fa
                        pdA += pd
                    far = (faA / nzST)
                    pdr = (pdA / nnzST)
                    tmp = '%d,%.6f,%.6f,%.6f' % (
                        threshold, gerador.rms(signalA - signalT), far, pdr)
                    if (threshold < pike):
                        threshold += 1
                    else:
                        if threshold == pike:
                            threshold = math.ceil(pike / 100) * 100
                        else:
                            threshold += 100
                    res.append([float(s) for s in tmp.split(',')])
                roc = panda.DataFrame(
                    res,
                    columns=[
                        'OMP:' + str(occupancy) + ':threshold',
                        'OMP:' + str(occupancy) + ':RMS',
                        'OMP:' + str(occupancy) + ':FA',
                        'OMP:' + str(occupancy) + ':DP'
                    ])

                data = panda.concat([data, roc], axis=1, sort=False)
                with lock:
                    data.to_csv(nome, index=False)

            metodo = 'LS-OMP'
            if metodo in metodos:
                threshold, pdr, far = 0, 5, 5
                res = []
                while (float('{:.2f}'.format(pdr)) > 0.01) or (float(
                        '{:.2f}'.format(far)) > 0.01):
                    faA, pdA = 0, 0
                    signalA = np.zeros(window * samples)
                    for i in range(samples):
                        step = (i * window)
                        paso = step + window
                        if (e > 6):
                            paso = paso - (e - 6)
                        signalTw = np.concatenate(
                            (fillCd, signalT[step:paso], fillCe))
                        signalSw = np.concatenate(
                            (fillCd, signalN[step:paso], fillCe))

                        step += halfA
                        paso = step + b

                        x, fa, pd = algo.LS_OMP_roc(threshold, signalSw,
                                                    signalTw, b, H)
                        signalA[step:paso] = x
                        faA += fa
                        pdA += pd
                    far = (faA / nzST)
                    pdr = (pdA / nnzST)
                    tmp = '%d,%.6f,%.6f,%.6f' % (
                        threshold, gerador.rms(signalA - signalT), far, pdr)
                    if (threshold < pike):
                        threshold += 1
                    else:
                        if threshold == pike:
                            threshold = math.ceil(pike / 100) * 100
                        else:
                            threshold += 100
                    res.append([float(s) for s in tmp.split(',')])
                roc = panda.DataFrame(
                    res,
                    columns=[
                        'LS-OMP:' + str(occupancy) + ':threshold',
                        'LS-OMP:' + str(occupancy) + ':RMS',
                        'LS-OMP:' + str(occupancy) + ':FA',
                        'LS-OMP:' + str(occupancy) + ':DP'
                    ])
                data = panda.concat([data, roc], axis=1, sort=False)
                with lock:
                    data.to_csv(nome, index=False)

            ended = datetime.now()
            print(
                'Ended ROC generate for Greedy with occupancy %d at  %s after %s'
                % (occupancy, ended.strftime("%H:%M:%S %d/%m/%Y"),
                   u.totalTime(started)))
            info.info(
                'Ended ROC generate for Greedy with occupancy %d after %s' %
                (occupancy, u.totalTime(started)))

        started = datetime.now()
        print('Started ROC generate for Shrinkage with occupancy %d at  %s' %
              (occupancy, started.strftime("%H:%M:%S %d/%m/%Y")))
        info.info('Started ROC generate for Shrinkage with occupancy %d' %
                  (occupancy))

        metodo = 'DS'
        if metodo in metodos:
            const['metodo'] = metodo
            roc = gerador.roc(algo.getRMSfloat(const, opt)['signal'], signalT)
            roc = roc.rename(
                columns={
                    s: metodo + ':' + str(occupancy) + ':' + s
                    for s in list(roc.columns.values)
                })
            data = panda.concat([data, roc], axis=1, sort=False)
            with lock:
                data.to_csv(nome, index=False)

        metodo = 'GD '
        if metodo in metodos:
            metodo = metodo.strip()
            const['metodo'] = metodo
            roc = gerador.roc(algo.getRMSfloat(const, opt)['signal'], signalT)
            roc = roc.rename(
                columns={
                    s: metodo + ':' + str(occupancy) + ':' + s
                    for s in list(roc.columns.values)
                })
            data = panda.concat([data, roc], axis=1, sort=False)
            with lock:
                data.to_csv(nome, index=False)

        metodo = 'GDi'
        if metodo in metodos:
            metodo = metodo.strip()
            const['metodo'] = metodo
            roc = gerador.roc(algo.getRMSfloat(const, opt)['signal'], signalT)
            roc = roc.rename(
                columns={
                    s: metodo + ':' + str(occupancy) + ':' + s
                    for s in list(roc.columns.values)
                })
            data = panda.concat([data, roc], axis=1, sort=False)
            with lock:
                data.to_csv(nome, index=False)

        metodo = 'SSF '
        if metodo in metodos:
            metodo = metodo.strip()
            const['metodo'] = metodo
            opt['mi'] = .25
            roc = gerador.roc(algo.getRMSfloat(const, opt)['signal'], signalT)
            roc = roc.rename(
                columns={
                    s: metodo + ':' + str(occupancy) + ':' + s
                    for s in list(roc.columns.values)
                })
            data = panda.concat([data, roc], axis=1, sort=False)
            with lock:
                data.to_csv(nome, index=False)

        metodo = 'SSFi'
        if metodo in metodos:
            metodo = metodo.strip()
            const['metodo'] = metodo
            opt['mi'] = .25
            roc = gerador.roc(algo.getRMSfloat(const, opt)['signal'], signalT)
            roc = roc.rename(
                columns={
                    s: metodo + ':' + str(occupancy) + ':' + s
                    for s in list(roc.columns.values)
                })
            data = panda.concat([data, roc], axis=1, sort=False)
            with lock:
                data.to_csv(nome, index=False)

        metodo = 'SSFls '
        if metodo in metodos:
            metodo = metodo.strip()
            const['metodo'] = metodo
            opt['mi'] = .25
            roc = gerador.roc(algo.getRMSfloat(const, opt)['signal'], signalT)
            roc = roc.rename(
                columns={
                    s: metodo + ':' + str(occupancy) + ':' + s
                    for s in list(roc.columns.values)
                })
            data = panda.concat([data, roc], axis=1, sort=False)
            with lock:
                data.to_csv(nome, index=False)

        metodo = 'SSFlsi'
        if metodo in metodos:
            metodo = metodo.strip()
            const['metodo'] = metodo
            opt['mi'] = .25
            roc = gerador.roc(algo.getRMSfloat(const, opt)['signal'], signalT)
            roc = roc.rename(
                columns={
                    s: metodo + ':' + str(occupancy) + ':' + s
                    for s in list(roc.columns.values)
                })
            data = panda.concat([data, roc], axis=1, sort=False)
            with lock:
                data.to_csv(nome, index=False)

        metodo = 'SSFlsc '
        if metodo in metodos:
            metodo = metodo.strip()
            const['metodo'] = metodo
            opt['mi'] = .25
            roc = gerador.roc(algo.getRMSfloat(const, opt)['signal'], signalT)
            roc = roc.rename(
                columns={
                    s: metodo + ':' + str(occupancy) + ':' + s
                    for s in list(roc.columns.values)
                })
            data = panda.concat([data, roc], axis=1, sort=False)
            with lock:
                data.to_csv(nome, index=False)

        metodo = 'SSFlsci'
        if metodo in metodos:
            metodo = metodo.strip()
            const['metodo'] = metodo
            opt['mi'] = .25
            roc = gerador.roc(algo.getRMSfloat(const, opt)['signal'], signalT)
            roc = roc.rename(
                columns={
                    s: metodo + ':' + str(occupancy) + ':' + s
                    for s in list(roc.columns.values)
                })
            data = panda.concat([data, roc], axis=1, sort=False)
            with lock:
                data.to_csv(nome, index=False)

        metodo = 'PCD '
        if metodo in metodos:
            metodo = metodo.strip()
            const['metodo'] = metodo
            opt['mi'] = math.inf
            roc = gerador.roc(algo.getRMSfloat(const, opt)['signal'], signalT)
            roc = roc.rename(
                columns={
                    s: metodo + ':' + str(occupancy) + ':' + s
                    for s in list(roc.columns.values)
                })
            data = panda.concat([data, roc], axis=1, sort=False)
            with lock:
                data.to_csv(nome, index=False)

        metodo = 'PCDi'
        if metodo in metodos:
            metodo = metodo.strip()
            const['metodo'] = metodo
            opt['mi'] = math.inf
            roc = gerador.roc(algo.getRMSfloat(const, opt)['signal'], signalT)
            roc = roc.rename(
                columns={
                    s: metodo + ':' + str(occupancy) + ':' + s
                    for s in list(roc.columns.values)
                })
            data = panda.concat([data, roc], axis=1, sort=False)
            with lock:
                data.to_csv(nome, index=False)

        ended = datetime.now()
        print(
            'Ended ROC generate for Shrinkage with occupancy %d at  %s after %s'
            % (occupancy, ended.strftime("%H:%M:%S %d/%m/%Y"),
               u.totalTime(started)))
        info.info(
            'Ended ROC generate for Shrinkage with occupancy %d after %s' %
            (occupancy, u.totalTime(started)))
    ended = datetime.now()
    print('Ended ROC generate for occupancy %d at  %s after %s' %
          (occupancy, ended.strftime("%H:%M:%S %d/%m/%Y"),
           u.totalTime(startedI)))
    info.info('Ended ROC generate for occupancy %d after %s' %
              (occupancy, u.totalTime(startedI)))
コード例 #4
0
def withoutInitial(const, radical, path, quantization, lock):
    u = Utiliters()
    occupancy = 30
    samples = 1820
    pattern = '48b7e'
    info = u.setup_logger('information', radical + 'info.log')
    startedI = datetime.datetime.now()
    print('Started Quantization Test, for quant %d at %s' % (quantization, startedI.strftime("%H:%M:%S %d/%m/%Y")))
    info.info('Started Quantization Test, for quant %d' % quantization)
    gerador = Signal()
    matrizes = Matrizes()
    verilog = XbYe()

    algov = verilog.getAlgo([pattern])
    bunch = pattern.rsplit('b', 1)
    empty = bunch[1].rsplit('e', 1)
    b = int(bunch[0])
    e = int(empty[0])
    u = Utiliters()
    bwindow = b + 6
    window = b + e
    halfA = e - int(math.ceil(e / 2))
    halfCd = int(math.ceil((bwindow - window) / 2))
    halfCe = int(bwindow - window - halfCd)
    fillAd = np.zeros(halfA)
    fillAe = np.zeros(e - halfA)
    if halfCd > 0:
        fillCd = np.zeros(halfCd)
    else:
        fillCd = np.arange(0)
    if halfCe > 0:
        fillCe = np.zeros(halfCe)
    else:
        fillCe = np.arange(0)
    matrix = matrizes.matrix()
    nome = radical + pattern + '_' + str(occupancy)

    bitsH = quantization
    bitsA = bitsH + 5
    align = bitsA
    mh, ma, mb = matrizes.generateFix(bitsH, bitsA)

    try:
        signalT = np.genfromtxt(path + 'signalT_' + pattern + '_' + str(occupancy) + '.csv', delimiter=',')
        signalN = np.genfromtxt(path + 'signalN_' + pattern + '_' + str(occupancy) + '.csv', delimiter=',')
    except:
        print('Error get saved signals')
        signalT, signalN, signalTf, signalNf = u.sgen(pattern, samples, b, fillAd, fillAe, matrix, path)

    for block in range(const['sB'], const['eB']):
        iterations = block * window
        for gain in range(const['sG'], const['eG']):
            bits = gain + 10
            signalA = np.zeros(window * samples)
            for ite in range(samples):
                step = (ite * window)
                paso = step + window
                if (e > 6):
                    paso = paso - (e - 6)
                signalS = np.concatenate((fillCd, signalN[step:paso], fillCe))
                step += halfA
                paso = step + b

                Hs, x = algov.sipo(signalS, gain, mh)
                x = algov.SSF([x, Hs, ma, iterations, bits, align, .25, 0])
                x = np.where(x < 0, 0, x)
                signalA[step:paso] = np.fix(np.divide(x, pow(2, gain)))
            rms = gerador.rms(signalA - signalT)

            with lock:
                with open(nome + '.csv', 'a') as file:
                    file.write(str(iterations) + u.s(quantization) + u.s(gain) + u.s(rms) + '\n')

    ended = datetime.datetime.now()
    print('Ended Quantization Test, for pseudoGain %d at %s after %s' % (
        quantization, ended.strftime("%H:%M:%S %d/%m/%Y"), u.totalTime(startedI)))
    info.info('Ended Quantization Test, for pseudoGain %d after %s' % (quantization, u.totalTime(startedI)))
コード例 #5
0
            plt.show()

    def graphViewer(self, methods, occupancies, kind):
        if 'ROC' in kind:
            self.graphROC(methods, occupancies, self.data)
        elif 'RMS' in kind:
            self.graphRMS(methods, occupancies, self.data)

def test(const, occupancy, lock):
    testSystem = TestSystem(const)
    testSystem.dataGenerate(occupancy, lock)
    return testSystem.data


if __name__ == '__main__':
    matrizes = Matrizes()
    util = Utiliters()
    pattern = '8b4e'
    totalSamples = 20
    bunch = pattern.rsplit('b', 1)
    empty = bunch[1].rsplit('e', 1)
    b = int(bunch[0])
    e = int(empty[0])
    bwindow = b + 6
    window = b + e
    halfA = e - int(math.ceil(e / 2))
    halfCd = int(math.ceil((bwindow - window) / 2))
    halfCe = int(bwindow - window - halfCd)
    fillAd = np.zeros(halfA)
    fillAe = np.zeros(e - halfA)
    if halfCd > 0:
コード例 #6
0
def rodar(patterns, metodos, radical, sinais, occupancy, lock):
    u = Utiliters()
    info = u.setup_logger('information', radical + 'info.log')
    startedI = datetime.datetime.now()
    print('Started Mi full Test with occupancy %d at %s' %
          (occupancy, startedI.strftime("%H:%M:%S %d/%m/%Y")))
    info.info('Started Mi full Test with occupancy %d' % occupancy)
    algo = Algorithms()
    matrizes = Matrizes()
    samples = 1820
    iterations = 331

    for pattern in patterns:
        nome = radical + pattern + '_' + str(occupancy)
        bunch = pattern.rsplit('b', 1)
        empty = bunch[1].rsplit('e', 1)
        b = int(bunch[0])
        e = int(empty[0])
        u = Utiliters()
        bwindow = b + 6
        window = b + e
        halfA = e - int(math.ceil(e / 2))
        halfCd = int(math.ceil((bwindow - window) / 2))
        halfCe = int(bwindow - window - halfCd)
        fillAd = np.zeros(halfA)
        fillAe = np.zeros(e - halfA)
        if halfCd > 0:
            fillCd = np.zeros(halfCd)
        else:
            fillCd = np.arange(0)
        if halfCe > 0:
            fillCe = np.zeros(halfCe)
        else:
            fillCe = np.arange(0)
        H, A, B = matrizes.generate(b)
        matrix = matrizes.matrix()
        try:
            signalN = np.genfromtxt(sinais + 'signalN_' + pattern + '_' +
                                    str(occupancy) + '.csv',
                                    delimiter=',')
        except:
            print('Error get saved signals')
            signalT, signalN, signalTf, signalNf = u.sgen(
                pattern, samples, b, fillAd, fillAe, matrix, sinais)

        colunas = ['Window']
        for metodo in metodos:
            for ite in range(1, iterations):
                colunas.append(metodo + ':' + str(occupancy) + ':mu:' +
                               str(ite))
        data = panda.DataFrame([], columns=colunas)

        for its in range(samples):
            step = (its * window)
            paso = step + window
            if (e > 6):
                paso = paso - (e - 6)
            signalS = np.concatenate((fillCd, signalN[step:paso], fillCe))
            step += halfA

            Hs = H.T.dot(signalS)
            row = [its]
            for metodo in metodos:
                musL = []
                for ite in range(1, iterations):
                    if 'i' in metodo:
                        x = B.dot(signalS)
                    else:
                        x = signalS[3:b + 3]
                    muA, mu = 0.0, 0.0
                    for i in range(ite):
                        if 'GDP' in metodo:
                            x, mu = algo.GDP(x, Hs, A, returnMu=True)
                        elif 'GD' in metodo:
                            x, mu = algo.GD(x, Hs, A, returnMu=True)
                        elif 'SSFlsc' in metodo:
                            x, mu = algo.SSFlsc(x, Hs, A, returnMu=True)
                        elif 'SSFls' in metodo:
                            x, mu = algo.SSFls(x, Hs, A, returnMu=True)
                        elif 'SSF' in metodo:
                            x, mu = algo.SSF(x, Hs, A, returnMu=True)
                        elif 'PCD' in metodo:
                            x, mu = algo.PCD(x, Hs, A, returnMu=True)
                        muA += mu
                    musL.append('%.6f' % (muA / ite))
                row.extend(musL)
            l = len(data)
            data.loc[l] = row
            with lock:
                data.to_csv(nome + '.csv', index=False)
    ended = datetime.datetime.now()
    print('Ended Mi full Test with occupancy %d at  %s after %s' %
          (occupancy, ended.strftime("%H:%M:%S %d/%m/%Y"),
           u.totalTime(startedI)))
    info.info('Ended Mi full Test with occupancy %d after %s' %
              (occupancy, u.totalTime(startedI)))
コード例 #7
0
    def getRMSfloat(self, const, opt=None):
        if opt is None:
            opt = {}
        gerador = Signal()
        util = Utiliters()
        matrizes = Matrizes()
        iterations = const['iterations']
        occupancy = const['occupancy']
        pattern = const['pattern']
        signalT = const['signalT']
        signalN = const['signalN']
        metodo = const['metodo']
        if 'FDIP' in metodo:
            try:
                if 'order' in opt:
                    order = opt['order']
                else:
                    order = 26
                signalA = self.FDIP(order, const['signalNf'],
                                    const['signalTf'], signalN)
                result = {
                    'rms': gerador.rms(signalA - signalT),
                    'signal': signalA
                }
                return result
            except:
                return None

        if 'lambda' in opt:
            lamb = opt['lambda']
        else:
            lamb = 0
        if 'mi' in opt:
            mi = opt['mi']
        else:
            mi = math.inf
        if 'samples' in opt:
            samples = opt['samples']
        else:
            samples = 1820
        bunch = pattern.rsplit('b', 1)
        empty = bunch[1].rsplit('e', 1)
        b = int(bunch[0])
        e = int(empty[0])
        bwindow = b + 6
        window = b + e
        halfA = e - int(math.ceil(e / 2))
        halfCd = int(math.ceil((bwindow - window) / 2))
        halfCe = int(bwindow - window - halfCd)
        if halfCd > 0:
            fillCd = np.zeros(halfCd)
        else:
            fillCd = np.arange(0)
        if halfCe > 0:
            fillCe = np.zeros(halfCe)
        else:
            fillCe = np.arange(0)
        if 'maxB' in opt:
            maxB = opt['maxB']
        else:
            maxB = None
        H, A, B = matrizes.generate(b, maxB)
        if 'DS' in metodo:
            AA = np.vstack((np.hstack(
                (A, np.negative(A))), np.hstack((np.negative(A), A))))
            uns = np.ones(b)

        if 'MF' in metodo:
            fillAd = np.zeros(halfA)
            fillAe = np.zeros(e - halfA)
            fill = [fillAd, fillAe, fillCd, fillCe]
            matrix = matrizes.matrix()
            h = matrix[0:7, 5]
            if 'threshold' in opt:
                threshold = opt['threshold']
            else:
                threshold = util.getBestThreshold(metodo, occupancy)
            signalA = self.MatchedFw(signalN, h, threshold, samples, b, e,
                                     fill)
            result = {'rms': gerador.rms(signalA - signalT), 'signal': signalA}
            return result

        if 'constPCD' in opt:
            constPCD = opt['constPCD']
        else:
            constPCD = util.getPcdConst(A)
        if 'nu' in opt:
            nu = opt['nu']
        else:
            nu = util.getNuConst(occupancy)
        signalA = np.zeros(window * samples)
        for ite in range(samples):
            step = (ite * window)
            paso = step + window
            if (e > 6):
                paso = paso - (e - 6)
            signalS = np.concatenate((fillCd, signalN[step:paso], fillCe))
            step += halfA
            paso = step + b
            if 'DS' in metodo:
                signalA[step:paso] = self.DantzigSelec(signalS, b, H, AA, uns)
                continue

            if 'LS-OMP' in metodo:
                if 'threshold' in opt:
                    threshold = opt['threshold']
                else:
                    threshold = util.getBestThreshold(metodo, occupancy)
                signalA[step:paso] = self.LS_OMP(threshold, signalS, b, H)
                continue

            if 'OMP' in metodo:
                if 'threshold' in opt:
                    threshold = opt['threshold']
                else:
                    threshold = util.getBestThreshold(metodo, occupancy)
                signalA[step:paso] = self.OMP(threshold, signalS, b, H)
                continue

            if 'MP' in metodo:
                if 'threshold' in opt:
                    threshold = opt['threshold']
                else:
                    threshold = util.getBestThreshold(metodo, occupancy)
                signalA[step:paso] = self.MP(threshold, signalS, b, H)
                continue

            Hs = H.T.dot(signalS)

            if 'i' in metodo:
                x = B.dot(signalS)
            else:
                x = signalS[3:b + 3]
            for i in range(iterations):
                if 'GDP' in metodo:
                    x = self.GDP(x, Hs, A, mi)
                elif 'GD' in metodo:
                    x = self.GD(x, Hs, A, mi)
                elif 'SSFlsc' in metodo:
                    x = self.SSFlsc(x, Hs, A, mi, lamb, nu)
                elif 'SSFls' in metodo:
                    x = self.SSFls(x, Hs, A, mi, lamb, constPCD)
                elif 'SSF' in metodo:
                    x = self.SSF(x, Hs, A, mi, lamb)
                elif 'PCD' in metodo:
                    x = self.PCD(x, Hs, A, mi, lamb, constPCD)
            x = np.where(x < 0, 0, x)
            signalA[step:paso] = x
        result = {
            'rms': '%.6g' % gerador.rms(signalA - signalT),
            'signal': signalA
        }
        return result
コード例 #8
0
window = b + e
halfA = e - int(math.ceil(e / 2))
halfCd = int(math.ceil((bwindow - window) / 2))
halfCe = int(bwindow - window - halfCd)
fillAd = np.zeros(halfA)
fillAe = np.zeros(e - halfA)
if halfCd > 0:
    fillCd = np.zeros(halfCd)
else:
    fillCd = np.arange(0)
if halfCe > 0:
    fillCe = np.zeros(halfCe)
else:
    fillCe = np.arange(0)

matrizes = Matrizes()
matrix = matrizes.matrix()
gerador = Signal()
occupancies = [1, 5, 10, 20, 30, 40, 50, 60, 90]
path = './../tests/signals/training/'

# Generate 10 different signals
# for occupancy in occupancies:
#     rmsA = 0.0
#     rms = 0.0
#     signalT = signalTa = np.genfromtxt('./../tests/signals/signalT_' + pattern + '_' + str(occupancy) + '.csv', delimiter=',')
#     signalN = signalNa = np.genfromtxt('./../tests/signals/signalN_' + pattern + '_' + str(occupancy) + '.csv', delimiter=',')
#     for i in range(10):
#         sleep(random() * 10)
#         while rmsA == rms:
#             signalT, signalN = gerador.signalGenerator(samples, b, fillAd, fillAe, matrix, occupancy=occupancy)
コード例 #9
0
def rodar(patterns, metodos, radical, sinais, occupancy, lock):
    u = Utiliters()
    info = u.setup_logger('information', radical + 'info.log')
    startedI = datetime.datetime.now()
    print('Started B Fator Test with occupancy %d at %s' %
          (occupancy, startedI.strftime("%H:%M:%S %d/%m/%Y")))
    info.info('Started B Fator Test with occupancy %d' % occupancy)
    algo = Algorithms()
    matrizes = Matrizes()
    matrix = matrizes.matrix()
    samples = 1820
    iterations = 331

    for pattern in patterns:
        nome = radical + pattern + '_' + str(occupancy)
        bunch = pattern.rsplit('b', 1)
        empty = bunch[1].rsplit('e', 1)
        b = int(bunch[0])
        e = int(empty[0])
        halfA = e - int(math.ceil(e / 2))
        fillAd = np.zeros(halfA)
        fillAe = np.zeros(e - halfA)
        try:
            signalT = np.genfromtxt(sinais + 'signalT_' + pattern + '_' +
                                    str(occupancy) + '.csv',
                                    delimiter=',')
            signalN = np.genfromtxt(sinais + 'signalN_' + pattern + '_' +
                                    str(occupancy) + '.csv',
                                    delimiter=',')
        except:
            print('Error get saved signals')
            signalT, signalN, signalTf, signalNf = u.sgen(
                pattern, samples, b, fillAd, fillAe, matrix, sinais)

        const = {
            'iterations': iterations,
            'occupancy': occupancy,
            'pattern': pattern,
            'signalT': signalT,
            'signalN': signalN
        }

        # H, A, B = matrizes.generate(b, 0)
        # s, e = int(round(max(B.min(), B.max(), key=abs)*1000)), int(round(min(B.min(), B.max(), key=abs)*1000)-1)
        fatores = [
            2.38, 2.34, 2.3, 2.22, 2.06, 1.62, 1.46, 1.42, 1.4, 1.3, 1.22,
            1.14, 1.02, 0.9, 0.86, 0.74, 0.7, 0.66, 0.62, 0.58, 0.54, 0.5,
            0.46, 0.38, 0.34, 0.3, 0.26, 0.22, 0.18, 0.14, 0.1, 0.06, 0.02,
            0.006, 0.005, 0.004, 0.003, 0.002, 0.001, 0
        ]
        elementos = {
            2.38: 0,
            2.34: 38,
            2.3: 40,
            2.22: 42,
            2.06: 44,
            1.62: 46,
            1.46: 119,
            1.42: 125,
            1.4: 127,
            1.3: 130,
            1.22: 132,
            1.14: 134,
            1.02: 136,
            0.9: 140,
            0.86: 180,
            0.74: 187,
            0.7: 221,
            0.66: 227,
            0.62: 230,
            0.58: 233,
            0.54: 235,
            0.5: 275,
            0.46: 278,
            0.38: 310,
            0.34: 320,
            0.3: 363,
            0.26: 369,
            0.22: 409,
            0.18: 452,
            0.14: 494,
            0.1: 551,
            0.06: 638,
            0.02: 816,
            0.006: 986,
            0.005: 1050,
            0.004: 1062,
            0.003: 1128,
            0.002: 1148,
            0.001: 1280,
            0: 2592
        }

        # te = [np.count_nonzero(B)]
        # for i in range(s, e, -1):
        #     aux = i / 1000
        #     aaux = abs(aux)
        #     H, A, B = matrizes.generate(b, aaux)
        #     tmp = np.count_nonzero(B)
        #     if not tmp in te:
        #         fatores.append(aaux)
        #         elementos[aaux] = tmp
        #         te.append(tmp)

        fatores = sorted(np.abs(fatores))
        colunas = ['Fator', 'Elementos']
        for metodo in metodos:
            for ite in range(1, iterations):
                colunas.append(metodo + ':' + str(occupancy) + ':RMS:' +
                               str(ite))
        data = panda.DataFrame([], columns=colunas)
        for fator in fatores:
            opt = {'maxB': fator, 'mi': .25}
            row = ['%.3f' % fator]
            row.append(elementos[fator])
            for metodo in metodos:
                const['metodo'] = metodo
                for ite in range(1, iterations):
                    const['iterations'] = ite
                    row.append(algo.getRMSfloat(const, opt)['rms'])
            l = len(data)
            data.loc[l] = row
            with lock:
                data.to_csv(nome + '.csv', index=False)
    ended = datetime.datetime.now()
    print('Ended B Fator Test with occupancy %d at  %s after %s' %
          (occupancy, ended.strftime("%H:%M:%S %d/%m/%Y"),
           u.totalTime(startedI)))
    info.info('Ended B Fator Test with occupancy %d after %s' %
              (occupancy, u.totalTime(startedI)))
コード例 #10
0
    def getRMSfix(self, const, opt):
        if opt is None:
            opt = {}
        gerador = Signal()
        matrizes = Matrizes()
        util = Utiliters()
        iterations = const['iterations']
        occupancy = const['occupancy']
        pattern = const['pattern']
        signalT = const['signalT']
        signalN = const['signalN']
        metodo = const['metodo']
        if 'lambda' in opt:
            lamb = opt['lambda']
        else:
            lamb = 0
        if 'mi' in opt:
            mi = opt['mi']
        else:
            mi = math.inf
        if 'samples' in opt:
            samples = opt['samples']
        else:
            samples = 1820
        if 'gain' in opt:
            gain = opt['gain']
        else:
            gain = 0
        if 'bitsH' in opt:
            bitsH = opt['bitsH']
        else:
            bitsH = 5
        if 'bitsB' in opt:
            bitsB = opt['bitsB']
        else:
            bitsB = None
        bits = gain + 10
        bitsA = bitsH + 5
        align = bitsA
        bunch = pattern.rsplit('b', 1)
        empty = bunch[1].rsplit('e', 1)
        b = int(bunch[0])
        e = int(empty[0])
        bwindow = b + 6
        window = b + e
        halfA = e - int(math.ceil(e / 2))
        halfCd = int(math.ceil((bwindow - window) / 2))
        halfCe = int(bwindow - window - halfCd)
        if halfCd > 0:
            fillCd = np.zeros(halfCd)
        else:
            fillCd = np.arange(0)
        if halfCe > 0:
            fillCe = np.zeros(halfCe)
        else:
            fillCe = np.arange(0)
        mh, ma, mb = matrizes.generateFix(bitsH, bitsA, bitsB)
        H, A, B = matrizes.generate(b)
        if 'constPCD' in opt:
            constPCDv = opt['constPCD']
        else:
            constPCD = util.getPcdConst(A)
            constPCDv = int(np.round(constPCD * math.pow(2, gain)))
        if 'nu' in opt:
            nuV = opt['nu']
        else:
            nu = util.getNuConst(occupancy)
            nuV = int(np.round(nu * math.pow(2, gain)))
        signalA = np.zeros(window * samples)
        for ite in range(samples):
            step = (ite * window)
            paso = step + window
            if (e > 6):
                paso = paso - (e - 6)
            signalS = np.concatenate((fillCd, signalN[step:paso], fillCe))
            step += halfA
            paso = step + b

            Hs, x = self.sipo(signalS, gain, mh, mb, bitsB)
            if 'GDP' in metodo:
                x = self.GDP([x, Hs, ma, iterations, bits, align, mi])
            elif 'GD' in metodo:
                x = self.GD([x, Hs, ma, iterations, bits, align, mi])
            elif 'SSFlsc' in metodo:
                x = self.TAS([x, Hs, ma, iterations, bits, align, mi, lamb, gain, nuV])
            elif 'SSFls' in metodo:
                x = self.TAS([x, Hs, ma, iterations, bits, align, mi, lamb, gain, nuV])
            elif 'SSF' in metodo:
                x = self.SSF([x, Hs, ma, iterations, bits, align, mi, lamb])
            elif 'PCD' in metodo:
                x = self.PCD([x, Hs, ma, iterations, bits, align, mi, lamb, gain, constPCDv])
            x = np.where(x < 0, 0, x)
            signalA[step:paso] = np.fix(np.divide(x, pow(2, gain)))
        result = {'rms': '%.6g' % gerador.rms(signalA - signalT), 'signal': signalA}
        return result
コード例 #11
0
def rodar(patterns, metodos, conf, radical, sinais, occupancy, lock):
    u = Utiliters()
    info = u.setup_logger('information', radical + 'info.log')
    startedI = datetime.datetime.now()
    print('Started Mi Test with occupancy %d at %s' %
          (occupancy, startedI.strftime("%H:%M:%S %d/%m/%Y")))
    info.info('Started Mi Test with occupancy %d' % occupancy)
    algo = Algorithms()
    matrizes = Matrizes()
    matrix = matrizes.matrix()
    samples = 1820

    for pattern in patterns:
        nome = radical + pattern + '_' + str(occupancy)
        bunch = pattern.rsplit('b', 1)
        empty = bunch[1].rsplit('e', 1)
        b = int(bunch[0])
        e = int(empty[0])
        halfA = e - int(math.ceil(e / 2))
        fillAd = np.zeros(halfA)
        fillAe = np.zeros(e - halfA)
        try:
            signalT = np.genfromtxt(sinais + 'signalT_' + pattern + '_' +
                                    str(occupancy) + '.csv',
                                    delimiter=',')
            signalN = np.genfromtxt(sinais + 'signalN_' + pattern + '_' +
                                    str(occupancy) + '.csv',
                                    delimiter=',')
            signalTf = np.genfromtxt(sinais + 'fir/signalT_' + pattern + '_' +
                                     str(occupancy) + '.csv',
                                     delimiter=',')
            signalNf = np.genfromtxt(sinais + 'fir/signalN_' + pattern + '_' +
                                     str(occupancy) + '.csv',
                                     delimiter=',')
        except:
            print('Error get saved signals')
            signalT, signalN, signalTf, signalNf = u.sgen(
                pattern, samples, b, fillAd, fillAe, matrix, sinais)

        const = {
            'iterations': conf['iterations'],
            'occupancy': occupancy,
            'pattern': pattern,
            'signalT': signalT,
            'signalN': signalN
        }
        const['metodo'] = 'FDIP'
        constf = const
        constf['signalNf'] = signalNf
        constf['signalTf'] = signalTf
        rms = algo.getRMSfloat(constf)['rms']

        colunas = ['Iterations', 'mu']
        for metodo in metodos:
            colunas.append(metodo + ':' + str(occupancy) + ':RMS')
        colunas.append('FDIP:' + str(occupancy) + ':RMS')
        data = panda.DataFrame([[np.inf] * (len(colunas) - 1) + [rms]],
                               columns=colunas)
        for it in range(1, conf['iterations']):
            const['iterations'] = it
            for muI in range(conf['sM'], conf['eM']):
                muF = 1 / math.pow(2, muI)
                if muF == 1.0:
                    mi = math.inf
                else:
                    mi = muF
                opt = {'mi': mi}
                row = [it, muF]
                for metodo in metodos:
                    const['metodo'] = metodo
                    row.append(algo.getRMSfloat(const, opt)['rms'])
                row.append(np.inf)
                l = len(data)
                data.loc[l] = row
                with lock:
                    data.to_csv(nome + '.csv', index=False)
    ended = datetime.datetime.now()
    print('Ended Mi Test with occupancy %d at  %s after %s' %
          (occupancy, ended.strftime("%H:%M:%S %d/%m/%Y"),
           u.totalTime(startedI)))
    info.info('Ended Mi Test with occupancy %d after %s' %
              (occupancy, u.totalTime(startedI)))