Esempio n. 1
0
def Diff_FSPM():
    '''
    Diff-FSPM 算法分为如下3个步骤:
        - 原始序列数据集局部转换
            - 获取最优序列长度 l_opt            ok
            - 截断原始序列数据集                ok
        - 层次遍历构建绕动闭前缀序列树
            - min_sup 约束剪枝
            - 闭等价关系 剪枝
            - 预测计数值 PK. 噪音计数值
        - 描述上是挖掘FSP树, 实际直接输出结果集
            
    @summary: Diff-FSPM algorithm
    '''
    dplog.info( " === Phase 1: Decomposing input sequence dataset to n-grams (%d<=n<=%d) Begin ===" % (1, conf.l_opt) )
    conf.l_opt = GetOptSeqLength(conf.dataset, conf.epsilon, mechanism="Exponential")
    ngram_set = NGramSet( int(conf.l_opt), N_max=int(conf.n_max) )
    ngram_set.load_dataset( conf.dataset, conf.dataset_ngrams % (conf.l_opt) )
    dplog.info( " === Phase 1: Decomposing input sequence dataset to n-grams (%d<=n<=%d) End ===" % (1, conf.l_opt) )

    dplog.info( " === Phase 2: Sanitizing n-grams to build noisy frequent sequential patterns Tree Begin ===" )
    ngram_set = Sanitizer.ngram( ngram_set, conf.n_max, conf.epsilon, conf.l_opt, conf.min_sup)
    ngram_set.dump( conf.dataset_noisy % (conf.l_opt, conf.epsilon))
    dplog.info( " === Phase 2: Sanitizing n-grams to build noisy frequent sequential patterns Tree End ===" )
    
    dplog.info( " === Phase 3: Synthetic frequent sequential patterns from santized n-grams Begin ===" )
    factory = Reconstruction( ngram_set, conf.min_sup )
    factory.extend()
    factory.ngramset.dump( conf.dataset_result % (conf.l_opt, conf.epsilon))
    dplog.info( " === Phase 3: Synthetic frequent sequential patterns from santized n-grams End ===" )
Esempio n. 2
0
    print "\n=== Phase 2.1: Sanitizing clos_n-grams\n"
    ngram_set = Sanitizer.Equivalence(
        ngram_set, output_dir + dataset_name + "-" + str(scale) +
        "-original-" + str(n_max) + "grams.dat", output_dir + dataset_name +
        "-" + str(scale) + "-original-" + str(n_max) + "_clo_grams.dat")
    print "\n=== Phase 2.2: Sanitizing n-grams\n"
    ngram_set = Sanitizer.ngram(ngram_set,
                                n_max,
                                budget=epsilon,
                                sensitivity=l_max)

    ngram_set.dump(output_dir + dataset_name + file_id + ".dat")

    print "\n=== Phase 3: Synthetic sequential database generation from sanitized n-grams\n"
    factory = Reconstruction(ngram_set, lUp)

    # Reconstruct longer grams from shorter ones using the Markov approach
    factory.extend()

    # Saving the extended ngramset
    factory.ngramset.dump(outdataset_name_info %
                          (scale, n_max, topN, lLeft, lUp, deta, epsilon) +
                          "-extended.dat")

    # Generating dataset
    factory.reconstruct(outdataset_name_info %
                        (scale, n_max, topN, lLeft, lUp, deta, epsilon) +
                        "-reconstructed.dat")

    print "\n=== Phase 4: Get Consolidated Frequency"
