Exemplo n.º 1
0
    def __init__(self, data, parent=None, liveplot=None):
        # Init Feature
        Feature.__init__(self,
                         'Cell Selection',
                         data,
                         parent,
                         liveplot,
                         display_name_label=False)

        self.data_manager = data
        self.data_manager.cell_selection = self

        self.setMinimumSize(350, 450)

        self.allowEditROI = True
        self.disabled_roi_handles = []
        self.preview_mode = True
        self.show_user_roi = False
        self.ellipse_mode = True
        self.update_on_ellipse_mode_change = True

        # data
        self.input = {'source': None, 'roi_ellipse_mode': None}
        self.output = {'cell': None, 'cell mean': None, 'roi': None}

        # view / plot
        self.imv = ImageView()
        self.imv.setMinimumHeight(450)
        self.layout.addWidget(self.imv)
        self.imv.view.mouseClickEvent = lambda ev: self.imvViewMouseClickEvent(
            self.imv.view, ev)
        self.imv.view.raiseContextMenu = lambda ev: self.imvViewRaiseContextMenu(
            self.imv.view, ev)
        self.imv.view.getContextMenus = lambda ev=None: self.imvViewGetContextMenus(
            self.imv.view, ev)

        self.imv.view.preview_mode = self.imv.view.menu.addAction(
            'live preview mode')
        self.imv.view.preview_mode.setCheckable(True)
        self.imv.view.preview_mode.setChecked(self.preview_mode)
        self.imv.view.preview_mode.triggered.connect(self.switchPreviewMode)

        self.imv.view.ellipse_mode = self.imv.view.menu.addAction(
            'ellipse mode')
        self.imv.view.ellipse_mode.setCheckable(True)
        self.imv.view.ellipse_mode.setChecked(self.ellipse_mode)
        self.connectEllipseMode()

        # methods
        self.addMethod('ROI', cs_roi_params, self.calculateROI)
        self.initMethodUI()
        self.initParametersUI()

        self.show()
        """
        the image must be displayed once such that the roicurve is created and can be shown
        even if the user loads a non-TIF source before he loads a TIF source.
        """
        self.imv.setImage(np.zeros((1, 10, 10)), xvals=np.arange(10))
        self.imv.clear()
Exemplo n.º 2
0
 def __init__(self, name: str, description: str, count_index: int):
     Feature.__init__(self,
                      name=name,
                      description=description,
                      count_index=count_index)
     self._amplitude_count = 0
     self._count = 0
Exemplo n.º 3
0
    def updateLivePlot(self):
        y = self.input['y']
        seconds_range = self.data.sources[
            self.data.source_selection].secondsRange()

        # threshold visualization
        self.liveplot.setData('minimal amplitude', seconds_range, self.th)

        # plotting the signal
        self.liveplot.setData('y', seconds_range, y)

        # plotting the train
        if self.output['train'] is not None and len(self.output['train']) > 0:
            diff = max(y) - min(y)
            train_height = diff / 6
            self.liveplot.setData('train', seconds_range,
                                  train_height * self.output['train'])
        else:
            # can not call self.undisplayPlots because that would undisplay other data too, like y and thresholds
            # this is why we undisplay the train manually
            self.liveplot.setData('train', [], [])
            # and then Feature.undisplayPlots method which cares about the compare plots
            Feature.undisplayPlots(self)

        if self.output['time'] is not None and self.output[
                'amplitude'] is not None:
            self.liveplot.setData(
                'train symbols',
                [seconds_range[t]
                 for t in self.output['time']], self.output['amplitude'])
        else:
            self.liveplot.setData('train symbols', [], [])
