Пример #1
0
     for pos in range(length):
         pvar[pos] = np.std(d[pos * step:(pos * step) + rslt, s])
     #print p
     lsignalsvar.append((pvar, datainfo.sensors[s]))
     plt.subplots(figsize=(20, 10))
     plt.axis([0, length, 0, 0.2])
     plot(range(length), pvar)
     #plt.show()
     plt.title(datainfo.datafiles[dfile] + '-' +
               datainfo.expnames[dfile] + '-' + datainfo.sensors[s],
               fontsize=48)
     plt.savefig(
         datainfo.dpath + '/' + datainfo.name + '/Results/' +
         'variance-' + datainfo.datafiles[dfile] + '-' +
         datainfo.expnames[dfile] + '-' + datainfo.sensors[s] +
         '.pdf',
         orientation='landscape',
         format='pdf')
     plt.close()
 plotSignals(
     lsignalsvar,
     6,
     2,
     0.2,
     0,
     'variance-' + datainfo.datafiles[dfile] + '-' +
     datainfo.expnames[dfile] + '-' + str(rslt) + '-' + str(step),
     datainfo.datafiles[dfile] + '-' + datainfo.expnames[dfile],
     datainfo.dpath + '/' + datainfo.name + '/Results/',
     orientation='portrait',
     cstd=[0.05] * 12)
            rects = ax.bar(ind+(i*width), h, width, color=colors[i])
        fig.suptitle(datainfo.name + '-' + s + ext, fontsize=48)

        minaxis = np.min(km.cluster_centers_)
        maxaxis = np.max(km.cluster_centers_)

        for nc in range(nclusters):
            ax2 = fig.add_subplot(2, nclusters, nc+nclusters+1)
            signal = km.cluster_centers_[lmax[nc][0]]
            plt.title(' ( '+str(cnt[lmax[nc][0]])+' )')
            t = arange(0.0, len(signal), 1)
            ax2.axis([0, len(signal), minaxis, maxaxis])
            ax2.plot(t,signal)
            plt.axhline(linewidth=1, color='r', y=0)
        fig.savefig(datainfo.dpath+'/Results/' + datainfo.name + '-' + s + ext + '-histo-sort.pdf', orientation='landscape', format='pdf')
    #    plt.show()

        print '*******************'
        for nc in range(nclusters):
            lsignals.append((km.cluster_centers_[lmax[nc][0]], str(nc)+' ( '+str(cnt[lmax[nc][0]])+' )'))

        #print s, np.max(km.cluster_centers_), np.min(km.cluster_centers_)
        if nclusters % 2 == 0:
            part = nclusters /2
        else:
            part = (nclusters /2) + 1
        plotSignals(lsignals,part,2,np.max(km.cluster_centers_),np.min(km.cluster_centers_), datainfo.name + '-' + s + ext,
                    datainfo.name + '-' + s + ext, datainfo.dpath+'/Results/')
        # for cc in range(nclusters):
        #     show_signal(km.cluster_centers_[cc])
    f.close()
Пример #3
0
    c = Counter(l)

    print c

    lcenters = []
    numex = np.zeros(nc)
    for i in c:
        centers[i] /= c[i]
        print i, c[i]
        numex[i] = c[i]
        lcenters.append((centers[i], 'center %d' % i))

    mx = 0.26  # np.max(centers)
    mn = -0.06  # np.min(centers)

    plotSignals(lcenters, nc, 1, mx, mn, 'cluster-' + alg + '-%s-NC%d' % (line, nc),
                'cluster-' + alg + '-%sNC%d' % (line, nc), clusterpath)

    if alg == 'spectral':
        params = {'clalg': 'spectral',
                  'nc': nc,
                  'labels': 'discretize',
                  'affinity': 'nearest_neighbors',
                  'n_neigbors': 30
                  }
    elif alg == 'kmeans':
        params = {'clalg': 'kmeans', 'nc': nc}
    peakdata = {'labels': lab,
                'centers': centers,
                'numex': numex,
                'params': params
                }
