Esempio n. 1
0
    def draw_topK(search_type=0, bar_type=0):
        # testSampleResultFile.t=0.ns=500.r=1.k=10.nw=1
        alg_type = ['SPBase', 'SPBest']
        ns = 200
        radius = 2
        ks = [1, 3, 5, 8, 10, 15, 20]
        nw = 5

        if bar_type==0:
            ys = [i*1000 for i in range(13)]
            ys = None
            y_label = 'Runtime (ms)'
        elif bar_type==1:
            ys = [i*100 for i in range(5)]
            y_label = '# of TQSP Computations'
        else:
            ys = [i*10 for i in range(6)]
            y_label = '# of R-tree nodes accessed'

        base_dir = 'D:\\nowMask\KnowledgeBase\\sample_result\\yago2s_single_date\\k_nw\\'

        if bar_type==0:
            timeBar = Bar(xLabel=r'top-$k$', yLabel=y_label, is_stack=True, title=r'top-k type=' + str(search_type), ys=ys)
            for i in range(len(alg_type)):
                datas = []
                for k in ks:
                    data = Data.getData(fp=PathUtility.sample_res_path(base_dir, sp=alg_type[i], nwlen=1000000, mds=1000, t=search_type, ns=200, r=2, k=k, nw=5, wf=500, dr=7))
                    print(data)
                    datas.append(data)
                timeOthers = []
                timeSemantics = []
                for data in datas:
                    timeSemantics.append(data.timeSemantic)
                    timeOthers.append(data.timeOther)

                timeBar.draw_bar(i, timeSemantics, hatch=Bar.hatchx, label=alg_type[i])
                timeBar.draw_bar(i, timeOthers, ys=timeSemantics, faceColor='white')
            timeBar.show()
        else:
            if 1==bar_type: y_type = 'TQSP'
            elif 2==bar_type: y_type = 'RTree'
            bar = Bar(xLabel=r'top-$k$', yLabel=y_label, title=r'top-k type=' + str(search_type), ys=ys, y_type=y_type)
            for i in range(len(alg_type)):
                datas = []
                for k in ks:
                    data = Data.getData(fp=PathUtility.sample_res_path(base_dir, sp=alg_type[i], nwlen=1000000, mds=1000, t=search_type, ns=200, r=2, k=k, nw=5, wf=500, dr=7))
                    print(data)
                    datas.append(data)
                list1 = []
                for data in datas:
                    if 1==bar_type:
                        list1.append(data.numTQSP)
                    elif 2==bar_type:
                        list1.append(data.numAccessedRTreeNode)
                bar.draw_bar(i, list1, label=alg_type[i])
            bar.show()
Esempio n. 2
0
    def __init__(self,
                 title='title',
                 xlabel=None,
                 xs=None,
                 ylable=None,
                 yscale='linear',
                 ys=None,
                 ylim=None,
                 fName='test.pdf'):
        self.linestyles = ['-', '--', '-.', ':']
        self.indexLineStyle = 0
        self.dashess = [[2, 2, 2, 2], [4, 4, 4, 4], [6, 6, 6, 6], [6, 2, 6, 2],
                        [10, 5, 10, 5], [12, 12, 12, 12]]
        self.indexDash = 0

        self.title = title

        self.xlabel = xlabel
        self.xs = xs

        self.ylable = ylable
        self.yscale = yscale
        self.ys = ys
        self.ylim = ylim

        self.fpath = PathUtility.figure_path() + fName

        # self.fig = plt.figure(random.randint(1, 10000), figsize=(10.1023, 6.5), tight_layout=True)
        self.fig = plt.figure(random.randint(1, 10000),
                              figsize=(10, 8),
                              tight_layout=True)
        self.fig.canvas.set_window_title(title)

        plt.rcParams['font.size'] = 20
        self.ax = self.fig.add_subplot(111)
