Пример #1
0
    def data(self, index, role):
        if not index.isValid():
            qVariant = QtCore.QVariant()
        elif role != QtCore.Qt.DisplayRole:
            qVariant = QtCore.QVariant()
        else:
            worldName, runNumber = sorted(
                self.runData[self.selectedMetric].keys())[index.row()]

            selectedData = self.runData[self.selectedMetric][worldName,
                                                             runNumber]
            if index.column() == 0:
                aggr = lambda x: float(
                    numpy.min(map(itemgetter(1), selectedData)))
            elif index.column() == 1:
                aggr = lambda x: float(
                    numpy.max(map(itemgetter(1), selectedData)))
            elif index.column() == 2:
                aggr = lambda x: float(
                    numpy.mean(map(itemgetter(1), selectedData)))
            elif index.column() == 3:
                aggr = lambda x: float(
                    numpy.std(map(itemgetter(1), selectedData)))
            elif index.column() == 4:
                aggr = lambda x: float(
                    numpy.median(map(itemgetter(1), selectedData)))
            elif index.column() == 5:
                aggr = lambda x: float(map(itemgetter(1), selectedData)[-1])
            elif index.column() == 6:
                aggr = lambda x: float(selectedData[-1][0])
            qVariant = QtCore.QVariant(aggr(selectedData))

        return qVariant
Пример #2
0
    def _update(self, name, time, value, worldName, runNumber):
        self.lock.acquire()

        changingLayout = (name == self.selectedMetric) \
                            and (worldName, runNumber) not in self.runData[name]
        if changingLayout:
            self.emit(QtCore.SIGNAL("layoutAboutToBeChanged()"))
        else:
            # Check if we have to chop off too long runs
            runLength = len(self.runData[name][(worldName, runNumber)])
            if runLength >= self.maxEpisodes:
                self.lock.release()
                return  # Ignore sample

        self.runData[name][(worldName, runNumber)].append((time, value))

        if changingLayout:
            self.verticalHeader = \
                ["%s Run %s" % (worldName, runNumber)
                    for worldName, runNumber in sorted(self.runData[name].keys())]
            self.emit(QtCore.SIGNAL("layoutChanged()"))

        if name == self.selectedMetric:
            runIndex = sorted(self.runData[name].keys()).index(
                (worldName, runNumber))
            self.emit(
                QtCore.SIGNAL(
                    'dataChanged(const QModelIndex &, const QModelIndex &)'),
                self.createIndex(runIndex, 0), self.createIndex(runIndex, 6))

        self.lock.release()
Пример #3
0
    def __init__(self, initialDict, entryDict, comboBox, configureButton,
                 parent):
        self.configDict = dict(initialDict)
        self.entryDict = entryDict
        if 'name' in self.configDict:
            self.selection = self.configDict.pop('name')
            self.selectionKey = 'name'
        elif 'method' in self.configDict:
            self.selection = self.configDict.pop('method')
            self.selectionKey = 'method'
        else:
            self.selection = self.configDict.pop('type')
            self.selectionKey = 'type'
        self.parent = parent

        entries = entryDict.keys()
        entries.remove(self.selection)
        entries = [self.selection] + entries
        comboBox.addItems(entries)

        parent.connect(comboBox, QtCore.SIGNAL('activated (const QString&)'),
                       self.selectionChanged)

        parent.connect(configureButton, QtCore.SIGNAL('clicked()'),
                       self.configure)

        # We have to evaluate the standard window once to get default config dict
        self._evaluateStandardWindow()
Пример #4
0
    def headerData(self, index, orientation, role):
        if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
            qVariant = QtCore.QVariant(self.horizontalHeader[index])
        elif orientation == QtCore.Qt.Vertical and role == QtCore.Qt.DisplayRole:
            qVariant = QtCore.QVariant(self.verticalHeader[index])
        else:
            qVariant = None

        return qVariant
Пример #5
0
    def __init__(self, parent=None, vlayout=None, worldConfigObject=None):
        self.parent = parent

        self.monitorConf = Monitor.DEFAULT_CONFIG_DICT

        self._environmentSelectionChanged(sorted(MMLF_ENVIRONMENTS.keys())[0])
        self._agentSelectionChanged(sorted(MMLF_AGENTS.keys())[0])

        # Environment Configuration
        environmentLabel = QtGui.QLabel("Environment")
        self.environmentComboBox = QtGui.QComboBox(self.parent)
        self.environmentComboBox.addItems(sorted(MMLF_ENVIRONMENTS.keys()))
        self.environmentComboBox.setToolTip(
            "Environment in which the agent will act")
        environmentConfigureButton = QtGui.QPushButton("Configure")

        if parent:  # Sometime we use this only for loading ...
            parent.connect(self.environmentComboBox,
                           QtCore.SIGNAL('activated (const QString&)'),
                           self._environmentSelectionChanged)
            parent.connect(environmentConfigureButton,
                           QtCore.SIGNAL('clicked()'),
                           self._configureEnvironment)

        # Agent Configuration
        agentLabel = QtGui.QLabel("Agent")
        self.agentComboBox = QtGui.QComboBox(self.parent)
        self._updateAvailableAgents(self.selectedEnvironment)
        self.agentComboBox.setToolTip("The learning agent")
        agentConfigureButton = QtGui.QPushButton("Configure")

        if parent:  # Sometimes we use this only for loading ...
            parent.connect(self.agentComboBox,
                           QtCore.SIGNAL('activated (const QString&)'),
                           self._agentSelectionChanged)
            parent.connect(agentConfigureButton, QtCore.SIGNAL('clicked()'),
                           self._configureAgent)

        # If we start with a non-default world configuration
        if worldConfigObject is not None:
            # We overwrite the default config
            self._initFromWorldConfigObject(worldConfigObject)

        if vlayout is not None:  # Sometimes we use this only for loading ...
            # Adding GUI elements to external vlayout
            self.hlayoutEnvironment = QtGui.QHBoxLayout()
            self.hlayoutEnvironment.addWidget(environmentLabel)
            self.hlayoutEnvironment.addWidget(self.environmentComboBox)
            self.hlayoutEnvironment.addWidget(environmentConfigureButton)

            self.hlayoutAgent = QtGui.QHBoxLayout()
            self.hlayoutAgent.addWidget(agentLabel)
            self.hlayoutAgent.addWidget(self.agentComboBox)
            self.hlayoutAgent.addWidget(agentConfigureButton)

            vlayout.addLayout(self.hlayoutEnvironment)
            vlayout.addLayout(self.hlayoutAgent)
Пример #6
0
    def headerData(self, index, orientation, role):
        self.lock.acquire()

        if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
            qVariant = QtCore.QVariant(self.horizontalHeader[index])
        elif orientation == QtCore.Qt.Vertical and role == QtCore.Qt.DisplayRole:
            qVariant = QtCore.QVariant(self.verticalHeader[index])
        else:
            qVariant = None

        self.lock.release()
        return qVariant
