Exemplo n.º 1
0
def plot_wikipedia(predictor, save_pdf=False):
    """Plot wikipedia target prediction and real values."""
    target, model = predictor.get_plot_data('wikipedia')
    output = '/tmp/wikipedia.pdf' if save_pdf else None
    plotter = Plotter(xlim=(3, 65), ylim=(0, 200))
    plotter.plot_model(model, target, output)
    print('Prediction of the Wikipedia application target execution duration.')
Exemplo n.º 2
0
def plot_wikipedia_cost(model, model_df, cost_func, save_pdf=False):
    output = '/tmp/wikipedia_cost.pdf' if save_pdf else None
    df = _select_df(model_df, 'application', 'wikipedia')
    target = _train(model, df)
    plotter = Plotter(xlim=(0, 3.5))
    plotter.update_config(s=40)
    plotter.plot_cost_model(model, target, cost_func, output)
    print('Prediction of the Wikipedia application cost.')
Exemplo n.º 3
0
def plot_wikipedia(model, model_df, save_pdf=False):
    """Plot actual results and model's predictions."""
    output = '/tmp/wikipedia.pdf' if save_pdf else None
    df = _select_df(model_df, 'application', 'wikipedia')
    target = _train(model, df)
    plotter = Plotter(xlim=(3, 65), ylim=(0, 200))
    plotter.plot_model(model, target, output)
    print('Prediction of the Wikipedia application target execution duration.')
Exemplo n.º 4
0
def plot_hbsort(predictor, save_pdf=False):
    """Plot actual results and model's predictions."""
    target, model = predictor.get_plot_data('hbsort')
    outputs = _get_outputs(save_pdf, 'hbsort3.pdf', 'hbsort30.pdf')
    plotter = Plotter(xlim=(0.75, 16.25))
    plotter.plot_model(model, target[target.input < 15 * 1024**3], outputs[0])
    plotter = Plotter(xlim=(14, 130))
    plotter.plot_model(model, target[target.input > 15 * 1024**3], outputs[1])
    print('The top figure is the result of the HiBench Sort application with'
          ' 3-GB input. The second figure uses 31-GB of data.')
Exemplo n.º 5
0
def plot_hbkmeans(predictor, save_pdf=False):
    """Plot actual results and model's predictions."""
    target, model = predictor.get_plot_data('hbkmeans')
    outputs = _get_outputs(save_pdf, 'hbkmeans16.pdf', 'hbkmeans65.pdf')
    plotter = Plotter(xlim=(7.5, 32.5))
    plotter.plot_model(model, target[target.input == 16384000], outputs[0])
    plotter = Plotter(xlim=(30, 130))
    plotter.plot_model(model, target[target.input == 65536000], outputs[1])
    print('The top figure is the result of the HiBench K-means application'
          ' with 16,384,000 samples. The second figure uses 65,536,000'
          ' samples.')
Exemplo n.º 6
0
def predict_example_2(fd, recogniter):
    """
    データはランダムに選択された関数から取得してnetwrokに入力.
    関数を確率を表示する.
    """
    plotter_2    = Plotter()
    result = defaultdict(list)

    plotter_2.initialize({
        'xy_value':{
            'ylim': [0,100],
            'sub_title': ['value']},
        'likelihood':{
            'ylim': [0,1],
            'sub_title': fd.function_list.keys()},
        }, movable=True)

    #for ftype in fd.function_list.keys():
    print '################"'
    for idx in range(100):
        ftype = fd.romdom_choice()
        data  = fd.get_data(ftype)
        for x, y in data:
            input_data = {
                    'xy_value': [x, y],
                    'x_value': x,
                    'y_value': y,
                    'ftype': None
                    }
            inferences = recogniter.run(input_data, learn=False)

            # print
            input_data['ftype'] = ftype
            recogniter.print_inferences(input_data, inferences)

            tmp = inferences[ "classifier_" + recogniter.selectivity]['likelihoodsDict']
            plotter_2.write_draw(title='xy_value',   x_value={'value': x + 100 * idx}, y_value={'value': y})
            plotter_2.write_draw(title='likelihood', x_value=dict([(sub, x + 100 * idx) for sub in tmp.keys()]),  y_value=tmp)
Exemplo n.º 7
0
from lib.msplot import *
import easygui
from lib.data import Data, AuxPlots
from lib.plotter import Plotter
import numpy as np

