Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
    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)