Пример #7
0
    def __init__(self, tableModel, parent):
        super(ExperimentViewer, self).__init__()
        
        self.parent = parent
        
        # set the table model
        self.tableModel = tableModel
               
        # Combobox to select metric (FloatStreamObservable) that is shown
        self.metricLabel = QtGui.QLabel("Metric")
        self.metricComboBox = QtGui.QComboBox(self)
        self.metricComboBox.addItems(self.tableModel.metrics)
        self.connect(self.metricComboBox,
                     QtCore.SIGNAL('activated (const QString&)'), 
                     self.tableModel.metricSelectionChanged)
        # Automatically update metric combobox when new metric observables
        # are created during runtime
        def addMetric(metric):
            self.metricComboBox.addItem(metric)
        self.tableModel.metricsObserver.append(addMetric)
        
        self.plotButton = QtGui.QPushButton("Visualize")
        self.connect(self.plotButton, QtCore.SIGNAL('clicked()'), 
                     self._plotResults)
        
        self.statisticsButton = QtGui.QPushButton("Statistics")
        self.connect(self.statisticsButton, QtCore.SIGNAL('clicked()'), 
                     self._analyzeStatistics)
        
        # create the view
        self.tableView = QtGui.QTableView()
        self.tableView.setModel(self.tableModel)
        self.tableView.setMinimumSize(400, 300) # set the minimum size
        self.tableView.setShowGrid(False) # hide grid

        # Start layouting ...
        self.topLineLayout = QtGui.QHBoxLayout()
        self.topLineLayout.addWidget(self.metricLabel)
        self.topLineLayout.addWidget(self.metricComboBox)
        self.topLineLayout.addWidget(self.plotButton)
        self.topLineLayout.addWidget(self.statisticsButton)

        self.layout = QtGui.QVBoxLayout() 
        self.layout.addLayout(self.topLineLayout)
        self.layout.addWidget(self.tableView) 
        self.setLayout(self.layout)
Пример #8
0
    def __init__(self, stateSpace):
        super(SeventeenAndFourValuefunctionViewer, self).__init__()

        self.stateSpace = stateSpace
        self.states = stateSpace["count"]["dimensionValues"]

        # Combo Box for selecting the observable
        self.comboBox = QtGui.QComboBox(self)
        self.stateActionValuesObservables = \
                OBSERVABLES.getAllObservablesOfType(StateActionValuesObservable)
        self.comboBox.addItems(
            map(lambda x: "%s" % x.title, self.stateActionValuesObservables))
        self.connect(self.comboBox, QtCore.SIGNAL('currentIndexChanged (int)'),
                     self._observableChanged)

        # Automatically update combobox when new float stream observables
        #  are created during runtime
        def updateComboBox(observable, action):
            self.comboBox.clear()
            self.stateActionValuesObservables = \
                    OBSERVABLES.getAllObservablesOfType(StateActionValuesObservable)
            self.comboBox.addItems(
                map(lambda x: "%s" % x.title,
                    self.stateActionValuesObservables))

        OBSERVABLES.addObserver(updateComboBox)

        # Create matplotlib widgets
        plotWidgetValueFunction = QtGui.QWidget(self)
        plotWidgetValueFunction.setMinimumSize(800, 500)

        self.figValueFunction = Figure((8.0, 5.0), dpi=100)
        #self.figValueFunction.subplots_adjust(left=0.01, bottom=0.04, right=0.99,
        #                               top= 0.95, wspace=0.05, hspace=0.11)
        self.axisValueFunction = self.figValueFunction.gca()
        self.canvasValueFunction = FigureCanvas(self.figValueFunction)
        self.canvasValueFunction.setParent(plotWidgetValueFunction)

        self.hlayout = QtGui.QHBoxLayout()
        self.hlayout.addWidget(plotWidgetValueFunction)
        self.hlayout.addWidget(self.comboBox)
        self.setLayout(self.hlayout)

        # Connect to observer (has to be the last thing!!)
        self.stateActionValuesObservableCallback = \
             lambda valueAccessFunction, actions: self.updateValues(valueAccessFunction, actions)
        if len(self.stateActionValuesObservables) > 0:
            # Show per default the first observable
            self.stateActionValuesObservable = self.stateActionValuesObservables[
                0]
            plotWidgetValueFunction.setWindowTitle(
                self.stateActionValuesObservable.title)

            self.stateActionValuesObservable.addObserver(
                self.stateActionValuesObservableCallback)
        else:
            self.stateActionValuesObservable = None
Пример #9
0
    def __init__(self,
                 possibleEntries,
                 initialList,
                 title,
                 closeCallback,
                 parent=None):
        super(ListEditorWindow, self).__init__(parent)

        self.setWindowTitle(title)
        self.closeCallback = closeCallback
        self.parent = parent

        self.currentList = []

        self.closeButton = QtGui.QPushButton("Save")
        self.connect(self.closeButton, QtCore.SIGNAL('clicked()'),
                     self.onClose)

        self.vlayout = QtGui.QVBoxLayout()

        self.checkboxes = []
        for entry in possibleEntries:
            checkbox = QtGui.QCheckBox(str(entry))
            if initialList is not None and entry in initialList:
                checkbox.setChecked(True)

            self.checkboxes.append(checkbox)
            self.vlayout.addWidget(checkbox)

        self.closeButton = QtGui.QPushButton("Save")
        self.connect(self.closeButton, QtCore.SIGNAL('clicked()'),
                     self.onClose)
        self.vlayout.addWidget(self.closeButton)

        centralWidget = QtGui.QWidget(self)
        centralWidget.setLayout(self.vlayout)
        self.setCentralWidget(centralWidget)
Пример #10
0
    def __init__(self,
                 initialConfigDict,
                 infoString,
                 closeCallback,
                 nonStandardConfigs={},
                 parent=None):
        super(ConfigEditorWidget, self).__init__(parent)

        self.infoString = infoString
        self.closeCallback = closeCallback
        self.parent = parent

        self.currentDict = {}

        self.vspace = QtGui.QLabel("")
        self.infoLabel = QtGui.QLabel("Info")
        self.infoLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.infoBox = QtGui.QTextBrowser(self)
        if infoString:
            self.infoBox.setText(infoString)
        else:
            self.infoBox.setText("Documentation missing")

        self.closeButton = QtGui.QPushButton("Save")
        self.connect(self.closeButton, QtCore.SIGNAL('clicked()'),
                     self.onClose)

        self.vlayoutLeft = QtGui.QVBoxLayout()
        self.vlayoutRight = QtGui.QVBoxLayout()

        self.fillLayoutFromDict(initialConfigDict,
                                self.currentDict,
                                infoString,
                                prefix="",
                                nonStandardConfigs=nonStandardConfigs)

        self.hlayout = QtGui.QHBoxLayout()
        self.hlayout.addLayout(self.vlayoutLeft)
        self.hlayout.addLayout(self.vlayoutRight)

        self.vlayout = QtGui.QVBoxLayout()
        self.vlayout.addLayout(self.hlayout)
        self.vlayout.addWidget(self.vspace)
        self.vlayout.addWidget(self.infoLabel)
        self.vlayout.addWidget(self.infoBox)
        self.vlayout.addWidget(self.closeButton)

        self.setLayout(self.vlayout)