Esempio n. 3
0
    def __init__(self):

        self.root = Tkinter.Tk()
        self.root.wm_title("Test Bench Dashboard")
        self.top = None
        self.topplot = None
        self.topcanvas = None
        self.topcbar = None
        self.topcbaxes = None

        menu = Tkinter.Menu(self.root)
        self.root.config(menu=menu)

        filemenu = Menu(menu)
        menu.add_cascade(label="File", menu=filemenu)
        filemenu.add_command(label="Exit", command=self.root.quit)
        viewmenu = Menu(menu)
        menu.add_cascade(label="View", menu=viewmenu)
        viewmenu.add_command(label="Dedicated Reconstruction Window",
                             command=self.Eitwin)
        viewmenu.add_separator()
        viewmenu.add_command(label="something else",
                             command=self.Something_else)
        helpmenu = Menu(menu)
        menu.add_cascade(label="Help", menu=helpmenu)
        helpmenu.add_command(label="About...", command=self.About)

        self.root.protocol("WM_DELETE_WINDOW", self.quit)
        # make Esc exit the program
        self.root.bind('<Escape>', lambda e: self.root.destroy())

        # Matplotlibbing.
        fig = mpl.figure.Figure(figsize=(5, 4), dpi=100)
        # pos = [left, bottom, width, height]
        image_position = [0.1, 0.25, 0.7, 0.7]
        histogram_position = [0.1, 0.08, 0.8, 0.1]
        colorbar_position = [0.85, 0.25, 0.03, 0.7]
        self.imageplt = fig.add_axes(image_position)
        self.histplt = fig.add_axes(histogram_position)
        self.cbaxes = fig.add_axes(colorbar_position)

        # 180,225,270,315,0,45,90,135
        # 1,2,3,4,5,6,7,8
        # Add text for electrode locations.
        self.imageplt.annotate('180d(AFE1)',
                               xy=(0.4, 0.9),
                               xycoords='axes fraction')
        self.imageplt.annotate('225d(AFE2)',
                               xy=(0.15, 0.75),
                               xycoords='axes fraction')
        self.imageplt.annotate('270d(AFE3)',
                               xy=(0.0, 0.5),
                               xycoords='axes fraction')
        self.imageplt.annotate('315d(AFE4)',
                               xy=(0.2, 0.2),
                               xycoords='axes fraction')
        self.imageplt.annotate('0d(AFE5)',
                               xy=(0.5, 0.1),
                               xycoords='axes fraction')
        self.imageplt.annotate('45d(AFE6)',
                               xy=(0.75, 0.25),
                               xycoords='axes fraction')
        self.imageplt.annotate('90d(AFE7)',
                               xy=(0.9, 0.5),
                               xycoords='axes fraction')
        self.imageplt.annotate('135d(AFE8)',
                               xy=(0.8, 0.8),
                               xycoords='axes fraction')

        ypadding = 10
        xpadding = 20

        #
        #
        self.file_marker = 0
        self.file_name = ''
        self.data_file_array = []
        # Will this often need to be changed?
        scale_max = 90000
        self.sliders = [0, scale_max, 0, scale_max]

        min_cbar = 0
        max_cbar = scale_max
        scale_tick_interval = float(scale_max / 10)
        # intialize the reconstruction library.
        self.image_reconstruct = eit.Reconstruction()
        self.img = self.image_reconstruct.img

        self.plot = self.imageplt.imshow(self.img, interpolation='nearest')

        # self.imageplt.set_position(image_position) # set a new position
        # self.histplt.set_position(histogram_position)
        self.cbar = mpl.pyplot.colorbar(self.plot, cax=self.cbaxes)
        # self.cbar = mpl.pyplot.colorbar(self.imageplt,cax = self.cbaxes)
        self.cbar.set_clim([min_cbar, max_cbar])
        #
        self.canvas = mpl.backends.backend_tkagg.FigureCanvasTkAgg(
            fig, master=self.root)

        self.canvas.show()
        self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
        toolbar = mpl.backends.backend_tkagg.NavigationToolbar2TkAgg(
            self.canvas, self.root)
        toolbar.update()
        self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
        # canvas.mpl_connect('key_press_event', on_key_event)

        self.use_blit = False
        # cache the background, in the init.
        if self.use_blit:  # cache the background.
            self.background = self.canvas.copy_from_bbox(self.imageplt.bbox)
            self.histbackground = self.canvas.copy_from_bbox(self.histplt.bbox)
            self.cbbackground = self.canvas.copy_from_bbox(self.cbaxes.bbox)
        self.total_rendering_time = 0.0
        self.total_processing_time = 0.0
        # ---------------
        # defining frames
        # ---------------
        bottomframe0 = Frame(self.root)
        bottomframe1 = Frame(self.root)
        bottomframe2 = Frame(self.root)
        bottomframe3 = Frame(self.root)

        bottomframe0.pack(side=TOP)
        bottomframe1.pack(side=TOP)
        bottomframe2.pack(side=TOP)
        bottomframe3.pack(side=TOP)

        # This is the text box...
        self.msg = Tkinter.Text(bottomframe0,
                                height=1.0,
                                bg="light cyan",
                                state=Tkinter.NORMAL)
        self.msg.grid(row=1, column=0, columnspan=3)
        self.msg.pack(fill="x", expand=True)

        # sliders.
        self.w1 = Tkinter.Scale(bottomframe0,
                                from_=self.sliders[0],
                                to=self.sliders[1],
                                length=600,
                                tickinterval=scale_tick_interval,
                                orient=HORIZONTAL,
                                label='MIN')
        self.w1.set(scale_max / 10)
        self.w1.pack(fill="x", expand=True)
        self.w2 = Tkinter.Scale(bottomframe0,
                                from_=self.sliders[2],
                                to=self.sliders[3],
                                length=600,
                                tickinterval=scale_tick_interval,
                                orient=HORIZONTAL,
                                label='MAX')
        self.w2.set(9 * scale_max / 10)
        self.w2.pack(fill="x", expand=True)

        # Text entry boxes for min and max range of each slider bar.
        #
        #
        cbarbut = Tkinter.Button(bottomframe0,
                                 text='Update HIST',
                                 command=self.update_hist)
        cbarbut.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

        cbarbut = Tkinter.Button(bottomframe0,
                                 text='Update CBAR',
                                 command=self.update_cbar)
        cbarbut.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

        self.hist_update = False

        self.min_slider_l = Tkinter.Entry(bottomframe0)
        self.min_slider_h = Tkinter.Entry(bottomframe0)
        self.max_slider_l = Tkinter.Entry(bottomframe0)
        self.max_slider_h = Tkinter.Entry(bottomframe0)
        self.max_slider_h.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)
        self.max_slider_h_label = Tkinter.Label(
            bottomframe0, text="max_h:").pack(side=Tkinter.RIGHT)
        self.max_slider_l.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)
        self.max_slider_l_label = Tkinter.Label(
            bottomframe0, text="max_l:").pack(side=Tkinter.RIGHT)
        self.min_slider_h.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)
        self.min_slider_h_label = Tkinter.Label(
            bottomframe0, text="min_h:").pack(side=Tkinter.RIGHT)
        self.min_slider_l.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)
        self.min_slider_l_label = Tkinter.Label(
            bottomframe0, text="min_l:").pack(side=Tkinter.RIGHT)
        self.min_slider_l.bind("<Return>", self.evaluate)
        self.min_slider_h.bind("<Return>", self.evaluate)
        self.max_slider_l.bind("<Return>", self.evaluate)
        self.max_slider_h.bind("<Return>", self.evaluate)

        full_ports = list(serial.tools.list_ports.comports())
        portnames = [item[0] for item in full_ports]
        if len(portnames) > 0:
            self.menuselect = StringVar(self.root)
            self.menuselect.set(portnames[0])
            # apply has been deprecated.
            # listboxdataconnect = apply(OptionMenu, (self.root, self.menuselect) + tuple(portnames ))

            listboxdataconnect = OptionMenu(*(self.root, self.menuselect) +
                                            tuple(portnames))

            listboxdataconnect.pack(in_=bottomframe1,
                                    side=Tkinter.LEFT,
                                    padx=3,
                                    pady=ypadding)

            self.baselinebut = Tkinter.Button(master=bottomframe1,
                                              text="Baseline",
                                              command=self.baseline)
            self.baselinebut.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

            self.recorddata = Tkinter.Button(master=bottomframe1,
                                             text='Record',
                                             command=self.record)
            self.recorddata.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

            self.buttonconnect = Tkinter.Button(master=bottomframe1,
                                                text='Connect',
                                                command=self.connect)
            self.buttonconnect.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

        else:
            # no serial port detected.
            print('no serial port found, hope that\'s OK')
            self.text = "no serial port found, hope that's OK"
            if expertMode is False:
                tkMessageBox.showwarning(
                    "No serial port",
                    "No device detected\nCheck cable and connection")

        readfilerunbut = Tkinter.Button(bottomframe2,
                                        text='Run',
                                        command=self.run_file)
        readfilerunbut.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

        readfilestartbut = Tkinter.Button(bottomframe2,
                                          text='Step',
                                          command=self.step_file)
        readfilestartbut.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

        readfilebut = Tkinter.Button(bottomframe2,
                                     text='ReadFromFile',
                                     command=self.load_file)
        readfilebut.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

        # start Serial handler off in a separate process.
        self.s = Serialhandler.Serialhandler()
        self.s.start()
        self.s.join()
        self.text = 'hi'
        self.root.after(200, self.process_data)
        self.root.mainloop()