if __name__ == '__main__':
    path = easygui.diropenbox()
    d = Data()

    d.load(path)

    p = Plotter(d)
    print(d.aux_data)

    # if __name__ == '__main__':
    # 	path = easygui.diropenbox()

    # 	s = Spectrum()

    # 	s.load(path, onblast_cutoff=150)
    # 	#s.load("C:\\Users\\ishma\\Dropbox (SteinLab)\\spectra\\(ID     186nm) 2016-07-26-tip15")
    # 	#s.load("../(ID     186nm) 2016-07-26-tip15/")

    p.makeAnimation(window=500,
                    step=20,
                    scan_range=(None, None),
                    mass_range=(None, None),
                    out_name="test.mp4",
                    normalization=SpecNorm.SCAN,
                    label_peaks=True,
Exemplo n.º 8
0
def main():
    type_a_data = [2] * 10 + [50] * 30
    type_b_data = [1] * 10 + [50] * 30

    data_set = {'a': type_a_data, 'b': type_b_data}

    recogniter = FunctionRecogniter()

    plotter = Plotter()
    result = defaultdict(list)
    plotter.initialize(
        {
            'anomaly': {
                'ylim': [0, 1],
                'sub_title': ['a', 'b']
            },
            'output-differ': {
                'ylim': [0, 1],
                'sub_title': ['a', 'b']
            },
            'first': {
                'ylim': [0, 100],
                'sub_title': ['a', 'b']
            },
        },
        movable=True)

    # トレーニング
    for i in range(100):
        anomaly_mean = {}
        output_differ_mean = {}
        first_input = {}
        for ftype, data in data_set.items():
            tmp_anomaly = []
            tmp_output_differ = []
            first_input_cnt = 0
            for x, y in enumerate(data):
                input_data = {
                    'xy_value': [x, y],
                    'x_value': x,
                    'y_value': y,
                    'ftype': ftype
                }
                inferences = recogniter.run(input_data, learn=True)

                # for plot
                tmp_anomaly.append(inferences['anomaly']['region1'])
                if len(inferences["output_differ"]) == 0:
                    first_input_cnt += 1
                else:
                    tmp_output_differ.append(
                        inferences["output_differ"]['region1'])

                # print
                #recogniter.print_inferences(input_data, inferences)
            recogniter.reset()

            # for plot
            anomaly_mean[ftype] = sum(tmp_anomaly) / len(tmp_anomaly)
            output_differ_mean[ftype] = sum(tmp_output_differ) / len(
                tmp_output_differ)
            first_input[ftype] = first_input_cnt

        plotter.write_draw(title='anomaly',
                           x_value={
                               'a': i,
                               'b': i
                           },
                           y_value=anomaly_mean)
        plotter.write_draw(title='output-differ',
                           x_value={
                               'a': i,
                               'b': i
                           },
                           y_value=output_differ_mean)
        plotter.write_draw(title='first',
                           x_value={
                               'a': i,
                               'b': i
                           },
                           y_value=first_input)

        # 予測
        #if i % 10 == 0:
        print
        print '##################### ', i
        predict_example_4(data_set, recogniter)

    plotter.show()
Exemplo n.º 9
0
    def __init__(self):
        QMainWindow.__init__(self)
        self.__config = ConfigObj("./config/seasnake.conf")
        self.setMinimumSize(
            QSize(int(self.__config['general']['win_width']),
                  int(self.__config['general']['win_height'])))
        self.dateutil = DateUtility()
        #print self.dateutil.todate(self.dateutil.currentepoch()), self.dateutil.currentepoch()
        self.plugins = []
        self.plot = Plotter()
        self.plot.setMinimumHeight(600)
        self.linelist = LineFeather(self)
        self.todaymark = InfiniteLine(angle=90,
                                      movable=False,
                                      pos=(self.dateutil.currentepoch()),
                                      name="Now",
                                      pen="g")
        self.todaymark.setFocus()
        self.plot._plt.addItem(self.todaymark, ignoreBounds=True)
        self.plot.region.setRegion([
            int(self.dateutil.currentepoch() - 7200),
            int(self.dateutil.currentepoch() + 36000)
        ])
        self.timer = QTimer()
        self.timer.timeout.connect(self.updateUI)
        self.timer.setInterval(10)
        self.timer.start(50)
        self.status = StatusBar()
        self.setStatusBar(self.status)
        self.statuslayout = QHBoxLayout()
        self.__maindisplay = QGroupBox()
        self.mainlayout = QFormLayout()
        self.mainlayout.expandingDirections()
        self.__maindisplay.setLayout(self.mainlayout)
        self.mainlayout.addRow(self.linelist, self.plot)
        self.mainlayout.addRow(self.linelist.chkplot,
                               self.linelist.chkfpredict)
        self.datapanel = QFormLayout()
        self.dslayout = QVBoxLayout()
        self.importerlayout = QVBoxLayout()
        self.importerlayout.setAlignment(Qt.AlignTop)
        self.importerdock = self.__build_dock
        self.importerdock.setLayout(self.importerlayout)

        self.progressbar = QProgressBar()
        self.progressbar.setMaximumWidth(100)
        self.progressbar.setMaximum(100)
        self.status.addPermanentWidget(self.progressbar)

        self.btntrigger = QPushButton("Start Prediction")
        self.btntrigger.clicked.connect(self.btntrigger_click)
        self.constituent_opts = QComboBox()

        self.datasource = DataSourceController(self)

        for k, v in self.__config['constituent'].items():
            self.constituent_opts.addItem(k)
            self.constcheck[k] = QCheckBox(k)
            self.constcheck[k].toggled.connect(self.btntrigger_click)

        self.dock = self.__dock
        self.dock.setWindowTitle("Options")
        self.tab = QTabWidget()
        self.tab.addTab(self.importerdock, "Importer")
        self.tab.addTab(self.__build_dspanel, "Datasource")
        self.tab.addTab(self.__build_dock, "Utilities")
        self.tab.addTab(self.__build_dock, "About")
        self.tab.setCurrentIndex(1)
        self.dock.setWidget(self.tab)
        self.addDockWidget(Qt.LeftDockWidgetArea, self.dock)
        self.setCentralWidget(self.__maindisplay)
Exemplo n.º 10
0
class MainWindow(QMainWindow):
    constcheck = {}

    def __init__(self):
        QMainWindow.__init__(self)
        self.__config = ConfigObj("./config/seasnake.conf")
        self.setMinimumSize(
            QSize(int(self.__config['general']['win_width']),
                  int(self.__config['general']['win_height'])))
        self.dateutil = DateUtility()
        #print self.dateutil.todate(self.dateutil.currentepoch()), self.dateutil.currentepoch()
        self.plugins = []
        self.plot = Plotter()
        self.plot.setMinimumHeight(600)
        self.linelist = LineFeather(self)
        self.todaymark = InfiniteLine(angle=90,
                                      movable=False,
                                      pos=(self.dateutil.currentepoch()),
                                      name="Now",
                                      pen="g")
        self.todaymark.setFocus()
        self.plot._plt.addItem(self.todaymark, ignoreBounds=True)
        self.plot.region.setRegion([
            int(self.dateutil.currentepoch() - 7200),
            int(self.dateutil.currentepoch() + 36000)
        ])
        self.timer = QTimer()
        self.timer.timeout.connect(self.updateUI)
        self.timer.setInterval(10)
        self.timer.start(50)
        self.status = StatusBar()
        self.setStatusBar(self.status)
        self.statuslayout = QHBoxLayout()
        self.__maindisplay = QGroupBox()
        self.mainlayout = QFormLayout()
        self.mainlayout.expandingDirections()
        self.__maindisplay.setLayout(self.mainlayout)
        self.mainlayout.addRow(self.linelist, self.plot)
        self.mainlayout.addRow(self.linelist.chkplot,
                               self.linelist.chkfpredict)
        self.datapanel = QFormLayout()
        self.dslayout = QVBoxLayout()
        self.importerlayout = QVBoxLayout()
        self.importerlayout.setAlignment(Qt.AlignTop)
        self.importerdock = self.__build_dock
        self.importerdock.setLayout(self.importerlayout)

        self.progressbar = QProgressBar()
        self.progressbar.setMaximumWidth(100)
        self.progressbar.setMaximum(100)
        self.status.addPermanentWidget(self.progressbar)

        self.btntrigger = QPushButton("Start Prediction")
        self.btntrigger.clicked.connect(self.btntrigger_click)
        self.constituent_opts = QComboBox()

        self.datasource = DataSourceController(self)

        for k, v in self.__config['constituent'].items():
            self.constituent_opts.addItem(k)
            self.constcheck[k] = QCheckBox(k)
            self.constcheck[k].toggled.connect(self.btntrigger_click)

        self.dock = self.__dock
        self.dock.setWindowTitle("Options")
        self.tab = QTabWidget()
        self.tab.addTab(self.importerdock, "Importer")
        self.tab.addTab(self.__build_dspanel, "Datasource")
        self.tab.addTab(self.__build_dock, "Utilities")
        self.tab.addTab(self.__build_dock, "About")
        self.tab.setCurrentIndex(1)
        self.dock.setWidget(self.tab)
        self.addDockWidget(Qt.LeftDockWidgetArea, self.dock)
        self.setCentralWidget(self.__maindisplay)

    def updateUI(self):
        self.todaymark.setPos(self.dateutil.currentepoch())
        #print self.todaymark.getPos()
    @property
    def xaxis(self):
        ax = DateAxis(orientation='bottom')
        return ax

    def setPlugins(self, pluginarray=[]):
        self.plugins = pluginarray

    def btntrigger_click(self):
        self.datasource.selected.constituent = {}
        self.datasource.clearplot()
        for k, v in self.constcheck.items():
            if self.constcheck[k].isChecked():
                self.datasource.selected.constituent[k] = self.__config[
                    'constituent'][str(v.text())]

        if len(self.datasource.selected.constituent.keys()) != 0:
            self.datasource.selected.bootup()

    @property
    def __build_dspanel(self):
        gb = QGroupBox()
        gb.setAlignment(Qt.AlignCenter)
        gblayout = QVBoxLayout()
        gblayout.addWidget(self.datasource.dscheckbox)
        for i in self.constcheck.values():
            gblayout.addWidget(i)
        gblayout.addWidget(self.datasource.paramgb)
        gblayout.addWidget(self.btntrigger)
        gb.setLayout(gblayout)
        return gb

    @property
    def __build_dock(self):
        gb = QGroupBox()
        return gb

    @property
    def __dock(self):
        dock = QDockWidget(self)
        dock.setMinimumWidth(300)
        dock.setMinimumHeight(100)
        dock.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)

        return dock

    @property
    def menubar(self):
        return self.menuBar()

    @property
    def toolbar(self):
        return self.toolButtonStyle()