Пример #11
0
    def __init__(self, parent=None):
        super(LogViewer, self).__init__(parent)

        # Log levels
        LEVELS = {
            'DEBUG': logging.DEBUG,
            'INFO': logging.INFO,
            'WARNING': logging.WARNING,
            'ERROR': logging.ERROR,
            'CRITICAL': logging.CRITICAL
        }

        # The actual logger object
        self.logger = logging.getLogger('')
        self.logger.setLevel(logging.INFO)

        # Create combobox for selecting the log level
        logLevelLabel = QtGui.QLabel("Log level")
        logLevelComboBox = QtGui.QComboBox(self)
        logLevelComboBox.addItems(
            ["DEBUG", "INFO", "WARNING", 'ERROR', 'CRITICAL'])

        def updateLogLevel(level):
            self.logger.setLevel(LEVELS[str(level)])

        self.connect(logLevelComboBox,
                     QtCore.SIGNAL('activated (const QString&)'),
                     updateLogLevel)

        # Create log text field
        logTextField = QtGui.QTextEdit()
        logHandler = QtStreamHandler(logTextField, self)
        self.logger.addHandler(logHandler)

        # Create layout
        layout = QtGui.QVBoxLayout()
        hlayout = QtGui.QHBoxLayout()
        hlayout.addWidget(logLevelLabel)
        hlayout.addWidget(logLevelComboBox)
        layout.addLayout(hlayout)
        layout.addWidget(logTextField)
        self.setLayout(layout)
Пример #12
0
    def __init__(self,
                 onCloseCallback=None,
                 parent=None,
                 worldConfigObject=None):
        super(WorldConfigEditorWindow, self).__init__(parent)

        self.onCloseCallback = onCloseCallback
        self.parent = parent

        self.setWindowTitle("MMLF World Configuration Editor")
        self.centralWidget = QtGui.QWidget()

        self.vlayout = QtGui.QVBoxLayout()
        self.worldConfigEditor = \
                    WorldConfigEditor(self, self.vlayout, worldConfigObject)

        self.saveButton = QtGui.QPushButton("Save")
        self.connect(self.saveButton, QtCore.SIGNAL('clicked()'),
                     self._onClose)
        self.vlayout.addWidget(self.saveButton)

        self.centralWidget.setLayout(self.vlayout)
        self.setCentralWidget(self.centralWidget)
    def __init__(self, pinballMazeEnv, stateSpace):        
        super(PinballMazeTrajectoryViewer, self).__init__()
        
        self.pinballMazeEnv = pinballMazeEnv
        
        self.dimensions = [stateSpace[dimName] for dimName in sorted(stateSpace.keys())]
        
        # The segments that are obtained while drawing is disabled. These
        # segment are drawn one drawing is reenabled 
        self.rememberedSegments = []
        
        # The eval function that can be used for coloring the trajectory
        self.evalFunction = None
        
        self.colorsCycle = cycle([(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0),
                                  (1.0, 1.0, 0.0), (0.0, 1.0, 1.0), (1.0, 0.0, 1.0),
                                  (0.5, 0.0, 0.0), (0.0, 0.5, 0.0), (0.0, 0.0, 0.5)])
        self.colors = defaultdict(lambda : self.colorsCycle.next())
        self.valueToColorMapping = dict()
        
        # Get required observables
        self.trajectoryObservable = \
                OBSERVABLES.getAllObservablesOfType(TrajectoryObservable)[0]
        
        # Create matplotlib widgets
        plotWidget = QtGui.QWidget(self)
        plotWidget.setMinimumSize(600, 500)
        plotWidget.setWindowTitle("Pinball Maze")
 
        self.fig = Figure((6.0, 5.0), dpi=100)
        self.axis = self.fig.gca()
        self.pinballMazeEnv.plotStateSpaceStructure(self.axis)
        self.canvas = FigureCanvas(self.fig)
        self.canvas.setParent(plotWidget)    
        self.canvas.draw()
        
        self.ballPatch = None
        self.linePatches = []
        
        # Add other elements to GUI           
        self.drawingEnabledCheckbox = \
                QtGui.QCheckBox("Drawing enabled", self)
        self.drawingEnabledCheckbox.setChecked(True)
        
        self.drawStyle = "Current Position"
        self.drawStyleLabel = QtGui.QLabel("Draw style")
        self.drawStyleComboBox = QtGui.QComboBox(self)
        self.drawStyleComboBox.addItems(["Current Position", "Last Episode", 
                                         "Online (All)"])
        self.connect(self.drawStyleComboBox,
                     QtCore.SIGNAL('activated (const QString&)'), 
                     self._drawStyleChanged)
                
        self.colorCriterion = "Action"
        self.colorCriterionLabel = QtGui.QLabel("Coloring of trajectory")
        self.colorCriterionComboBox = QtGui.QComboBox(self)
        self.colorCriterionComboBox.addItems(["Action", "Reward", "Q-Value"])
        self.connect(self.colorCriterionComboBox,
                     QtCore.SIGNAL('activated (const QString&)'), 
                     self._colorCriterionChanged) 
                
        # Legend of plot
        self.legendLabel = QtGui.QLabel("Legend:")
        self.legendWidget = QtGui.QListWidget(self)
        
        # Create layout
        self.hlayout = QtGui.QHBoxLayout()
        self.hlayout.addWidget(plotWidget)
        self.vlayout = QtGui.QVBoxLayout()
        self.vlayout.addWidget(self.drawingEnabledCheckbox)
        self.drawStyleLayout = QtGui.QHBoxLayout()
        self.drawStyleLayout.addWidget(self.drawStyleLabel)
        self.drawStyleLayout.addWidget(self.drawStyleComboBox)
        self.vlayout.addLayout(self.drawStyleLayout)
        self.coloringLayout = QtGui.QHBoxLayout()
        self.coloringLayout.addWidget(self.colorCriterionLabel)
        self.coloringLayout.addWidget(self.colorCriterionComboBox)
        self.vlayout.addLayout(self.coloringLayout)
        self.vlayout.addWidget(self.legendLabel)
        self.vlayout.addWidget(self.legendWidget)
        self.hlayout.addLayout(self.vlayout)
        self.setLayout(self.hlayout)
        
        # Connect to observer (has to be the last thing!!)
        self.trajectoryObservableCallback = \
             lambda *transition: self._updateSamples(*transition)
        self.trajectoryObservable.addObserver(self.trajectoryObservableCallback)