Esempio n. 3
0
    def draw_date_range(label=r'$|q.\delta|$', base_y=None, x_rotation=0, fpath='test.pdf'):
        if base_y!=None: ys = [base_y+i*100 for i in range(0, 17)]
        # x_txts = [r'$5\times10^8$', r'$1\times10^8$', r'$5\times10^7$', r'$1\times10^7$',
        #           r'$5\times10^6$', r'$1\times10^6$', r'$5\times10^5$', r'$1\times10^5$',
        #           r'$1\times10^4$', '0']
        # x_txts = [0,3,7,15,30,50,100,150,300,600]
        # drs = [0,3,7,15,30,50,100,150,300,600]
        drs = [0,3,7,15,30,50,100,150]
        x_txts = [0,6,14,30,60,100,200,300]
        xs=[i for  i in  range(len(drs))]

        if base_y!=None: chart = LineChart(xs, x_txts, ys=ys, yscale='liner', xLabel=label, title=label, yLabel='Runtime (ms)', xlabel_rotation=x_rotation, fpath = fpath)
        else:   chart = LineChart(xs, x_txts, xLabel=label, title=label, yLabel='Runtime (ms)', xlabel_rotation=x_rotation, fpath=fpath)

        base_dir = 'D:\\nowMask\KnowledgeBase\\sample_result\\yago2s_single_date\\dr\\'
        alg_types=['SPBase', 'SPBest']
        for alg_type in alg_types:
            runtimes = []
            for dr in drs:
                data = Data.getData(fp=PathUtility.sample_res_path(base_dir, sp=alg_type, nwlen=1000000, mds=1000, t=1, ns=200, r=2, k=5, nw=5, wf=500, dr=dr))
                # print(data)
                runtimes.append(data.timeTotal)
            print(runtimes)
            if alg_type=='SPBase':
                chart.draw_line(runtimes, r'$SPTR$')
            elif alg_type=='SPBest':
                chart.draw_line(runtimes, r'$SPTR^*$')
        chart.show()
Esempio n. 4
0
    def draw_differ_size(line_type=0, title='Graph Vertex Size (in million)', fpath='test.pdf'):
        # testSampleResultFile.t=0.ns=500.r=1.k=10.nw=1
        xs = [1, 2, 3, 4]
        x_txts = [2.0, 4.0, 6.0, 8.0]

        if line_type==0:    yLabel='Runtime (ms)'
        elif line_type==1:  yLabel = '# of R-tree nodes accessed'

        chart = LineChart(xs, x_txts, xLabel=r'Graph Vertex Size (in million)', yLabel=yLabel, title=title, fpath=fpath)

        alg_types = ['SPBase', 'SPBest']
        ts = [0, 1]
        sizes = ['2000000', '4000000', '6000000', 'org']
        alg_names = [r'$SPTD$', r'$SPTR$', r'$SPTD^*$', r'$SPTR^*$']
        base_dir = 'D:\\nowMask\KnowledgeBase\\sample_result\\yago2s_single_date\\diff_size\\'

        alg_names_index = 0
        for alg_type in alg_types:
            for t in ts:
                runtimes = []
                for i in range(len(sizes)):
                    data = Data.getData(fp=PathUtility.sample_res_path(base_dir + sizes[i] + '\\', sp=alg_type, nwlen=1000000, mds=1000, t=t, ns=200, r=2, k=5, nw=5, wf=500, dr=7))
                    print(data)
                    if line_type==0:    runtimes.append(data.timeTotal)
                    elif line_type==1:  runtimes.append(data.numAccessedRTreeNode)
                chart.draw_line(runtimes, label=alg_names[alg_names_index])
                alg_names_index = alg_names_index + 1
        chart.show()