Пример #4
0
    numex = np.zeros(nc)
    for i in c:
        centers[i] /= c[i]
        print i, c[i]
        numex[i] = c[i]
        lcenters.append((centers[i], 'center %d' % i))

    cstd = np.zeros((nc, data.shape[1]))
    for i in c:
        center_mask = lab == i
        cstd[i] = np.std(data[center_mask], axis=0)

    mx = np.max(centers)  # 0.26
    mn = np.min(centers)  #-0.06

    plotSignals(lcenters, 8, 2, mx, mn, 'cluster-' + alg + '-N-%s-NC%d' % (line, nc),
                'cluster-' + alg + '-%sNC%d' % (line, nc), clusterpath, cstd=cstd)

    #
    # if alg == 'spectral':
    #     params = {'clalg': 'spectral',
    #                        'nc': nc,
    #                        'labels': 'discretize',
    #                        'affinity': 'nearest_neighbors',
    #                        'n_neigbors': 30
    #                        }
    # elif alg == 'kmeans':
    #     params = {'clalg': 'kmeans', 'nc': nc}
    # peakdata = {'labels': lab,
    #             'centers': centers,
    #             'numex': numex,
    #             'params': params
Пример #5
0
            maxaxis = np.max(centroids)

            for nc in range(nclusters):
                ax2 = fig.add_subplot(2, nclusters, nc + nclusters + 1)
                signal = centroids[nc]
                plt.title(' ( ' + str(nc + 1) + ' )')
                t = np.arange(0.0, len(signal), 1)
                ax2.axis([0, len(signal), minaxis, maxaxis])
                ax2.plot(t, signal)
                plt.axhline(linewidth=1, color='r', y=0)
            fig.savefig(datainfo.dpath + '/' + datainfo.name + '/Results/' +
                        datainfo.name + '-' + sensor + '-' + str(nclusters) +
                        '-' + ext + '-histo-sort.pdf',
                        orientation='landscape',
                        format='pdf')
            #    plt.show()

            print('*******************')
            for nc in range(nclusters):
                lsignals.append((centroids[nc], str(nc)))

            if nclusters % 2 == 0:
                part = nclusters / 2
            else:
                part = (nclusters / 2) + 1
            plotSignals(
                lsignals, part, 2, maxaxis, minaxis, datainfo.name + '-' +
                sensor + '-' + str(nclusters) + '-' + ext,
                datainfo.name + '-' + sensor + '-' + ext,
                datainfo.dpath + '/' + datainfo.name + '/Results/')
        datainfo.close_experiment_data(f)
Пример #6
0
            ax.set_xticklabels(['class %d'% (i+1) for i in ind])
            for i, h in enumerate(lhisto):
                rects = ax.bar(ind+(i*width), h, width, color=colors[i])
            fig.suptitle(datainfo.name + '-' + sensor+ '-' + ext, fontsize=48)

            minaxis = np.min(centroids)
            maxaxis = np.max(centroids)

            for nc in range(nclusters):
                ax2 = fig.add_subplot(2, nclusters, nc+nclusters+1)
                signal = centroids[nc]
                plt.title(' ( '+str(nc+1)+' )')
                t = arange(0.0, len(signal), 1)
                ax2.axis([0, len(signal), minaxis, maxaxis])
                ax2.plot(t,signal)
                plt.axhline(linewidth=1, color='r', y=0)
            fig.savefig(datainfo.dpath + '/' + datainfo.name + '/Results/' + datainfo.name + '-' + sensor + '-' +
                        str(nclusters) + '-' + ext + '-histo-sort.pdf', orientation='landscape', format='pdf')
        #    plt.show()

            print('*******************')
            for nc in range(nclusters):
                lsignals.append((centroids[nc], str(nc)))

            if nclusters % 2 == 0:
                part = nclusters /2
            else:
                part = (nclusters /2) + 1
            plotSignals(lsignals, part, 2, maxaxis, minaxis, datainfo.name + '-' + sensor + '-' +
                        str(nclusters)+ '-' + ext, datainfo.name + '-' + sensor+ '-' + ext, datainfo.dpath + '/' + datainfo.name + '/Results/')
        datainfo.close_experiment_data(f)