Exemplo n.º 4
0
    def __init__(self, data, parent=None, liveplot=None):

        # Init Feature
        Feature.__init__(self, 'Baseline', data, parent, liveplot)

        self.liveplot_container, self.liveplot = self.liveplot

        # data
        self.input = {'y': None, 'object_source': None}
        self.output = {'baseline': None, 'y': None}

        # methods
        # 1 Polynomial Fitting
        self.addMethod('Polynomial Fitting', bl_polynomial_fitting_params, self.polyFit)
        self.markerItems = []
        # 2 Asymmetric Least Squares
        self.addMethod('Asymmetric Least Squares', bl_asymmetric_ls_params, self.alsWrapper)
        # 3 Top Hat
        self.addMethod('Top Hat', bl_top_hat_params, self.topHatWrapper)
        # 4 Moving Average
        self.addMethod('Moving Average', bl_moving_average_params, self.movingAverageWrapper)

        self.activateFunc = self.showMarkers

        self.initMethodUI()
        self.initParametersUI()
Exemplo n.º 5
0
    def __init__(self, data, parent=None, liveplot=None):

        # Init Feature
        Feature.__init__(self, 'Background Subtraction', data, parent,
                         liveplot)

        # data
        self.input = {
            'y': None,
            'roi_params': None,
            'roi_image': None,
            'cell': None,
            'roi_ellipse_mode': None
        }
        self.output = {'background mean': None, 'y': None}

        self.imv = self.liveplot
        self.activateFunc = self.showGUI

        ## METHODS ##

        # 1 ROI Background Subtraction
        self.addMethod('ROI', bs_roi_params, self.ROIBackgroundSubtraction)

        # 2 Perisomatic Background Subtraction
        self.addMethod('Perisomatic', bs_perisomatic_params,
                       self.perisomaticBackgroundSubtraction)

        self.initMethodUI()
        self.initParametersUI()

        self.undisplayPlots()
Exemplo n.º 6
0
 def __init__(self, name: str, description: str, count_index: int):
     Feature.__init__(self,
                      name=name,
                      description=description,
                      count_index=count_index)
     self._wavelength_count = 0
     self._count = 0
Exemplo n.º 7
0
    def __init__(self, data, parent=None, liveplot=None):

        # Init Feature
        Feature.__init__(self, 'Event Shape', data, parent, liveplot)

        # data
        self.input = {
            'y': None,
            'burst_time': None,
            'spike_time': None,
            'object_source_frequency': None
        }
        self.output = {
            'shapes': None,
            'mean shape': None,
            'mean shape smoothed': None
        }

        ## METHODS ##

        # 1 Mean Amplitude
        self.addMethod('Spike Shape', es_params, self.spikeShapeCalculation)
        self.addMethod('Burst Shape', es_params, self.burstShapeCalculation)

        self.initMethodUI()
        self.initParametersUI()
Exemplo n.º 8
0
    def show(self):

        Feature.show(self)

        for method in self.methods.values():
            self.setButtonLabel(method)

        self.updateParametersUI()
Exemplo n.º 9
0
    def undisplayPlots(self):
        Feature.undisplayPlots(self)

        # hide the self rois
        for roi_name in ['roi', 'rect_roi']:
            roi_view = self.getMethod().getParametersGUI(roi_name)
            if roi_view is not None:
                roi_view.hide()
Exemplo n.º 10
0
 def undisplayPlots(self):
     Feature.undisplayPlots(self)
     self.liveplot.setData('minimal amplitude', [], [])
     self.liveplot.setData('minimal base', [], [])
     self.liveplot.setData('y', [], [])
     self.liveplot.setData('train', [], [])
     self.liveplot.setData('train start symbols', [], [])
     self.liveplot.setData('train end symbols', [], [])
Exemplo n.º 11
0
 def undisplayPlots(self):
     Feature.undisplayPlots(self)
     if self.input[self.input_data_name] is not None:
         names = [data['name'] for data in self.input[self.input_data_name]]
         n = len(names)
         for i in range(n - 1):
             for j in range(i + 1, n):
                 self.liveplot.setData(
                     'CC {} -- {}'.format(names[i], names[j]), [], [])
 def __init__(self, name: str, description: str, count_index: int):
     Feature.__init__(self,
                      name=name,
                      description=description,
                      count_index=count_index)
     self._latest_complete_lvl8 = None
     self._latest_complete_lvl16 = None
     self._latest_answer_Q0 = None
     self._latest_answer_Q2 = None
     self._answer_time = None