def main():
    type_a_data = [2] * 10 + [50] * 30
    type_b_data = [1] * 10 + [50] * 30

    data_set  = {'a': type_a_data, 'b':type_b_data}

    recogniter = FunctionRecogniter()

    plotter    = Plotter()
    result = defaultdict(list)
    plotter.initialize({
        'anomaly':{
            'ylim': [0,1],
            'sub_title': ['a', 'b']},
        'output-differ':{
            'ylim': [0,1],
            'sub_title': ['a', 'b']},
        'first':{
            'ylim': [0,100],
            'sub_title': ['a', 'b']},
        }, movable=True)

    # トレーニング
    for i in range(100):
        anomaly_mean = {}
        output_differ_mean = {}
        first_input = {}
        for ftype, data in data_set.items():
            tmp_anomaly = []
            tmp_output_differ = []
            first_input_cnt = 0
            for x, y in enumerate(data):
                input_data = {
                        'xy_value': [x, y],
                        'x_value': x,
                        'y_value': y,
                        'ftype': ftype
                        }
                inferences = recogniter.run(input_data, learn=True)

                # for plot
                tmp_anomaly.append(inferences['anomaly']['region1'] )
                if len(inferences["output_differ"]) == 0:
                    first_input_cnt += 1
                else:
                    tmp_output_differ.append(inferences["output_differ"]['region1'])

                # print
                #recogniter.print_inferences(input_data, inferences)
            recogniter.reset()

            # for plot
            anomaly_mean[ftype]       = sum(tmp_anomaly) / len(tmp_anomaly)
            output_differ_mean[ftype] = sum(tmp_output_differ) / len(tmp_output_differ)
            first_input[ftype] =  first_input_cnt

        plotter.write_draw(title='anomaly', x_value={'a':i, 'b':i}, y_value=anomaly_mean)
        plotter.write_draw(title='output-differ', x_value={'a':i, 'b':i}, y_value=output_differ_mean)
        plotter.write_draw(title='first', x_value={'a':i, 'b':i}, y_value=first_input)


        # 予測
        #if i % 10 == 0:
        print
        print '##################### ', i
        predict_example_4(data_set, recogniter)

    plotter.show()