Esempio n. 5
0
    def draw_nw(base_y=None, fpath='test.pdf'):
        ys = None
        if base_y != None:
            ys = [base_y+i*100 for i in range(0, 11)]
        x_txts = [1.0, 3.0, 5.0, 8.0, 10.0]
        xs=[i for  i in  range(len(x_txts))]

        yLabel = 'Runtime (ms)'

        chart = LineChart(xs, x_txts, ys=ys, xLabel=r'|$q.\psi$|', yLabel=yLabel, title=r'|$q.\psi$|', fpath=fpath)

        alg_types = ['SPBase', 'SPBest']
        search_types = [0, 1]
        type = None

        nws = [1, 3, 5, 8, 10]
        base_dir = 'D:\\nowMask\KnowledgeBase\\sample_result\\yago2s_single_date\\k_nw\\'
        for search_index in range(len(search_types)):
            for alg_index in range(len(alg_types)):
                if alg_index==0:
                    if search_index==0: type=r'$SPTD$'
                    else:   type=r'$SPTR$'
                else:
                    if search_index==0: type=r'$SPTD^*$'
                    else:   type=r'$SPTR^*$'
                runtimes = []
                for nw in nws:
                    data = Data.getData(fp=PathUtility.sample_res_path(base_dir, sp=alg_types[alg_index], nwlen=1000000, mds=1000, t=search_types[search_index], ns=200, r=2, k=5, nw=nw, wf=500, dr=7))
                    print(data)
                    runtimes.append(data.timeTotal)
                chart.draw_line(runtimes, type)
        chart.show()
Esempio n. 6
0
    def draw_n_words(search_type=0):
        # testSampleResultFile.t=0.ns=500.r=1.k=10.nw=1
        xs = [0.5, 1, 2, 3, 4, 5, 5.5]
        x_txts = [1.0, 3.0, 5.0, 8.0, 10.0]
        ys = [i*100 for i in range(15)]
        alg_type = ['SPBase', 'SPBest']
        ns = 200
        radius = 2
        k = 5
        nws = [1, 3, 5, 8, 10]

        base_dir = 'D:\\nowMask\KnowledgeBase\\sample_result\\yago2s_single_date\\k_nw\\'

        timeBar = Bar(xLabel=r'|$q.\psi$|', yLabel='Runtime (ms)', is_stack=True, title='n_wrods type=' + str(search_type), ys=ys, xs=xs, x_txts=x_txts, y_type='NW')
        for i in range(len(alg_type)):
            datas = []
            for nw in nws:
                data = Data.getData(fp=PathUtility.sample_res_path(base_dir, sp=alg_type[i], nwlen=1000000, mds=1000, t=search_type, ns=200, r=2, k=5, nw=nw, wf=500, dr=7))
                print(data)
                datas.append(data)
            timeOthers = []
            timeSemantics = []
            for data in datas:
                timeSemantics.append(data.timeSemantic)
                timeOthers.append(data.timeOther)
            timeBar.draw_bar(i, timeSemantics, hatch=Bar.hatchx, label=alg_type[i])
            timeBar.draw_bar(i, timeOthers, ys=timeSemantics, faceColor='white')
        timeBar.show()
Esempio n. 7
0
    def __init__(self,
                 numBar,
                 title=None,
                 widthBar=0.14,
                 spanBars=0.03,
                 xlabel=None,
                 xTxts=None,
                 xTxtY=None,
                 xRotateAngle=0,
                 ylabel=None,
                 yscale='linear',
                 ys=None,
                 ylim=None,
                 loc=1,
                 fName=None):
        self.hatchxes = ['x', '.', '+', 'O']
        self.hatchIndex = 0

        if title == None: self.title = fName

        self.numBar = numBar
        self.widthBar = widthBar
        self.spanBars = spanBars  # 两个相邻bar之间相隔的宽度
        self.spanXTick = 5 / (len(xTxts) + 1)
        self.xs = [self.spanXTick * i for i in range(len(xTxts) + 2)]
        self.baseStartXOfBar = self.xs[1] - (widthBar * numBar + spanBars *
                                             (numBar - 1)) / 2
        self.spanNextBar = widthBar + spanBars  # 两个相邻bar的左边x坐标之差

        self.xlabel = xlabel
        self.xTxts = xTxts
        self.xTxtY = xTxtY  # 设置x轴的txt所在y
        self.xRotateAngle = xRotateAngle

        self.ylabel = ylabel
        self.yscale = yscale
        self.ys = ys
        self.ylim = ylim

        self.loc = loc

        self.fpath = PathUtility.figure_path() + fName

        # figure设置
        # self.fig = plt.figure(random.randint(1, 10000), figsize=(10.1023, 6.5), tight_layout=True)
        self.fig = plt.figure(random.randint(1, 10000),
                              figsize=(10, 8),
                              tight_layout=True)
        # self.fig = plt.figure(random.randint(1, 10000), figsize=(8, 6), tight_layout=True)
        self.fig.canvas.set_window_title(self.title)
        # 设置全局字体大小
        plt.rcParams['font.size'] = 25
        self.ax = self.fig.add_subplot(111)