Exemplo n.º 13
0
    def __init__(self, data, parent=None, liveplot=None):

        # Init Feature
        Feature.__init__(self, 'Spike Detection', data, parent, liveplot)

        # data
        self.input = {
            'y': None,
            'object_source_frequency': None,
            'object_noise_std': None
        }
        self.output = {
            'time': None,
            'amplitude': None,
            'train': None,
            'spike frequency': None,
            'mean amplitude': None,
            'τDecay': None,
            'mean τDecay': None
        }

        # dialog for averages
        self.showBtn = QtWidgets.QPushButton('Show quantities')
        self.showBtn.clicked.connect(self.showQuantities)
        self.layout.addWidget(self.showBtn)
        self.dialog = QtWidgets.QDialog(self,
                                        flags=QtCore.Qt.WindowTitleHint
                                        | QtCore.Qt.WindowCloseButtonHint)
        self.dialog.setWindowTitle(self.name + ' -- Quantities')
        self.dialog_table = QtWidgets.QTableWidget(self.dialog)
        self.dialog_table.horizontalHeader().hide()
        self.dialog_table.verticalHeader().hide()
        self.dialog_table.horizontalHeader().setSectionResizeMode(
            QtWidgets.QHeaderView.ResizeToContents)
        self.dialog_table.setRowCount(3)
        self.dialog_table.setColumnCount(2)
        self.dialog_table.setItem(0, 0,
                                  QtWidgets.QTableWidgetItem('mean amplitude'))
        self.dialog_table.setItem(
            1, 0, QtWidgets.QTableWidgetItem('spike frequency (#spikes / s)'))
        self.dialog_table.setItem(2, 0,
                                  QtWidgets.QTableWidgetItem('mean τDecay'))
        self.dialog_layout = QtWidgets.QGridLayout(self.dialog)
        self.dialog.setLayout(self.dialog_layout)
        self.dialog.layout().addWidget(self.dialog_table)
        ## METHODS ##
        self.addMethod('Threshold', sd_params, self.spikeUpdate)

        self.initMethodUI()
        self.initParametersUI()
Exemplo n.º 14
0
    def __init__(self,
                 data,
                 name,
                 input_data_name,
                 parent=None,
                 liveplot=None,
                 step_mode=False):

        # Init Feature
        Feature.__init__(self, name, data, parent, liveplot)

        self.input_data_name = input_data_name
        self.step_mode = step_mode

        # data
        self.output = {
            'xrange': None,
            'correlation': None,
            'coefficient': None,
            'delay': None,
            'delay coefficient': None
        }

        self.showBtn = QtWidgets.QPushButton(
            'Show Correlation Coefficients and Main Lags', self)
        self.showBtn.clicked.connect(self.showCoefficients)
        self.layout.addWidget(self.showBtn)
        self.dialog = QtWidgets.QDialog(self,
                                        flags=QtCore.Qt.WindowTitleHint
                                        | QtCore.Qt.WindowCloseButtonHint)
        self.dialog.setWindowTitle(
            self.name + ' -- Correlation Coefficients and Main Lags')
        self.dialog_table_coefficients = QtWidgets.QTableWidget(self.dialog)
        self.dialog_table_delay = QtWidgets.QTableWidget(self.dialog)
        self.dialog_table_delay_coefficients = QtWidgets.QTableWidget(
            self.dialog)
        self.dialog_layout = QtWidgets.QGridLayout(self.dialog)
        self.dialog.setLayout(self.dialog_layout)
        self.dialog.layout().addWidget(
            QtWidgets.QLabel('Correlation Coefficients'))
        self.dialog.layout().addWidget(self.dialog_table_coefficients)
        self.dialog_mainlag_layout = QtWidgets.QLabel()
        self.dialog.layout().addWidget(self.dialog_mainlag_layout)
        self.dialog.layout().addWidget(self.dialog_table_delay)
        self.dialog_table_delay_coefficients_label = QtWidgets.QLabel(
            'Correlation Coefficients at Main Lags')
        self.dialog.layout().addWidget(
            self.dialog_table_delay_coefficients_label)
        self.dialog.layout().addWidget(self.dialog_table_delay_coefficients)