Пример #7
0
        datainfo = experiments[expname]
        f = h5py.File(datainfo.dpath + datainfo.name + ext + '.hdf5', 'r')

        rslt = 50000
        step = 10000
        for dfile in range(0,len(datainfo.datafiles)):
            d = f[datainfo.datafiles[dfile] + '/' + 'Raw']
            length = int(d.shape[0]/float(step))
            lsignalsvar = []
            lsignalsmean = []
            for s in [4,5,6,7]: # range(len(datainfo.sensors)):
                print dfile, datainfo.sensors[s]
                pvar = np.zeros(length)
                pmean = np.zeros(length)
                for pos in range(length):
                    pvar[pos] = np.std(d[pos*step:(pos*step)+rslt, s])
                #print p
                lsignalsvar.append((pvar,datainfo.sensors[s]))
                plt.subplots(figsize=(20, 10))
                plt.axis([0, length, 0, 0.2])
                plot(range(length), pvar)
                #plt.show()
                plt.title(datainfo.datafiles[dfile]+ '-' + datainfo.sensors[s], fontsize=48)
                plt.savefig(datainfo.dpath + '/Results/' + datainfo.datafiles[dfile] + '-' + datainfo.sensors[s]
                            + '-variance.pdf', orientation='landscape', format='pdf')
                plt.close()
            plotSignals(lsignalsvar, 2, 2, 0.2, 0,
                        datainfo.datafiles[dfile]+'-'+str(rslt)+'-'+str(step)+'-variance',
                        datainfo.datafiles[dfile],
                        datainfo.dpath + '/Results/', orientation='portrait', cstd=[0.05, 0.05, 0.05, 0.05])
Пример #8
0
        datainfo = experiments[expname]
        f = h5py.File(datainfo.dpath + datainfo.name + '/' + datainfo.name + '.hdf5', 'r')

        rslt = 50000
        step = 10000
        for dfile in range(0,len(datainfo.datafiles)):
            d = f[datainfo.datafiles[dfile] + '/' + 'Raw']
            length = int(d.shape[0]/float(step))
            lsignalsvar = []
            lsignalsmean = []
            for s in range(len(datainfo.sensors)):
                print dfile, datainfo.sensors[s]
                pvar = np.zeros(length)
                pmean = np.zeros(length)
                for pos in range(length):
                    pvar[pos] = np.std(d[pos*step:(pos*step)+rslt, s])
                #print p
                lsignalsvar.append((pvar,datainfo.sensors[s]))
                plt.subplots(figsize=(20, 10))
                plt.axis([0, length, 0, 0.2])
                plot(range(length), pvar)
                #plt.show()
                plt.title(datainfo.datafiles[dfile]+'-'+ datainfo.expnames[dfile]+ '-' + datainfo.sensors[s], fontsize=48)
                plt.savefig(datainfo.dpath + '/' + datainfo.name + '/Results/' + 'variance-' + datainfo.datafiles[dfile]+'-'+ datainfo.expnames[dfile] + '-' + datainfo.sensors[s]
                            + '.pdf', orientation='landscape', format='pdf')
                plt.close()
            plotSignals(lsignalsvar, 6, 2, 0.2, 0,
                        'variance-'+datainfo.datafiles[dfile]+'-'+datainfo.expnames[dfile]+'-'+str(rslt)+'-'+str(step),
                        datainfo.datafiles[dfile]+'-'+datainfo.expnames[dfile],
                        datainfo.dpath + '/' + datainfo.name + '/Results/', orientation='portrait', cstd=[0.05]*12)
            ax.set_xticklabels(ind)
            for i, h in enumerate(lhisto):
                rects = ax.bar(ind+(i*width), h, width, color=colors[i])
            fig.suptitle(datainfo.name + '-' + sensor, fontsize=48)

            minaxis = np.min(centroids)
            maxaxis = np.max(centroids)

            for nc in range(nclusters):
                ax2 = fig.add_subplot(2, nclusters, nc+nclusters+1)
                signal = centroids[lmax[nc][0]]
                plt.title(' ( '+str(cnt[lmax[nc][0]])+' )')
                t = arange(0.0, len(signal), 1)
                ax2.axis([0, len(signal), minaxis, maxaxis])
                ax2.plot(t,signal)
                plt.axhline(linewidth=1, color='r', y=0)
            fig.savefig(datainfo.dpath + '/' + datainfo.name + '/Results/' + datainfo.name + '-' + sensor + '-' + str(nclusters)
                        + '-histo-sort.pdf', orientation='landscape', format='pdf')
        #    plt.show()

            print('*******************')
            for nc in range(nclusters):
                lsignals.append((centroids[lmax[nc][0]], str(nc)+' ( '+str(cnt[lmax[nc][0]])+' )'))

            if nclusters % 2 == 0:
                part = nclusters /2
            else:
                part = (nclusters /2) + 1
            plotSignals(lsignals, part, 2, maxaxis, minaxis, datainfo.name + '-' + sensor,
                        datainfo.name + '-' + sensor, datainfo.dpath + '/' + datainfo.name + '/Results/')
        datainfo.close_experiment_data(f)