Пример #14
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)
Пример #15
0
    def __init__(self, stateSpace):        
        super(MountainCarPolicyViewer, self).__init__()
        self.stateSpace = stateSpace
        self.actions = []
        self.colors = ['r','g','b', 'c', 'y']
        
        self.lock = threading.Lock()
        
        # Add a combobox for selecting the policy observable
        self.policyObservableLabel = QtGui.QLabel("Policy Observable")
        self.policyObservableComboBox = QtGui.QComboBox(self)
        policyObservables = \
            OBSERVABLES.getAllObservablesOfType(FunctionOverStateSpaceObservable)
        self.policyObservableComboBox.addItems([policyObservable.title 
                                                 for policyObservable in policyObservables])
        self.selectedPolicyObservable = None
        if len(policyObservables) > 0:
            self.selectedPolicyObservable = policyObservables[0].title
        
        self.connect(self.policyObservableComboBox,
                     QtCore.SIGNAL('activated (const QString&)'), 
                     self._policyObservableChanged) 
        
        # Automatically update policy observable combobox when new observables 
        # are created during runtime
        def updatePolicyObservableBox(viewer, action):
            self.policyObservableComboBox.clear()
            policyObservables = OBSERVABLES.getAllObservablesOfType(FunctionOverStateSpaceObservable)
            self.policyObservableComboBox.addItems([policyObservable.title 
                                                for policyObservable in policyObservables])
            if len(policyObservables) > 0:
                self.selectedPolicyObservable = policyObservables[0].title
            else: 
                self.selectedPolicyObservable = None
            
        OBSERVABLES.addObserver(updatePolicyObservableBox)
        
        # Get trajectory observable which is required for informing about end of episode
        self.trajectoryObservable = \
                OBSERVABLES.getAllObservablesOfType(TrajectoryObservable)[0]
        self.episodeTerminated = False

        # Slider that controls the granularity of the plot-grid
        self.gridNodesPerDim = 25        
        self.gridNodesSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.gridNodesSlider.setValue(self.gridNodesPerDim)
        self.gridNodesSlider.setMinimum(0)
        self.gridNodesSlider.setMaximum(100)
        self.gridNodesSlider.setTickInterval(10)
        self.gridNodesSlider.setTickPosition(QtGui.QSlider.TicksBelow)
        self.connect(self.gridNodesSlider, QtCore.SIGNAL('sliderReleased()'), 
                     self._changeGridNodes)
        self.gridNodesLabel = QtGui.QLabel("Grid Nodes Per Dimension: %s" 
                                           % self.gridNodesPerDim )
                
        # Create matplotlib widgets
        plotWidget = QtGui.QWidget(self)
        plotWidget.setMinimumSize(600, 500)
        plotWidget.setWindowTitle("Policy")
 
        self.fig = Figure((6.0, 5.0), dpi=100)
        self.axis = self.fig.gca()
        self.canvas = FigureCanvas(self.fig)
        self.canvas.setParent(plotWidget)    
        
        # Small text in plot legend
        matplotlib.rcParams.update({'legend.fontsize': 6})
        
        self.hlayout = QtGui.QHBoxLayout()
        self.hlayout.addWidget(plotWidget)
        self.vlayout = QtGui.QVBoxLayout()
        self.vlayout.addWidget(self.policyObservableLabel)
        self.vlayout.addWidget(self.policyObservableComboBox)
        self.vlayout.addWidget(self.gridNodesLabel)
        self.vlayout.addWidget(self.gridNodesSlider)
        self.hlayout.addLayout(self.vlayout)
        
        self.setLayout(self.hlayout)
        
        # Connect to observer (has to be the last thing!!)
        self.trajectoryObservableCallback = \
             lambda *transition: self.updateSamples(*transition)
        self.trajectoryObservable.addObserver(self.trajectoryObservableCallback)
        
        self.policyObservable = None
        if self.selectedPolicyObservable:
            self.policyObservable = OBSERVABLES.getObservable(self.selectedPolicyObservable,
                                                              FunctionOverStateSpaceObservable)
            self.policyObservableCallback = \
                 lambda policyEvalFunction: self.updatePolicy(policyEvalFunction)
            self.policyObservable.addObserver(self.policyObservableCallback)