Exemplo n.º 15
0
    def __init__(self, data, parent=None, liveplot=None):
        
        Feature.__init__(self, 'Movement Correction', data, parent, liveplot, display_name_label=False)

        self.input = {'source':None}
        self.output = {'source':None}

        self.addMethod('Movement Correction', mc_params, self.movementCorrection)
        
        self.initMethodUI()
        self.initParametersUI()

        self.symmetric_diffeomorphic_option = 'Symmetric Diffeomorphic'

        self.options = [
            ('None [original image]', None),
            (self.symmetric_diffeomorphic_option, None),
            ('Translation', StackReg.TRANSLATION),
            ('Rigid Body', StackReg.RIGID_BODY),
            ('Scaled Rotation', StackReg.SCALED_ROTATION),
            ('Affine', StackReg.AFFINE)
        ]

        self.calculated = []

        compare_layout = QtWidgets.QGridLayout()
        compare_layout.setSpacing(0)
        compare_layout.setMargin(0)
        compare_layout_widget = QtWidgets.QWidget()
        self.layout.addWidget(compare_layout_widget)
        compare_layout_widget.setLayout(compare_layout)
        compare_layout.addWidget(QtWidgets.QLabel('Correction: '), 0, 0)
        compare_layout.addWidget(QtWidgets.QLabel('Compare to: '), 1, 0)
        self.correction_combobox = QtWidgets.QComboBox()
        compare_layout.addWidget(self.correction_combobox, 0, 1)
        self.compare_combobox = QtWidgets.QComboBox()
        compare_layout.addWidget(self.compare_combobox, 1, 1)

        for type_, _ in self.options:
            self.correction_combobox.addItem(type_)
            self.compare_combobox.addItem(type_)
            self.calculated.append(None)

        self._connectComboboxes()
Exemplo n.º 16
0
    def __init__(self, data, parent=None, liveplot=None):

        # Init Feature
        Feature.__init__(self, 'Power Spectrum', data, parent, liveplot)

        # data
        self.input = {'y': None, 'object_source_frequency': None}
        self.output = {
            'frequencies': None,
            'psd': None,
            'max power': None,
            'max power frequency': None
        }

        # methods
        self.addMethod('Fast Fourier Transform', fs_fft_params,
                       self.updateFourier)
        self.initMethodUI()
        self.initParametersUI()
Exemplo n.º 17
0
    def __init__(self, data, parent=None, liveplot=None):

        # Init Feature
        Feature.__init__(self, 'Smoothing', data, parent, liveplot)

         # data
        self.input = {'y':None, 'object_source_frequency':None}
        self.output = {'y':None, 'noise_std': None}

        # methods
        # 1 Savitzky Golay
        self.addMethod('Savitzky Golay', sg_savitzky_golay_params, self.updateSGData)
        # 2 Moving Average
        self.addMethod('Moving Average', sg_moving_average_params, self.movingAverageWrapper)
        # 3 Butterworth
        self.addMethod('Butterworth', sg_butterworth_params, self.butter_lowpass_filter_wrapper)
        # 4 Scaled Window Convolution
        self.addMethod('Scaled Window Convolution', sg_scaled_window_convolution_params, self.scaled_window_convolution)

        self.initMethodUI()
        self.initParametersUI()
