Esempio n. 1
0
    def fillLayoutFromDict(self,
                           configDict,
                           currentDict,
                           infoString,
                           prefix="",
                           nonStandardConfigs={}):
        for key, value in sorted(configDict.items()):
            self.vlayoutLeft.addWidget(QtGui.QLabel(prefix + str(key)))
            if isinstance(value, dict):
                from mmlf.resources.function_approximators.function_approximator \
                                        import FunctionApproximator
                from mmlf.resources.model.model import Model
                from mmlf.resources.planner.planner import Planner
                from mmlf.resources.policy_search.policy_search \
                                        import PolicySearch
                from mmlf.resources.policies.policy import Policy
                from mmlf.resources.optimization.optimizer import Optimizer
                from mmlf.resources.skill_discovery.skill_discovery \
                                        import SkillDiscovery
                entryDicts = {
                    "function_approximator":
                    FunctionApproximator.getFunctionApproximatorDict(),
                    "preferences_approximator":
                    FunctionApproximator.getFunctionApproximatorDict(),
                    "model":
                    Model.getModelDict(),
                    "planner":
                    Planner.getPlannerDict(),
                    "policy_search":
                    PolicySearch.getPolicySearchDict(),
                    "policy":
                    Policy.getPolicyDict(),
                    "optimizer":
                    Optimizer.getOptimizerDict(),
                    "skill_discovery":
                    SkillDiscovery.getSkillDiscoveryDict()
                }
                if key in entryDicts.keys():
                    comboBox = QtGui.QComboBox(self)
                    configureButton = QtGui.QPushButton("Configure")

                    config = MMLFModuleGUIConfig(value, entryDicts[key],
                                                 comboBox, configureButton,
                                                 self)
                    currentDict[key] = (
                        lambda config: lambda: config.getConfig())(config)

                    comboBox.setToolTip(self._searchTooltip(key, infoString))

                    hlayout = QtGui.QHBoxLayout()
                    hlayout.addWidget(comboBox)
                    hlayout.addWidget(configureButton)
                    self.vlayoutRight.addLayout(hlayout)
                else:
                    self.vlayoutRight.addWidget(QtGui.QLabel(""))
                    someDict = dict()
                    # Recursive call
                    self.fillLayoutFromDict(
                        value,
                        someDict,
                        infoString,
                        prefix=prefix + "\t",
                        nonStandardConfigs=nonStandardConfigs)
                    currentDict[key] = someDict
            elif key in nonStandardConfigs.keys():
                # this key should be handled differently
                currentDict[key] = value
                configureButton = QtGui.QPushButton("Configure")
                configureButton.setToolTip(self._searchTooltip(
                    key, infoString))

                def createFunction(currentDict, key, value):
                    def callbackFunction(config):
                        currentDict[key] = config

                    def configureNonStandardConfig():
                        config = nonStandardConfigs[key](value,
                                                         callbackFunction,
                                                         parent=self)
                        config.show()

                    return configureNonStandardConfig

                self.connect(configureButton, QtCore.SIGNAL('clicked()'),
                             createFunction(currentDict, key, value))

                self.vlayoutRight.addWidget(configureButton)
            elif value is True or value is False or value in ["True", "False"]:
                checkbox = QtGui.QCheckBox()
                if value in [True, "True"]:
                    checkbox.setChecked(True)
                checkbox.setToolTip(self._searchTooltip(key, infoString))
                self.vlayoutRight.addWidget(checkbox)
                currentDict[key] = (lambda func: lambda: func())(
                    checkbox.isChecked)
            else:
                lineEdit = QtGui.QLineEdit(str(value))
                lineEdit.setToolTip(self._searchTooltip(key, infoString))
                self.vlayoutRight.addWidget(lineEdit)
                currentDict[key] = (lambda func: lambda: func())(lineEdit.text)
Esempio n. 2
0
    def __init__(self, experimentResults, parent=None):
        super(StatisticalAnalysisWidget, self).__init__(parent)
        
        self.experimentResults = experimentResults
        
        # Statistical test
        self.TESTS = {'MannWhitney U-Test': lambda x, y: scipy.stats.mannwhitneyu(x,y)[1],
                      'Student t-test': lambda x, y: scipy.stats.ttest_ind(x,y)[1]/2}
                
        # Create combobox for selecting the metric
        metricsLabel = QtGui.QLabel("Metric")
        self.metricsComboBox = QtGui.QComboBox(self)
        self.metricsComboBox.addItems(self.experimentResults.metrics)
        
        # Text field for the aggregation function
        aggregationLabel = QtGui.QLabel("Aggregation") 
        self.aggregationFctEdit = QtGui.QLineEdit("lambda x: mean(x[:])")
        self.aggregationFctEdit.minimumSizeHint = lambda : QtCore.QSize(100,30)
        self.aggregationFctEdit.setToolTip("Function which maps a time series "
                                           "onto a single scalar value, which "
                                           "is then used as a sample in "
                                           "the statistical hypothesis testing."
                                           "The functions min, max, mean, and "
                                           "median may be used.")
        
        # Create combobox for selecting the test
        testLabel = QtGui.QLabel("Hypothesis test")
        self.testComboBox = QtGui.QComboBox(self)
        self.testComboBox.addItems(self.TESTS.keys()) 
        
        # Text field for the p-Value
        pValueLabel = QtGui.QLabel("p <") 
        self.pValueEdit = QtGui.QLineEdit("0.05")
        self.pValueEdit.minimumSizeHint = lambda : QtCore.QSize(100,30)
        self.pValueEdit.setToolTip("Significance level: The minimal p-Value "
                                   "which is required for something to be "
                                   "considered as significant.")
        
        # button for redoing the statistics for the current setting
        self.updateButton = QtGui.QPushButton("Update")
        self.connect(self.updateButton, QtCore.SIGNAL('clicked()'), 
                     self._analyze)
                
        # Create matplotlib widget
        plotWidget = QtGui.QWidget(self)
        plotWidget.setMinimumSize(500, 500)
 
        fig = Figure((5.0, 5.0), dpi=100)
        fig.subplots_adjust(0.2)
        self.canvas = FigureCanvas(fig)
        self.canvas.setParent(plotWidget)
        self.axis = fig.gca()
        
        # The table for statistics results
        self.significanceTable = QtGui.QTableWidget(self)
        
        # Do the analyzing once for the default values
        self._analyze()
        
        # Create layout
        layout = QtGui.QVBoxLayout()
        hlayout1 = QtGui.QHBoxLayout()
        hlayout1.addWidget(metricsLabel)
        hlayout1.addWidget(self.metricsComboBox)
        hlayout1.addWidget(aggregationLabel)
        hlayout1.addWidget(self.aggregationFctEdit)
        hlayout1.addWidget(testLabel)
        hlayout1.addWidget(self.testComboBox)
        hlayout1.addWidget(pValueLabel)
        hlayout1.addWidget(self.pValueEdit)
        hlayout1.addWidget(self.updateButton)
        hlayout2 = QtGui.QHBoxLayout()
        hlayout2.addWidget(plotWidget)
        hlayout2.addWidget(self.significanceTable)
        layout.addLayout(hlayout1)
        layout.addLayout(hlayout2)
        self.setLayout(layout)