Пример #16
0
    def __init__(self, pinballMazeEnv, stateSpace):
        super(PinballMazeFunctionViewer, self).__init__()

        self.pinballMazeEnv = pinballMazeEnv
        self.stateSpace = stateSpace
        self.actions = []

        self.updateCounter = 0
        self.updatePlotNow = False
        self.evalFunction = None

        self.lock = threading.Lock()

        # Create matplotlib widgets
        plotWidget = QtGui.QWidget(self)
        plotWidget.setMinimumSize(600, 500)
        plotWidget.setWindowTitle("Pinball Maze")

        self.fig = Figure((6.0, 5.0), dpi=100)
        self.axis = self.fig.gca()
        self.pinballMazeEnv.plotStateSpaceStructure(self.axis)
        self.canvas = FigureCanvas(self.fig)
        self.canvas.setParent(plotWidget)
        self.canvas.draw()

        self.plottedPatches = []

        # Add a combobox for selecting the function over state space that is observed
        self.selectedFunctionObservable = None
        self.functionObservableLabel = QtGui.QLabel(
            "Function over State Space")
        self.functionObservableComboBox = QtGui.QComboBox(self)
        functionObservables = OBSERVABLES.getAllObservablesOfType(
            FunctionOverStateSpaceObservable)
        self.functionObservableComboBox.addItems([
            functionObservable.title
            for functionObservable in functionObservables
        ])
        if len(functionObservables) > 0:
            self.selectedFunctionObservable = functionObservables[0].title

        self.connect(self.functionObservableComboBox,
                     QtCore.SIGNAL('activated (const QString&)'),
                     self._functionObservableChanged)

        # Automatically update funtion observable combobox when new observables
        # are created during runtime
        def updateFunctionObservableBox(viewer, action):
            self.functionObservableComboBox.clear()
            functionObservables = \
                OBSERVABLES.getAllObservablesOfType(FunctionOverStateSpaceObservable)
            self.functionObservableComboBox.addItems([
                functionObservable.title
                for functionObservable in functionObservables
            ])
            if len(functionObservables) > 0:
                self.selectedFunctionObservable = functionObservables[0].title

        OBSERVABLES.addObserver(updateFunctionObservableBox)

        # Slider that controls the granularity of the plot-grid
        self.gridNodesPerDim = 50
        self.gridNodesSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.gridNodesSlider.setValue(self.gridNodesPerDim)
        self.gridNodesSlider.setMinimum(0)
        self.gridNodesSlider.setMaximum(100)
        self.gridNodesSlider.setTickInterval(10)
        self.gridNodesSlider.setTickPosition(QtGui.QSlider.TicksBelow)
        self.connect(self.gridNodesSlider, QtCore.SIGNAL('sliderReleased()'),
                     self._changeGridNodes)
        self.gridNodesLabel = QtGui.QLabel("Grid Nodes Per Dimension: %s" %
                                           self.gridNodesPerDim)

        # Slider that controls the frequency of update the plot
        self.updateFrequency = 0.0
        self.updateFrequencySlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.updateFrequencySlider.setValue(int(self.updateFrequency * 100))
        self.updateFrequencySlider.setMinimum(0)
        self.updateFrequencySlider.setMaximum(100)
        self.updateFrequencySlider.setTickInterval(0.1)
        self.updateFrequencySlider.setTickPosition(QtGui.QSlider.TicksBelow)
        self.connect(self.updateFrequencySlider,
                     QtCore.SIGNAL('sliderReleased()'),
                     self._changeUpdateFrequency)
        self.updateFrequencyLabel = QtGui.QLabel("UpdateFrequency: %s" %
                                                 self.updateFrequency)

        # Button to enforce update of plot
        self.updatePlotButton = QtGui.QPushButton("Update Plot")
        self.connect(self.updatePlotButton, QtCore.SIGNAL('clicked()'),
                     self._updatePlot)

        # Chosen xvel and yvel values
        self.xVel = 0.5
        self.xVelSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.xVelSlider.setValue(int(self.xVel * 10))
        self.xVelSlider.setMinimum(0)
        self.xVelSlider.setMaximum(10)
        self.xVelSlider.setTickInterval(1)
        self.xVelSlider.setTickPosition(QtGui.QSlider.TicksBelow)
        self.connect(self.xVelSlider, QtCore.SIGNAL('sliderReleased()'),
                     self._changeXVel)
        self.xVelLabel = QtGui.QLabel("xvel value: %s" % self.xVel)

        self.yVel = 0.5
        self.yVelSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.yVelSlider.setValue(int(self.yVel * 10))
        self.yVelSlider.setMinimum(0)
        self.yVelSlider.setMaximum(10)
        self.yVelSlider.setTickInterval(1)
        self.yVelSlider.setTickPosition(QtGui.QSlider.TicksBelow)
        self.connect(self.yVelSlider, QtCore.SIGNAL('sliderReleased()'),
                     self._changeYVel)
        self.yVelLabel = QtGui.QLabel("yvel value: %s" % self.xVel)

        # Legend of plot
        self.legendLabel = QtGui.QLabel("Legend:")
        self.legendWidget = QtGui.QListWidget(self)

        self.hlayout = QtGui.QHBoxLayout()
        self.hlayout.addWidget(plotWidget)
        self.vlayout = QtGui.QVBoxLayout()
        self.functionObservableLayout = QtGui.QHBoxLayout()
        self.functionObservableLayout.addWidget(self.functionObservableLabel)
        self.functionObservableLayout.addWidget(
            self.functionObservableComboBox)
        self.vlayout.addLayout(self.functionObservableLayout)
        self.gridNodesLayout = QtGui.QHBoxLayout()
        self.gridNodesLayout.addWidget(self.gridNodesLabel)
        self.gridNodesLayout.addWidget(self.gridNodesSlider)
        self.vlayout.addLayout(self.gridNodesLayout)
        self.updateFrequencyLayout = QtGui.QHBoxLayout()
        self.updateFrequencyLayout.addWidget(self.updateFrequencyLabel)
        self.updateFrequencyLayout.addWidget(self.updateFrequencySlider)
        self.vlayout.addLayout(self.updateFrequencyLayout)
        self.vlayout.addWidget(self.updatePlotButton)
        self.xVelLayout = QtGui.QHBoxLayout()
        self.xVelLayout.addWidget(self.xVelLabel)
        self.xVelLayout.addWidget(self.xVelSlider)
        self.vlayout.addLayout(self.xVelLayout)
        self.yVelLayout = QtGui.QHBoxLayout()
        self.yVelLayout.addWidget(self.yVelLabel)
        self.yVelLayout.addWidget(self.yVelSlider)
        self.vlayout.addLayout(self.yVelLayout)
        self.vlayout.addWidget(self.legendLabel)
        self.vlayout.addWidget(self.legendWidget)
        self.hlayout.addLayout(self.vlayout)
        self.setLayout(self.hlayout)

        # Connect to observer (has to be the last thing!!)
        self.functionObservable = None
        if self.selectedFunctionObservable:
            self.functionObservable = \
                    OBSERVABLES.getObservable(self.selectedFunctionObservable,
                                              FunctionOverStateSpaceObservable)
            self.functionObservableCallback = \
                 lambda evalFunction: self._updateFunction(evalFunction)
            self.functionObservable.addObserver(
                self.functionObservableCallback)