Esempio n. 8
0
    def __init__(self,
                 fig=None,
                 xs=None,
                 ys=None,
                 xlim=None,
                 ylim=None,
                 title='title',
                 pathBgImg=None,
                 yscale='linear',
                 showXY=True,
                 markerscale=1,
                 fName='test.pdf'):

        plt.rcParams['axes.ymargin'] = 0
        plt.rcParams['axes.autolimit_mode'] = 'round_numbers'

        if fig is None:
            # self.fig = plt.figure(random.randint(1, 10000), figsize=(10.1023, 6.5), tight_layout=True)
            self.fig = plt.figure(random.randint(1, 10000),
                                  figsize=(8, 6.5),
                                  tight_layout=True)
        else:
            self.fig = fig
        # self.fig = plt.figure(random.randint(1, 10000))
        self.fig.canvas.set_window_title(title)

        # #  = None
        # if yscale != None:
        #     self.yscale = yscale
        # else:
        #     self.yscale = 'linear'
        self.markerscale = markerscale
        self.yscale = yscale
        self.xs = xs
        self.ys = ys
        self.xlim = xlim
        self.ylim = ylim
        self.pathBgImg = pathBgImg

        self.showXY = showXY

        self.fpath = PathUtility.figure_path() + fName

        plt.rcParams['font.size'] = 20
        plt.subplots_adjust(left=0, right=1, bottom=0, top=1)
        plt.margins(0)
        if fig is None:
            self.ax = self.fig.add_subplot(111)
Esempio n. 9
0
    def draw_radius(type=0, base_y=600, title='TEST', fpath='test.pdf'):
        ys = [base_y+i*50 for i in range(0, 11)]
        xs=[i for  i in  range(0, 4)]
        x_txts = [1.0, 2.0, 3.0, 5.0]
        chart = LineChart(xs, x_txts, ys=ys, yscale='liner', xLabel=r'$\alpha$-radius', yLabel='Runtime (ms)', title=title, fpath=fpath)
        # chart = LineChart(xs, x_txts, xLabel=r'$\alpha$-radius', yLabel='Runtime (ms)')

        radius = [1, 2, 3, 5]
        ks = [1, 3, 5, 8, 10, 15, 20]
        base_dir = 'D:\\nowMask\KnowledgeBase\\sample_result\\yago2s_single_date\\radius_k\\'
        for k in ks:
            runtimes = []
            for r in radius:
                data = Data.getData(fp=PathUtility.sample_res_path(base_dir, nwlen=1000000, mds=1000, t=type, ns=200, r=r, k=k, nw=5, wf=500, dr=7))
                print(data)
                runtimes.append(data.timeTotal)
            chart.draw_line(runtimes, 'k=' + str(k))
        chart.show()