Exemplo n.º 18
0
    def __init__(self, data, parent=None, liveplot=None):

        Feature.__init__(self,
                         'Adjust Frequency',
                         data,
                         parent,
                         liveplot,
                         display_name_label=False)

        self.input = {'y': None, 'object_source_af_params': None}
        self.output = {'y': None}

        self.addMethod('Nearest Neighbour', af_params,
                       self.nearestNeighbourWrapper)
        self.addMethod('Linear', af_params, self.linearWrapper)
        self.addMethod('Cubic', af_params, self.cubicWrapper)

        self.initMethodUI()
        self.initParametersUI()

        # disconnect the usual method because we dont want updates when the method is changed, only graphic updates.
        self.disconnectMethodCombo()
        self.method_combo.currentIndexChanged.connect(self.updateParametersUI)
Exemplo n.º 19
0
 def show(self):
     Feature.show(self)
     self.refreshROIVisibleState()
     self.imv.getRoiPlot().enableAutoRange(axis=pg.ViewBox.XYAxes,
                                           enable=True)
Exemplo n.º 20
0
 def undisplayPlots(self):
     Feature.undisplayPlots(self)
     self.liveplot.clear()
     self.clearMarkers()
Exemplo n.º 21
0
 def undisplayPlots(self):
     Feature.undisplayPlots(self)
     self.liveplot.setData('shape', [], [])
     self.liveplot.setData('smoothed shape', [], [])
Exemplo n.º 22
0
 def updateParametersUI(self):
     Feature.updateParametersUI(self)
     self.refreshROIVisibleState()
Exemplo n.º 23
0
experiments = {}

TimeEGreedy_formula = lambda t:1./np.sqrt(t)
TimeSoftmax_formula = lambda t:4*((1000-float(t))/1000) + 1

#### Experiment 1: 2 agents with no plan or heuristic
#####################################################

nr_of_agents = 2
learners = []
begins = [[7,4], [7,14]]

for i in range(nr_of_agents):
    e_greedy = EGreedy(epsilon=0.1)
    no_features = Feature(state_length=state_length)
    trace = Eligibility(lambda_=0.4, actions=actions, shape=(no_features.num_features(), len(actions)))
    learners.append(Sarsa(actions=actions, alpha=0.1, gamma=0.99, policy=e_greedy, features=no_features, trace=trace))

environment = RoomWorld(grid, population_size=nr_of_agents, ids=[l.id for l in learners], begins=begins, goal=[1,1])
experiment = MultiGeneric(max_steps=None, episodes=1000, trials=30, learners=learners, environment=environment)

no_plan = {'experiment': experiment, 'nr_of_agents': nr_of_agents, 'learners_per_agent': 1}
experiments['no_plan'] = no_plan

#### Experiment 2: 2 agents with joint-plan
###########################################

nr_of_agents = 2
learners = []
begins = [[7,4], [7,14]]
 def __init__(self, name:str, description:str, count_index:int):
     Feature.__init__(self, name=name, description=description, count_index=count_index)
     self._answer = None
 def __init__(self, name:str, description:str, count_index:int):
     Feature.__init__(self, name=name, description=description, count_index=count_index)
     self._offset_count = 0
     self._good_count = 0
Exemplo n.º 26
0
 def show(self):
     Feature.show(self)
     self.compare_combobox.setCurrentIndex(0)
     self.correction_combobox.setCurrentText(self.methods['Movement Correction'].getParameters()['correction'])
 def __init__(self, name:str, description:str):
     Feature.__init__(self, name=name, description=description, count_index=0)