Пример #17
0
    def __init__(self, stateSpace):        
        super(TrajectoryViewer, self).__init__()
        
        self.stateSpace = stateSpace
        
        # Define colors for plotting
        self.colors = itertools.cycle(['g', 'b', 'c', 'm', 'k', 'y'])
                
        self.plotLines = deque()
        
        # Combo Boxes for selecting displaced state space dimensions
        self.comboBox1 = QtGui.QComboBox(self)
        self.comboBox1.addItems(sorted(stateSpace.keys()))
        self.comboBox2 = QtGui.QComboBox(self)
        self.comboBox2.addItems(sorted(stateSpace.keys()))
        self.comboBox2.setCurrentIndex(1)
        self.dimension1 = sorted(self.stateSpace.keys())[0]
        self.dimension2 = sorted(self.stateSpace.keys())[1]
        self.connect(self.comboBox1, QtCore.SIGNAL('currentIndexChanged (int)'), 
                     self._dimension1Changed)
        self.connect(self.comboBox2, QtCore.SIGNAL('currentIndexChanged (int)'), 
                     self._dimension2Changed)
        
        # Slider for controlling the number of Trajectories
        self.maxLines = 5
        self.numberTrajectoriesSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.numberTrajectoriesSlider.setValue(self.maxLines)
        self.numberTrajectoriesSlider.setMinimum(1)
        self.numberTrajectoriesSlider.setMaximum(20)
        self.numberTrajectoriesSlider.setTickInterval(5)
        self.numberTrajectoriesSlider.setTickPosition(QtGui.QSlider.TicksBelow)
        
        self.connect(self.numberTrajectoriesSlider, QtCore.SIGNAL('sliderReleased()'), 
                     self._changeNumTrajectories)
        
        # Checkbox for dis-/enabling trajectory plotting
        self.plottingEnabled = True
        self.enabledCheckBox = QtGui.QCheckBox("Plotting Enabled")
        self.enabledCheckBox.setChecked(self.plottingEnabled)
        self.connect(self.enabledCheckBox, QtCore.SIGNAL('stateChanged(int)'), 
                     self._enablingPlotting)
        
        # Some labels
        self.dimension1Label = QtGui.QLabel("Dimension X Axis")
        self.dimension2Label = QtGui.QLabel("Dimension Y Axis")
        self.numTrajectoriesLabel = QtGui.QLabel("Trajectories shown")
        
        # Create matplotlib widgets
        plotWidgetTrajectory = QtGui.QWidget(self)
        plotWidgetTrajectory.setMinimumSize(800, 500)
 
        self.figTrajectory = Figure((8.0, 5.0), dpi=100)
        self.axisTrajectory = self.figTrajectory .gca()
        self.canvasTrajectory = FigureCanvas(self.figTrajectory)
        self.canvasTrajectory .setParent(plotWidgetTrajectory )
        
        # Initialize plotting
        self._reinitializePlot()
        
        # Create layout
        self.vlayout = QtGui.QVBoxLayout()
        self.hlayout1 = QtGui.QHBoxLayout()
        self.hlayout1.addWidget(self.dimension1Label)
        self.hlayout1.addWidget(self.comboBox1)
        self.hlayout2 = QtGui.QHBoxLayout()
        self.hlayout2.addWidget(self.dimension2Label)
        self.hlayout2.addWidget(self.comboBox2)
        self.hlayout3 = QtGui.QHBoxLayout()
        self.hlayout3.addWidget(self.numTrajectoriesLabel)
        self.hlayout3.addWidget(self.numberTrajectoriesSlider)
        
        self.vlayout.addLayout(self.hlayout1)
        self.vlayout.addLayout(self.hlayout2)
        self.vlayout.addLayout(self.hlayout3)
        self.vlayout.addWidget(self.enabledCheckBox)
        
        self.hlayout = QtGui.QHBoxLayout()
        self.hlayout.addWidget(plotWidgetTrajectory)
        self.hlayout.addLayout(self.vlayout)
        self.setLayout(self.hlayout)
        
        # Connect to trajectory observable
        self.trajectoryObservable = \
                OBSERVABLES.getAllObservablesOfType(TrajectoryObservable)[0]
        self.trajectoryObservableCallback = \
             lambda *transition: self.addTransition(*transition)
        self.trajectoryObservable.addObserver(self.trajectoryObservableCallback)
Пример #18
0
    def __init__(self, maze, stateSpace):
        super(Maze2DFunctionViewer, self).__init__()

        self.maze = maze
        self.stateSpace = stateSpace

        self.updateCounter = 0
        self.updatePlotNow = False
        self.evalFunction = None

        self.lock = threading.Lock()

        # Create matplotlib widgets
        plotWidget = QtGui.QWidget(self)
        plotWidget.setMinimumSize(600, 500)
        plotWidget.setWindowTitle("Maze2D")

        self.fig = Figure((6.0, 5.0), dpi=100)
        self.axis = self.fig.gca()
        self.axis.clear()
        self.maze.drawIntoAxis(self.axis)
        self.canvas = FigureCanvas(self.fig)
        self.canvas.setParent(plotWidget)
        self.canvas.draw()

        self.plottedPatches = []

        # Add a combobox for selecting the function over state space that is observed
        self.selectedFunctionObservable = None
        self.functionObservableLabel = QtGui.QLabel(
            "Function over State Space")
        self.functionObservableComboBox = QtGui.QComboBox(self)
        functionObservables = OBSERVABLES.getAllObservablesOfType(
            FunctionOverStateSpaceObservable)
        stateActionValueObservables = \
                OBSERVABLES.getAllObservablesOfType(StateActionValuesObservable)
        functionObservables.extend(stateActionValueObservables)
        self.functionObservableComboBox.addItems([
            functionObservable.title
            for functionObservable in functionObservables
        ])
        if len(functionObservables) > 0:
            self.selectedFunctionObservable = functionObservables[0].title

        self.connect(self.functionObservableComboBox,
                     QtCore.SIGNAL('activated (const QString&)'),
                     self._functionObservableChanged)

        # Automatically update funtion observable combobox when new observables
        # are created during runtime
        def updateFunctionObservableBox(viewer, action):
            self.functionObservableComboBox.clear()
            functionObservables = \
                OBSERVABLES.getAllObservablesOfType(FunctionOverStateSpaceObservable)
            stateActionValueObservables = \
                OBSERVABLES.getAllObservablesOfType(StateActionValuesObservable)
            functionObservables.extend(stateActionValueObservables)
            self.functionObservableComboBox.addItems([
                functionObservable.title
                for functionObservable in functionObservables
            ])
            if self.selectedFunctionObservable is None \
                    and len(functionObservables) > 0:
                self.selectedFunctionObservable = functionObservables[0].title
            else:
                # Let combobox still show the selected observable
                index = self.functionObservableComboBox.findText(
                    self.selectedFunctionObservable)
                if index != -1:
                    self.functionObservableComboBox.setCurrentIndex(index)

        OBSERVABLES.addObserver(updateFunctionObservableBox)

        # Add a combobox for for selecting the suboption that is used when
        # a StateActionValuesObservable is observed
        self.selectedSuboption = None
        self.suboptionLabel = QtGui.QLabel("Suboption")
        self.suboptionComboBox = QtGui.QComboBox(self)

        # Slider that controls the frequency of update the plot
        self.updateFrequency = 0.0
        self.updateFrequencySlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.updateFrequencySlider.setValue(int(self.updateFrequency * 100))
        self.updateFrequencySlider.setMinimum(0)
        self.updateFrequencySlider.setMaximum(100)
        self.updateFrequencySlider.setTickInterval(0.1)
        self.updateFrequencySlider.setTickPosition(QtGui.QSlider.TicksBelow)
        self.connect(self.updateFrequencySlider,
                     QtCore.SIGNAL('sliderReleased()'),
                     self._changeUpdateFrequency)
        self.updateFrequencyLabel = QtGui.QLabel("UpdateFrequency: %s" %
                                                 self.updateFrequency)

        # Button to enforce update of plot
        self.updatePlotButton = QtGui.QPushButton("Update Plot")
        self.connect(self.updatePlotButton, QtCore.SIGNAL('clicked()'),
                     self._updatePlot)

        # Legend of plot
        self.legendLabel = QtGui.QLabel("Legend:")
        self.legendWidget = QtGui.QListWidget(self)

        self.hlayout = QtGui.QHBoxLayout()
        self.hlayout.addWidget(plotWidget)
        self.vlayout = QtGui.QVBoxLayout()
        self.functionObservableLayout = QtGui.QHBoxLayout()
        self.functionObservableLayout.addWidget(self.functionObservableLabel)
        self.functionObservableLayout.addWidget(
            self.functionObservableComboBox)
        self.vlayout.addLayout(self.functionObservableLayout)
        self.suboptionLayout = QtGui.QHBoxLayout()
        self.suboptionLayout.addWidget(self.suboptionLabel)
        self.suboptionLayout.addWidget(self.suboptionComboBox)
        self.vlayout.addLayout(self.suboptionLayout)
        self.updateFrequencyLayout = QtGui.QHBoxLayout()
        self.updateFrequencyLayout.addWidget(self.updateFrequencyLabel)
        self.updateFrequencyLayout.addWidget(self.updateFrequencySlider)
        self.vlayout.addLayout(self.updateFrequencyLayout)
        self.vlayout.addWidget(self.updatePlotButton)
        self.vlayout.addWidget(self.legendLabel)
        self.vlayout.addWidget(self.legendWidget)
        self.hlayout.addLayout(self.vlayout)
        self.setLayout(self.hlayout)

        # Connect to observer (has to be the last thing!!)
        self.functionObservable = None
        if self.selectedFunctionObservable is not None:
            self._functionObservableChanged(self.selectedFunctionObservable)