Esempio n. 10
0
    def draw_k(show_type, base_y=None, fpath='test.pdf'):
        ys = None
        ys = [i*100 for i in range(17)]
        if base_y != None:
            ys = [base_y+i*100 for i in range(0, 17)]
        x_txts = [1.0, 3.0, 5.0, 8.0, 10.0, 15.0, 20.0]
        xs=[i for  i in  range(len(x_txts))]

        yLabel = None
        yscale = 'liner'
        if 0==show_type:
            yLabel = 'Runtime (ms)'
        elif 1==show_type:
            yLabel = '# of TQTSP Computations'
            yscale='log'
        elif 2==show_type: yLabel = '# of R-tree nodes accessed'

        chart = LineChart(xs, x_txts, ys=ys, yscale=yscale, xLabel=r'top-$k$', yLabel=yLabel, title=r'top-$k$', fpath=fpath)

        alg_types = ['SPBase', 'SPBest']
        search_types = [0, 1]
        type = None

        ks = [1, 3, 5, 8, 10, 15, 20]
        base_dir = 'D:\\nowMask\KnowledgeBase\\sample_result\\yago2s_single_date\\k_nw\\'
        for search_index in range(len(search_types)):
            for alg_index in range(len(alg_types)):
                if alg_index==0:
                    if search_index==0: type=r'$SPTD$'
                    else:   type=r'$SPTR$'
                else:
                    if search_index==0: type=r'$SPTD^*$'
                    else:   type=r'$SPTR^*$'
                runtimes = []
                for k in ks:
                    data = Data.getData(fp=PathUtility.sample_res_path(base_dir, sp=alg_types[alg_index], nwlen=1000000, mds=1000, t=search_types[search_index], ns=200, r=2, k=k, nw=5, wf=500, dr=7))
                    print(data)
                    if 0==show_type: runtimes.append(data.timeTotal)
                    elif 1==show_type: runtimes.append(data.numTQSP)
                    elif 2==show_type: runtimes.append(data.numAccessedRTreeNode)
                chart.draw_line(runtimes, type)
        chart.show()
Esempio n. 11
0
 def loadCsv(dir, rFanout=50, alpha=0.5, steepD=0.1, h=15, om=1, oe='1.0E-4', ns=50, t=1, k=5000, nw=2, mpts=5,
                 eps='0.001', xi='0.001', maxPNeiByte=2147483631):
     fp = PathUtility.sample_res_path(dir, rFanout, alpha, steepD, h, om, oe, ns, t, k, nw, mpts,eps, xi, maxPNeiByte)
     filename = fp[fp.rindex('res') + 4:]
     alldata = []
     reader = IterableReader(fp)
     index = 0
     for line in reader:
         if index == 0:
             index += 1
             continue
         strArr = line.split(',')
         data = Data(filename)
         data.numSample = 1
         data.numRangeRtree = int(strArr[7])
         data.numOpticFastRange = int(strArr[16])
         data.numOpticLuceneRange = int(strArr[18])
         data.timeTotal = int(strArr[24])
         data.numCluster = int(strArr[25])
         alldata.append(data)
     return alldata
Esempio n. 12
0
    def draw_word_frequency(title='WORD_FREQUENCY', base_y=None, rotation=0, fpath='test.pdf'):
        if base_y!=None: ys = [base_y+i*100 for i in range(0, 14)]
        xs=[i for  i in  range(0, 10)]
        x_txts = [0, r'$5\times10^1$', r'$1\times10^2$',
                     r'$5\times10^2$', r'$1\times10^3$',
                     r'$5\times10^3$', r'$1\times10^4$',
                     r'$5\times10^4$', r'$1\times10^5$',
                     r'$1\times10^6$'
                 ]
        if base_y!=None: chart = LineChart(xs, x_txts, ys=ys, yscale='liner', xLabel=title, yLabel='Runtime (ms)', title=title, xlabel_rotation=rotation, fpath = fpath)
        else: chart = LineChart(xs, x_txts, xLabel=title, yLabel='Runtime (ms)', title=title, xlabel_rotation=rotation, fpath = fpath)

        # chart.ax.grid('on')

        wfs = [0, 50, 100, 500, 1000, 5000, 10000, 50000, 100000, 1000000]

        base_dir = 'D:\\nowMask\KnowledgeBase\\sample_result\\yago2s_single_date\\word_fequency_test\\'
        runtimes = []
        for wf in wfs:
            data = Data.getData(fp=PathUtility.sample_res_path(base_dir, wf=wf))
            runtimes.append(data.timeTotal)
        chart.draw_line(runtimes, r'$SPTD^*$')
        chart.show()