Exemplo n.º 28
0
def dimensionReduction(X, y, source, mindf, maxdf, data=None):
    """
    perform dimension reduction

    :param X: text data
    :param y: classes (gender and age)
    :param source: twitter, facebook, or merged
    :param mindf: lower threshold for term frequency filter
    :param maxdf: upper threshold for term frequency filter
    :param data: features of the data
    """

    feature = Feature(X, y, source, data)
    # for freq in DOC_FREQS:
    mindf = str(mindf)
    maxdf = str(maxdf)
    for i in range(10, 61, 10):
        # i = 60
        gen_data = feature.getFeatures(selection=SelectPercentile(
            chi2, percentile=i),
                                       mode='Gender')
        gen_data.to_csv('data/' + source + '/chi2/gender_' + str(i) + '_' +
                        mindf + '-' + maxdf + '.csv')
        gen_data = feature.getFeatures(selection=SelectPercentile(
            chi2, percentile=i),
                                       mode='Age')
        gen_data.to_csv('data/' + source + '/chi2/age_' + str(i) + '_' +
                        mindf + '-' + maxdf + '.csv')
        gen_data = feature.getFeatures(selection=SelectPercentile(
            chi2, percentile=i),
                                       mode='Both')
        gen_data.to_csv('data/' + source + '/chi2/both_' + str(i) + '_' +
                        mindf + '-' + maxdf + '.csv')

    for i in range(100, 1001, 100):
        gen_data = feature.getFeatures(selection=TruncatedSVD(n_components=i),
                                       mode='Gender')
        gen_data.to_csv('data/' + source + '/svd/gender_' + str(i) + '_' +
                        mindf + '-' + maxdf + '.csv')
        gen_data = feature.getFeatures(selection=TruncatedSVD(n_components=i),
                                       mode='Age')
        gen_data.to_csv('data/' + source + '/svd/age_' + str(i) + '_' + mindf +
                        '-' + maxdf + '.csv')
        gen_data = feature.getFeatures(selection=TruncatedSVD(n_components=i),
                                       mode='Both')
        gen_data.to_csv('data/' + source + '/svd/both_' + str(i) + '_' +
                        mindf + '-' + maxdf + '.csv')

    for i in range(10, 61, 10):
        gen_data = feature.getFeatures(selection=SelectPercentile(
            score_func=mutual_info_classif, percentile=i),
                                       mode='Gender')
        gen_data.to_csv('data/' + source + '/mi/gender_' + str(i) + '_' +
                        mindf + '-' + maxdf + '.csv')
        gen_data = feature.getFeatures(selection=SelectPercentile(
            score_func=mutual_info_classif, percentile=i),
                                       mode='Age')
        gen_data.to_csv('data/' + source + '/mi/age_' + str(i) + '_' + mindf +
                        '-' + maxdf + '.csv')
        gen_data = feature.getFeatures(selection=SelectPercentile(
            score_func=mutual_info_classif, percentile=i),
                                       mode='Both')
        gen_data.to_csv('data/' + source + '/mi/both_' + str(i) + '_' + mindf +
                        '-' + maxdf + '.csv')

    gen_data = feature.useLasso(mode='Gender')
    gen_data.to_csv('data/' + source + '/lasso/gender_' + mindf + '-' + maxdf +
                    '.csv')
    gen_data = feature.useLasso(mode='Age')
    gen_data.to_csv('data/' + source + '/lasso/age_' + mindf + '-' + maxdf +
                    '.csv')
    gen_data = feature.useLasso(mode='Both')
    gen_data.to_csv('data/' + source + '/lasso/both_' + mindf + '-' + maxdf +
                    '.csv')
Exemplo n.º 29
0
 def show(self):
     Feature.show(self)
     self.bandpassStateChanged(update=False)
     self.instantaneousStateChanged(update=False)
Exemplo n.º 30
0
 def undisplayPlots(self):
     Feature.undisplayPlots(self)
     self.liveplot.setData('PSD', [], [])
Exemplo n.º 31
0
 def show(self):
     Feature.show(self)
     polynomial_fitting = self.methods['Polynomial Fitting']
     if self.getMethod() is polynomial_fitting and not polynomial_fitting.getParametersGUI('use_marker').isChecked(): 
         self.methods['Polynomial Fitting'].getParametersGUI('Add Marker').hide()
         self.layout.update()