Пример #19
0
    def __init__(self, tableModel, parent):  
        super(PlotExperimentWindow, self).__init__(parent)
            
        self.tableModel = tableModel
        # Colors used for different configurations in plots
        self.colors = cycle(["b", "g", "r", "c", "m", "y", "k"])
        self.colorMapping = defaultdict(lambda : self.colors.next())
        # The length of the moving window average 
        self.mwaSize = 2**0
        # Whether we plot each run separately or only their mean
        self.linePlotTypes = ["Each Run", "Average"]
        self.linePlot = self.linePlotTypes[0]
        
        # The central widget
        self.centralWidget = QtGui.QWidget(self)
        
        # Create matplotlib widget
        self.plotWidget = QtGui.QWidget(self.centralWidget)
        self.plotWidget.setMinimumSize(800, 500)
 
        self.fig = Figure((8.0, 5.0), dpi=100)
        self.canvas = FigureCanvas(self.fig)
        self.canvas.setParent(self.plotWidget)
        self.axis = self.fig.gca()
        
        self.mplToolbar = NavigationToolbar(self.canvas, self.centralWidget)
        
        self.mwaLabel = QtGui.QLabel("Moving Window Average: %s" % self.mwaSize)        
        # Slider for controlling the moving average window
        self.mwaSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.mwaSlider.setValue(0)
        self.mwaSlider.setMinimum(0)
        self.mwaSlider.setMaximum(10)
        self.mwaSlider.setTickInterval(10)
        self.mwaSlider.setTickPosition(QtGui.QSlider.TicksBelow)
        
        self.connect(self.mwaSlider, QtCore.SIGNAL('sliderReleased()'), 
                     self._changeMWA)
        
        self.lineLabel = QtGui.QLabel("Plot of agent: ")
        # Combo Box for selecting the observable
        self.lineComboBox = QtGui.QComboBox(self)
        self.lineComboBox.addItems(["Each Run", "Average"])
        self.connect(self.lineComboBox, QtCore.SIGNAL('currentIndexChanged (int)'), 
                     self._linePlotChanged)
    
        # Add a button for replotting
        self.replotButton = QtGui.QPushButton("Update")
        self.connect(self.replotButton, QtCore.SIGNAL('clicked()'), 
                     self._plot)
        
        # Add a button for saving a plot
        self.saveButton = QtGui.QPushButton("Save")
        self.connect(self.saveButton, QtCore.SIGNAL('clicked()'), 
                     self._save)
        
        # Set layout
        self.topLinelayout = QtGui.QHBoxLayout()
        self.topLinelayout.addWidget(self.mwaLabel)
        self.topLinelayout.addWidget(self.mwaSlider)
        self.topLinelayout.addWidget(self.lineLabel)
        self.topLinelayout.addWidget(self.lineComboBox)
        self.topLinelayout.addWidget(self.replotButton)
        self.topLinelayout.addWidget(self.saveButton)
        self.vlayout = QtGui.QVBoxLayout()
        self.vlayout.addLayout(self.topLinelayout)
        self.vlayout.addWidget(self.plotWidget)
        self.vlayout.addWidget(self.mplToolbar)
        self.centralWidget.setLayout(self.vlayout)
        
        self.setCentralWidget(self.centralWidget)
        self.setWindowTitle("Current experiment's results")
        
        # Plot the results once upon creation
        self._plot()
Пример #20
0
 def metricSelectionChanged(self, selectedMetric):
     self.selectedMetric = str(selectedMetric)
     self.emit(QtCore.SIGNAL("layoutAboutToBeChanged()"))
     self.emit(QtCore.SIGNAL("layoutChanged()"))