Exemplo n.º 12
0
def predict_example_3(fd, recogniter):
    """
    各層の統計的特徴を比較する.

    1. 各層のclassifier結果のgraph表示.
    2.

    """
    plotter    = Plotter()
    result = defaultdict(lambda: defaultdict(list))
    plotter.initialize({
        # 'selectivity_center':{
        #     'ylim': [0,100],
        #     'sub_title': recogniter.dest_resgion_data.keys() },
        # 'selectivity_outside':{
        #     'ylim': [0,100],
        #     'sub_title': recogniter.dest_resgion_data.keys() },
        'xy_value':{
            'ylim': [0,100],
            'sub_title': ['value']},
        'likelihood':{
            'ylim': [0,1],
            'sub_title': recogniter.dest_resgion_data.keys() },
        }, movable=False)

    for ftype in fd.function_list.keys():
        print ftype
        data = fd.get_data(ftype)
        for x, y in data:
            input_data = {
                    'xy_value': [x, y],
                    'x_value': x,
                    'y_value': y,
                    'ftype': None
                    }
            inferences = recogniter.run(input_data, learn=False)

            # print
            input_data['ftype'] = ftype
            recogniter.print_inferences(input_data, inferences)

            # for result summary
            for name in recogniter.dest_resgion_data.keys():
                tmp = inferences[ "classifier_" + name ]['likelihoodsDict'][ftype]
                result[name][ftype].append(tmp)

            # for plot
            plotter.write(title="xy_value", x_value={'value': x}, y_value={'value': y})
            tmp = {}
            for name in recogniter.dest_resgion_data.keys():
                class_name = "classifier_" + name
                tmp[name] = inferences[class_name]['likelihoodsDict'][ftype]
            plotter.write(title="likelihood", y_value=tmp)

        # # for plot
        # x_tmp = {}
        # y_tmp = {}
        # for name in recogniter.dest_resgion_data.keys():
        #     x_tmp[name] = recogniter.evaluation[name].get_selectivity()[ftype]['x']
        #     y_tmp[name] = recogniter.evaluation[name].get_selectivity()[ftype]['y']
        # plotter.add(title="selectivity_center", x_values=x_tmp, y_values=y_tmp)
        #
        # x_tmp2 = {}
        # y_tmp2 = {}
        # for name in recogniter.dest_resgion_data.keys():
        #     x_tmp2[name] = recogniter.evaluation_2[name].get_selectivity()[ftype]['x']
        #     y_tmp2[name] = recogniter.evaluation_2[name].get_selectivity()[ftype]['y']
        # plotter.add(title="selectivity_outside", x_values=x_tmp2, y_values=y_tmp2)

        plotter.show(save_dir='./docs/images/multi_layer/', file_name='each-layer-'+ftype+'.png')
        plotter.reset()


    # write result summary
    import numpy
    print '### result'
    for name, datas in result.items():
        print '#### ', name
        for title ,data in datas.items():
            print title , " : ",
            print numpy.mean(data)

    # print evaluation summary
    for name in recogniter.dest_resgion_data.keys():
        print '### ', name
        recogniter.evaluation[name].print_summary()