Пример #21
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)
Пример #22
0
    def __init__(self, maze, stateSpace, actions):
        super(Maze2DDetailedViewer, self).__init__()

        self.maze = maze
        self.stateSpace = stateSpace
        self.actions = actions

        self.samples = defaultdict(lambda: 0)
        self.valueAccessFunction = None

        self.redrawRequested = False

        # Get required observables
        self.trajectoryObservable = \
                OBSERVABLES.getAllObservablesOfType(TrajectoryObservable)[0]
        self.stateActionValuesObservables = \
                OBSERVABLES.getAllObservablesOfType(StateActionValuesObservable)

        # Combo Box for selecting the observable
        self.observableLabel = QtGui.QLabel("Observable")
        self.comboBox = QtGui.QComboBox(self)
        self.comboBox.addItems(
            map(lambda x: "%s" % x.title, self.stateActionValuesObservables))
        self.connect(self.comboBox, QtCore.SIGNAL('currentIndexChanged (int)'),
                     self._observableChanged)

        # Automatically update combobox when new float stream observables
        #  are created during runtime
        def updateComboBox(observable, action):
            self.comboBox.clear()
            self.stateActionValuesObservables = \
                    OBSERVABLES.getAllObservablesOfType(StateActionValuesObservable)
            self.comboBox.addItems(
                map(lambda x: "%s" % x.title,
                    self.stateActionValuesObservables))

        OBSERVABLES.addObserver(updateComboBox)

        # Combo Box for selecting the updateFrequency
        self.updateFreqLabel = QtGui.QLabel("Update")
        self.updateComboBox = QtGui.QComboBox(self)
        self.updateComboBox.addItems(["Every Episode", "Every Step"])

        # Create matplotlib widgets
        plotWidgetPolicy = QtGui.QWidget(self)
        plotWidgetPolicy.setMinimumSize(300, 400)
        plotWidgetPolicy.setWindowTitle("Policy")

        self.figPolicy = Figure((3.0, 4.0), dpi=100)
        self.figPolicy.subplots_adjust(left=0.01,
                                       bottom=0.01,
                                       right=0.99,
                                       top=0.99,
                                       wspace=0.05,
                                       hspace=0.11)

        self.canvasPolicy = FigureCanvas(self.figPolicy)
        self.canvasPolicy.setParent(plotWidgetPolicy)

        ax = self.figPolicy.gca()
        ax.clear()
        self.maze.drawIntoAxis(ax)

        self.plotWidgetValueFunction = dict()
        self.figValueFunction = dict()
        self.canvasValueFunction = dict()
        for index, action in enumerate(self.actions):
            self.plotWidgetValueFunction[action] = QtGui.QWidget(self)
            self.plotWidgetValueFunction[action].setMinimumSize(300, 400)
            self.plotWidgetValueFunction[action].setWindowTitle(str(action))

            self.figValueFunction[action] = Figure((3.0, 4.0), dpi=100)
            self.figValueFunction[action].subplots_adjust(left=0.01,
                                                          bottom=0.01,
                                                          right=0.99,
                                                          top=0.99,
                                                          wspace=0.05,
                                                          hspace=0.11)

            self.canvasValueFunction[action] = FigureCanvas(
                self.figValueFunction[action])
            self.canvasValueFunction[action].setParent(
                self.plotWidgetValueFunction[action])

            ax = self.figValueFunction[action].gca()
            ax.clear()
            self.maze.drawIntoAxis(ax)

        self.textInstances = dict()
        self.arrowInstances = []

        self.canvasPolicy.draw()
        for index, action in enumerate(self.actions):
            self.canvasValueFunction[action].draw()

        self.mdiArea = QtGui.QMdiArea(self)
        self.mdiArea.addSubWindow(plotWidgetPolicy)
        for index, action in enumerate(self.actions):
            self.mdiArea.addSubWindow(self.plotWidgetValueFunction[action])
        self.vlayout = QtGui.QVBoxLayout()
        self.vlayout.addWidget(self.mdiArea)
        self.hlayout = QtGui.QHBoxLayout()
        self.hlayout.addWidget(self.observableLabel)
        self.hlayout.addWidget(self.comboBox)
        self.hlayout.addWidget(self.updateFreqLabel)
        self.hlayout.addWidget(self.updateComboBox)
        self.vlayout.addLayout(self.hlayout)
        self.setLayout(self.vlayout)

        # Connect to observer (has to be the last thing!!)
        self.trajectoryObservableCallback = \
             lambda *transition: self.updateSamples(*transition)
        self.trajectoryObservable.addObserver(
            self.trajectoryObservableCallback)

        self.stateActionValuesObservableCallback = \
             lambda valueAccessFunction, actions: self.updateValues(valueAccessFunction, actions)
        if len(self.stateActionValuesObservables) > 0:
            # Show per default the first observable
            self.stateActionValuesObservable = self.stateActionValuesObservables[
                0]

            self.stateActionValuesObservable.addObserver(
                self.stateActionValuesObservableCallback)
        else:
            self.stateActionValuesObservable = None
Пример #23
0
    def __init__(self):
        super(FloatStreamViewer, self).__init__()

        # Create matplotlib widget
        plotWidget = QtGui.QWidget(self)
        plotWidget.setMinimumSize(800, 500)

        fig = Figure((8.0, 5.0), dpi=100)
        self.canvas = FigureCanvas(fig)
        self.canvas.setParent(plotWidget)
        self.axis = fig.gca()

        # Local container for displayed values
        self.values = deque()
        self.times = deque()

        # Combo Box for selecting the observable
        self.comboBox = QtGui.QComboBox(self)
        self.floatStreamObservables = \
                OBSERVABLES.getAllObservablesOfType(FloatStreamObservable)
        self.comboBox.addItems(
            map(lambda x: "%s" % x.title, self.floatStreamObservables))
        self.connect(self.comboBox, QtCore.SIGNAL('currentIndexChanged (int)'),
                     self._observableChanged)

        # Automatically update combobox when new float stream observables
        #  are created during runtime
        def updateComboBox(observable, action):
            self.comboBox.clear()
            self.floatStreamObservables = \
                    OBSERVABLES.getAllObservablesOfType(FloatStreamObservable)
            self.comboBox.addItems(
                map(lambda x: "%s" % x.title, self.floatStreamObservables))

        OBSERVABLES.addObserver(updateComboBox)

        # The number of values from the observable that are remembered
        self.windowSize = 64

        # Slider for controlling the window size
        self.windowSizeSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.windowSizeSlider.setValue(numpy.log2(self.windowSize))
        self.windowSizeSlider.setMinimum(0)
        self.windowSizeSlider.setMaximum(15)
        self.windowSizeSlider.setTickInterval(1)
        self.windowSizeSlider.setTickPosition(QtGui.QSlider.TicksBelow)

        self.connect(self.windowSizeSlider, QtCore.SIGNAL('sliderReleased()'),
                     self._changeWindowSize)

        self.windowSizeLabel = QtGui.QLabel("WindowSize: %s" % self.windowSize)

        # The length of the moving window average
        self.mwaSize = 10

        # Slider for controlling the moving average window
        self.mwaSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.mwaSlider.setValue(self.mwaSize)
        self.mwaSlider.setMinimum(1)
        self.mwaSlider.setMaximum(50)
        self.mwaSlider.setTickInterval(10)
        self.mwaSlider.setTickPosition(QtGui.QSlider.TicksBelow)

        self.connect(self.mwaSlider, QtCore.SIGNAL('sliderReleased()'),
                     self._changeMWA)

        self.mwaLabel = QtGui.QLabel("Moving Window Average : %s" %
                                     self.mwaSize)

        # Create layout
        self.vlayout = QtGui.QVBoxLayout()
        self.vlayout.addWidget(self.comboBox)
        self.vlayout.addWidget(self.windowSizeSlider)
        self.vlayout.addWidget(self.windowSizeLabel)
        self.vlayout.addWidget(self.mwaSlider)
        self.vlayout.addWidget(self.mwaLabel)

        self.hlayout = QtGui.QHBoxLayout()
        self.hlayout.addWidget(plotWidget)
        self.hlayout.addLayout(self.vlayout)

        self.setLayout(self.hlayout)

        # Handling connecting to observable
        self.observableCallback = lambda time, value, *args: self.update(
            time, value)
        if len(self.floatStreamObservables) > 0:
            # Show per default the first observable
            self.observable = self.floatStreamObservables[0]
            # Connect to observer (has to be the last thing!!)
            self.observable.addObserver(self.observableCallback)
        else:
            self.observable = None