Exemplo n.º 13
0
def predict_example(fd, recogniter):
    """
    全ての関数から得たデータをnetwrokに入力, 関数を予測する.
    最終的に, 関数毎の平均正解率と入力に対する正解率を表示する.
    neuronの選択性が得られているかを表示.

    """
    plotter    = Plotter()
    result = defaultdict(list)
    plotter.initialize({
        'xy_value':{
            'ylim': [0,100],
            'sub_title': ['value']},
        'likelihood':{
            'ylim': [0,1],
            'sub_title': fd.function_list.keys()},
        }, movable=False)

    for ftype in fd.function_list.keys():
        print ftype
        data = fd.get_data(ftype)
        for x, y in data:
            input_data = {
                    'xy_value': [x, y],
                    'x_value': x,
                    'y_value': y,
                    'ftype': None
                    }
            inferences = recogniter.run(input_data, learn=False)


            # print
            input_data['ftype'] = ftype
            recogniter.print_inferences(input_data, inferences)

            # for result summary
            tmp = inferences[ "classifier_" + recogniter.selectivity]['likelihoodsDict'][ftype]
            result[ftype].append(tmp)

            # for plot
            plotter.write(title="xy_value", x_value={'value': x}, y_value={'value': y})
            plotter.write(title="likelihood", y_value=inferences[ "classifier_" + recogniter.selectivity]['likelihoodsDict'])

        plotter.show(save_dir='./docs/images/multi_layer/', file_name='2layer-'+ftype+'.png')
        plotter.reset()


    # write result summary
    import numpy
    print '### result'
    for title , data in result.items():
        print title , " : ",
        print numpy.mean(data)

    # print evaluation summary
    for name in recogniter.dest_resgion_data.keys():
        print '### ', name
        recogniter.evaluation[name].print_summary()