コード例 #1
0
    def initUI(self):

        self.M = 1
        self.NUM = 10
        self.Lambda = 0

        self.graph1 = GraphWindow(self)
        self.graph1.setGeometry(0, 0, 600, 600)
        self.graph1.setXRange(0, 1)
        self.graph1.setYRange(-1.3, 1.3)
        self.graph2 = GraphWindow(self)
        self.graph2.setGeometry(600, 0, 600, 600)
        self.graph2.setXRange(0, 1)
        self.graph2.setYRange(-1.3, 1.3)

        self.sineX, self.sineY = Sine()
        self.xs, self.ts = list(
            map(np.array,
                randomSine(num=self.NUM, sigma2=0.3, regularIntervals=False)))
        self.graph1.show()
        self.graph2.show()

        self.plot()

        self.slM = SliderLabel(self, func=self.changeValueM, tag="M=")
        self.slM.setGeometry(20, 0, 280, 30)
        self.slN = SliderLabel(self, func=self.changeValueNum, tag="NUM=")
        self.slN.setGeometry(20, 30, 280, 30)
        self.slL = SliderLabel(self, func=self.changeValueLambda, tag="lnλ=")
        self.slL.setGeometry(20, 60, 280, 30)

        self.show()
コード例 #2
0
class RealSimpleGrapher(LabradServer):
    """ Methods for controlling graphing """

    name = "Grapher"

    @inlineCallbacks
    def initServer(self):
        self.listeners = set()
        self.gui = GraphWindow(reactor)
        self.gui.setWindowTitle('Real Simple Grapher')
        self.dv = yield self.client.data_vault

    def make_dataset(self, dataset_location):
        cxt = self.client.context()
        ds = Dataset(self.dv, cxt, dataset_location, reactor)
        return ds

    def do_plot(self, dataset_location, graph, send_to_current):
        if (graph != 'current') and (send_to_current == True):
            # add the plot to the Current tab as well as an additional
            # specified tab for later examination
            ds = self.make_dataset(dataset_location)
            self.gui.graphDict['current'].add_dataset(ds)
        ds = self.make_dataset(dataset_location)
        self.gui.graphDict[graph].add_dataset(ds)

#tabindex = self.gui.indexOf(self.gui.tabDict[graph])
#self.gui.setCurrentIndex(tabindex)

    @setting(1,
             'Plot',
             dataset_location=['(*s, s)', '(*s, i)'],
             graph='s',
             send_to_current='b',
             returns='')
    def plot(self, c, dataset_location, graph, send_to_current=True):
        self.do_plot(dataset_location, graph, send_to_current)

    @setting(2,
             'Plot with axis',
             dataset_location=['(*s, s)', '(*s, i)'],
             graph='s',
             axis='*v',
             send_to_current='b',
             returns='')
    def plot_with_axis(self,
                       c,
                       dataset_location,
                       graph,
                       axis,
                       send_to_current=True):
        minim = min(axis)
        maxim = max(axis)
        if (graph != 'current') and (send_to_current == True):
            self.gui.graphDict['current'].set_xlimits(
                [minim[minim.units], maxim[maxim.units]])
        self.gui.graphDict[graph].set_xlimits(
            [minim[minim.units], maxim[maxim.units]])
        #self.gui.graphDict[graph].set_xlimits([min(axis).value, max(axis).value])
        self.do_plot(dataset_location, graph, send_to_current)
コード例 #3
0
    def initUI(self):

        self.graphT = GraphWindow(self, title="Student's t Distribution")
        self.graphT.setGeometry(0, 0, 600, 600)
        self.graphT.setXRange(MIN, MAX)
        self.graphT.setYRange(0, 1)

        self.btnData = QPushButton('Add Data',self)
        self.btnData.setGeometry(20, 0, 120, 30)
        self.btnData.clicked.connect(self.clickedAddData)

        self.btnNoiseData = QPushButton('Add Noise Data',self)
        self.btnNoiseData.setGeometry(20, 30, 120, 30)
        self.btnNoiseData.clicked.connect(self.clickedAddNoiseData)

        self.btnReset = QPushButton('Reset Data',self)
        self.btnReset.setGeometry(150, 0, 120, 30)
        self.btnReset.clicked.connect(self.clickedResetData)


        self.slNy = SliderLabel(self, func=self.changeValueNy, tag="ν=")
        self.slNy.setGeometry(20, 60, 1000, 30)
        self.slLambda = SliderLabel(self, func=self.changeValueLambda, tag="λ=")
        self.slLambda.setGeometry(20, 90, 1000, 30)

        self.setGeometry(620, 200, 300, 200)
        self.show()
        self.xs = []
        self.lambda_ = 1
        self.ny = 10

        self.ValueChanged()
コード例 #4
0
    def initUI(self):

        self.graph = GraphWindow(self)
        self.graph.setGeometry(0, 0, 600, 600)
        self.graph.setXRange(0, 1)
        self.graph.setYRange(0, 12)

        self.slBeta = SliderLabel(self, func=self.changeValueBeta, tag="beta=")
        self.slBeta.setGeometry(20, 40, 1000, 30)

        self.slW = SliderLabel(self, func=self.changeValueWin, tag="win :")
        self.slW.setGeometry(20, 70, 1000, 30)

        self.slL = SliderLabel(self, func=self.changeValueLose, tag="lose :")
        self.slL.setGeometry(20, 100, 1000, 30)

        self.labelMode = QLabel(self)
        self.labelMode.setGeometry(200, 128, 80, 30)
        self.labelMode.setStyleSheet('color: red')

        self.labelRate = QLabel(self)
        self.labelRate.setGeometry(200, 158, 80, 30)
        self.labelRate.setStyleSheet('color: blue')

        self.setGeometry(700, 300, 280, 200)
        self.setWindowTitle('BayesianInference')
        self.show()

        self.beta = 2
        self.win = 0
        self.lose = 0
        self.ValueChanged()
コード例 #5
0
 def initServer(self):
     self.listeners = set()
     print 'trying to make gui'
     self.gui = GraphWindow(reactor)
     self.gui.setWindowTitle('Real Simple Grapher')
     print 'done making gui'
     self.dv = yield self.client.data_vault
コード例 #6
0
    def initUI(self):

        self.Lambda = 0
        self.BASISFUNCTION = GaussianBasisFunctions

        self.graph1 = GraphWindow(self, "Variance Graph")
        self.graph1.setGeometry(0, 0, 600, 600)
        self.graph1.setXRange(0, 1)
        self.graph1.setYRange(-1.3, 1.3)
        self.graph2 = GraphWindow(self, "Bias Graph")
        self.graph2.setGeometry(600, 0, 600, 600)
        self.graph2.setXRange(0, 1)
        self.graph2.setYRange(-1.3, 1.3)

        self.sineX, self.sineY = Sine()

        self.data = []
        for i in range(NUM):
            xs, ts = randomSine(num=25,sigma2=0.09,regularIntervals=True)
            self.data.append([xs, ts])

        self.graph1.show()
        self.graph2.show()
        self.plot()

        self.slL = SliderLabel(self, func=self.changeValueLambda, tag="lnλ=")
        self.slL.setGeometry(20, 0, 280, 30)
        self.show()
コード例 #7
0
ファイル: HistoryWindow.py プロジェクト: rromero83/openDemo
 def graph(self):        
     
     indexes = self.listView.selectionModel().selectedIndexes()
     if len(indexes)==0:
         QtGui.QMessageBox.information(None,u"Informació",u"Ha de seleccionar un element de la llista") 
     else:
         isCheckedTemp = self.checkBoxTemp.isChecked()
         isCheckedHum = self.checkBoxHum.isChecked()
         if isCheckedTemp or isCheckedHum:
             token=None
             for index in indexes:            
                 token= self.diccDescripToken.get(str(index.data().toString()))       
             if token is not None:
                 year=self.dateEdit.date().year()
                 month= self.dateEdit.date().month()                     
                 day= self.dateEdit.date().day()-1
                 tz=timezone('Europe/Madrid')    
                 hourUtcOffset=int(str(tz.utcoffset(datetime.datetime(year,month,day))).split(':')[0])
                 dayNext=self.checkDate(str(day+1))
                 month= self.checkDate(str(month))
                 day=self.checkDate(str(day))
                 min=str(24-hourUtcOffset)
                 graphWindow= GraphWindow(token, isCheckedTemp,isCheckedHum,str(year)+month+day+min+'0000' ,str(year)+month+dayNext+min+'0000',hourUtcOffset )
                 graphWindow.show()
                 graphWindow.exec_()
             else:
                 QtGui.QMessageBox.warning(None,"Error",u"No es pot mostrar el gràfic") 
         else:
             QtGui.QMessageBox.information(None,u"Informació",u"Ha de seleccionar Temperatura i/o Humitat")
コード例 #8
0
    def initServer(self):
        self.listeners = set()
        print 'trying to make gui'
        self.gui = GraphWindow(reactor)
	self.gui.setWindowTitle('Real Simple Grapher')
        print 'done making gui'
        self.dv = yield self.client.data_vault
コード例 #9
0
    def initUI(self):

        self.graphGamma = GraphWindow(self, title="Gamma Distribution")
        self.graphGamma.setGeometry(0, 0, 600, 600)
        self.graphGamma.setYRange(0, 2)

        self.sl_a = SliderLabel(self, func=self.ValueChangedA, tag="a=")
        self.sl_a.setGeometry(20, 40, 300, 30)

        self.sl_b = SliderLabel(self, func=self.ValueChangedB, tag="b=")
        self.sl_b.setGeometry(20, 70, 300, 30)

        self.a = 1
        self.b = 1
        self.show()
        self.ValueChanged()
コード例 #10
0
class RealSimpleGrapher(LabradServer):
    
    """ Methods for controlling graphing """

    name = "Grapher"

    @inlineCallbacks
    def initServer(self):
        self.listeners = set()
        print 'trying to make gui'
        self.gui = GraphWindow(reactor)
	self.gui.setWindowTitle('Real Simple Grapher')
        print 'done making gui'
        self.dv = yield self.client.data_vault

    def make_dataset(self, dataset_location):
        cxt = self.client.context()
        ds = Dataset(self.dv, cxt, dataset_location, reactor)
        return ds

    def do_plot(self, dataset_location, graph, send_to_current):
        if (graph != 'current') and (send_to_current == True):
            # add the plot to the Current tab as well as an additional
            # specified tab for later examination
            ds = self.make_dataset(dataset_location)
            self.gui.graphDict['current'].add_dataset(ds)
        ds = self.make_dataset(dataset_location)
        self.gui.graphDict[graph].add_dataset(ds)
	#tabindex = self.gui.indexOf(self.gui.tabDict[graph])
	#self.gui.setCurrentIndex(tabindex)
        
    @setting(1, 'Plot', dataset_location = ['(*s, s)', '(*s, i)'], graph = 's', send_to_current = 'b' ,returns = '')
    def plot(self, c,  dataset_location, graph, send_to_current = True):
        self.do_plot(dataset_location, graph, send_to_current)

    @setting(2, 'Plot with axis', dataset_location = ['(*s, s)', '(*s, i)'], graph = 's', axis = '*v', send_to_current = 'b', returns = '')
    def plot_with_axis(self, c, dataset_location, graph, axis, send_to_current = True):
        minim = min(axis)
        maxim = max(axis)
        if (graph != 'current') and (send_to_current == True):
            self.gui.graphDict['current'].set_xlimits([minim[minim.units], maxim[maxim.units]])
        self.gui.graphDict[graph].set_xlimits([minim[minim.units], maxim[maxim.units]])
        #self.gui.graphDict[graph].set_xlimits([min(axis).value, max(axis).value])
        self.do_plot(dataset_location, graph, send_to_current)
コード例 #11
0
class GammaDistributionGraph(MYQWidget):

    NAME = "Gamma DistributionGraph"

    def __init__(self):
        super().__init__("Gamma DistributionGraph")

        self.initUI()

    def initUI(self):

        self.graphGamma = GraphWindow(self, title="Gamma Distribution")
        self.graphGamma.setGeometry(0, 0, 600, 600)
        self.graphGamma.setYRange(0, 2)

        self.sl_a = SliderLabel(self, func=self.ValueChangedA, tag="a=")
        self.sl_a.setGeometry(20, 40, 300, 30)

        self.sl_b = SliderLabel(self, func=self.ValueChangedB, tag="b=")
        self.sl_b.setGeometry(20, 70, 300, 30)

        self.a = 1
        self.b = 1
        self.show()
        self.ValueChanged()

    def ValueChanged(self):
        lambdas, ps = Gam(self.a, self.b)
        self.graphGamma.clear()
        self.graphGamma.setValue(lambdas, ps)
        self.graphGamma.show()
        pass

    def ValueChangedA(self, value):
        self.a = value / 99 * 9.9 + 0.1
        self.ValueChanged()
        return str('%02.2f' % self.a)

    def ValueChangedB(self, value):
        self.b = value / 99 * 9.9 + 0.1
        self.ValueChanged()
        return str('%02.2f' % self.b)
コード例 #12
0
ファイル: BetaFunction.py プロジェクト: tnyo43/PRMLstudy
    def initUI(self):

        self.a, self.b = 3, 3

        self.slA = SliderLabel(self, func=self.changeValueA, tag="a=")
        self.slA.setGeometry(20, 0, 250, 30)
        self.slB = SliderLabel(self, func=self.changeValueB, tag="b=")
        self.slB.setGeometry(20, 30, 250, 30)

        self.graph = GraphWindow(self)
        self.graph.setGeometry(0, 0, 600, 600)
        self.graph.show()
        self.graph.setXRange(0, 1)
        self.graph.setYRange(0, 4)

        self.labelE = QLabel(self)
        self.labelE.setGeometry(100, 60, 80, 30)
        self.labelE.setStyleSheet('color: red')

        self.setWindowTitle('Beta Function')
        self.show()
コード例 #13
0
    def initUI(self):

        self.m = 5
        self.sigma2 = 1

        self.graphVonMises1 = GraphWindow(self, title=self.name)
        self.graphVonMises1.setGeometry(0, 0, 600, 600)
        self.graphVonMises1.setXRange(-1.3, 1.3)
        self.graphVonMises1.setYRange(-1.3, 1.3)

        self.graphVonMises2 = GraphWindow(self, title="von Mises Distribution")
        self.graphVonMises2.setGeometry(0, 0, 600, 600)
        self.graphVonMises2.setXRange(0, 2 * np.pi)
        self.graphVonMises2.setYRange(0, 1.5)

        self.btnData = QPushButton('Add Data', self)
        self.btnData.setGeometry(20, 0, 120, 30)
        self.btnData.clicked.connect(self.clickedAddData)

        self.btnReset = QPushButton('Reset Data', self)
        self.btnReset.setGeometry(150, 0, 120, 30)
        self.btnReset.clicked.connect(self.clickedResetData)

        self.slSigma2 = SliderLabel(self,
                                    func=self.changeValueSigma2,
                                    tag="σ2=")
        self.slSigma2.setGeometry(20, 30, 300, 30)

        self.label_mML = QLabel(self)
        self.label_mML.setGeometry(300, 30, 80, 30)

        self.xs = []
        for i in range(1000):
            x = randn(MU, self.sigma2) % (2 * np.pi)
            self.xs.append(x)

        self.show()
        self.slSigma2.setValue(56)
コード例 #14
0
ファイル: NonParametric.py プロジェクト: tnyo43/PRMLstudy
    def initUI(self):

        self.xs, self.ps = sampleDistribution()
        self.Delta = 1 / 25
        self.h = 0
        self.K = 10
        self.data = sampleData()

        self.graphHist = GraphWindow(self, title="Sample Data")
        self.graphHist.setGeometry(0, 0, 600, 600)
        self.graphHist.setXRange(0, 1)
        self.graphHist.setYRange(0, 5)
        self.graphHist.show()

        self.graphKernelDensity = GraphWindow(
            self, title="Kernel Density Estimation")
        self.graphKernelDensity.setGeometry(600, 0, 600, 600)
        self.graphKernelDensity.setXRange(0, 1)
        self.graphKernelDensity.setYRange(0, 5)
        self.graphKernelDensity.show()

        self.graphKNear = GraphWindow(self, title="K nearest neighbor method")
        self.graphKNear.setGeometry(300, 300, 600, 600)
        self.graphKNear.setXRange(0, 1)
        self.graphKNear.setYRange(0, 5)
        self.graphKNear.show()

        self.slDelta = SliderLabel(self, func=self.changeValueDelta, tag="Δ=")
        self.slDelta.setGeometry(20, 0, 250, 30)
        self.slH = SliderLabel(self, func=self.changeValueH, tag="h=")
        self.slH.setGeometry(20, 30, 250, 30)
        self.slK = SliderLabel(self, func=self.changeValueK, tag="K=")
        self.slK.setGeometry(20, 60, 250, 30)

        self.show()
        self.changeValue()
コード例 #15
0
class CurveFittingGraph(MyQWidget):

    NAME = "Curve Fiting"

    def __init__(self):
        super().__init__("Curve Fiting")

        self.initUI()

    def initUI(self):

        self.M = 1
        self.NUM = 10
        self.Lambda = 0

        self.graph1 = GraphWindow(self)
        self.graph1.setGeometry(0, 0, 600, 600)
        self.graph1.setXRange(0, 1)
        self.graph1.setYRange(-1.3, 1.3)
        self.graph2 = GraphWindow(self)
        self.graph2.setGeometry(600, 0, 600, 600)
        self.graph2.setXRange(0, 1)
        self.graph2.setYRange(-1.3, 1.3)

        self.sineX, self.sineY = Sine()
        self.xs, self.ts = list(
            map(np.array,
                randomSine(num=self.NUM, sigma2=0.3, regularIntervals=False)))
        self.graph1.show()
        self.graph2.show()

        self.plot()

        self.slM = SliderLabel(self, func=self.changeValueM, tag="M=")
        self.slM.setGeometry(20, 0, 280, 30)
        self.slN = SliderLabel(self, func=self.changeValueNum, tag="NUM=")
        self.slN.setGeometry(20, 30, 280, 30)
        self.slL = SliderLabel(self, func=self.changeValueLambda, tag="lnλ=")
        self.slL.setGeometry(20, 60, 280, 30)

        self.show()

    def changeValueM(self, value):
        m = int(value / 99 * 24 + 1)
        if m < self.NUM:
            self.M = m
            self.plot()
        return str(self.M)

    def changeValueNum(self, value):
        n = int(value + 2)
        if n > self.M:
            self.NUM = n
            self.xs, self.ts = list(
                map(
                    np.array,
                    randomSine(num=self.NUM,
                               sigma2=0.3,
                               regularIntervals=False)))
            self.plot()
        return str(self.NUM)

    def changeValueLambda(self, value):
        l = (value / 99 * 30 - 20)
        self.Lambda = np.exp(l)
        self.plot()
        return str('%02.1f' % l)

    def plot(self):
        self.graph1.clear()
        self.graph1.setValue(self.xs, self.ts, line=False)
        self.graph1.setValue(self.sineX, self.sineY, color='b')
        self.graph2.clear()
        self.graph2.setValue(self.xs, self.ts, line=False)
        self.graph2.setValue(self.sineX, self.sineY, color='b')

        ws1 = SumOfSquareError(self.xs, self.ts, self.M)
        ys = [model(x, ws1, self.M) for x in self.sineX]
        self.graph1.setValue(self.sineX, ys, color='r')
        ws2 = shinkage(self.xs, self.ts, self.M, self.Lambda)
        ys = [model(x, ws2, self.M) for x in self.sineX]
        self.graph2.setValue(self.sineX, ys, color='r')
コード例 #16
0
ファイル: BetaFunction.py プロジェクト: tnyo43/PRMLstudy
class BetaFunctionGraph(MyQWidget):

    NAME = "Beta Distribution"

    def __init__(self):
        super().__init__("Beta Distribution")

        self.initUI()
        self.beta = 0

    def initUI(self):

        self.a, self.b = 3, 3

        self.slA = SliderLabel(self, func=self.changeValueA, tag="a=")
        self.slA.setGeometry(20, 0, 250, 30)
        self.slB = SliderLabel(self, func=self.changeValueB, tag="b=")
        self.slB.setGeometry(20, 30, 250, 30)

        self.graph = GraphWindow(self)
        self.graph.setGeometry(0, 0, 600, 600)
        self.graph.show()
        self.graph.setXRange(0, 1)
        self.graph.setYRange(0, 4)

        self.labelE = QLabel(self)
        self.labelE.setGeometry(100, 60, 80, 30)
        self.labelE.setStyleSheet('color: red')

        self.setWindowTitle('Beta Function')
        self.show()

    def changeValue(self):
        xs, ys = p(self.a, self.b)
        E = self.a / (self.a + self.b)
        self.graph.clear()
        self.graph.setValue(xs, ys, 'b')
        self.graph.setValue([E, E], [-1, 10], 'r')
        self.graph.show()

        self.labelE.setText('E[μ]=' + str('%01.2f' % E))

    def changeValueA(self, value):
        self.a = value / 10 + 0.1
        self.changeValue()
        return str('%02.1f' % self.a)

    def changeValueB(self, value):
        self.b = value / 10 + 0.1
        self.changeValue()
        return str('%02.1f' % self.b)
コード例 #17
0
 def showGraph(self):
     print('showing graph')
     self.graphWindow = GraphWindow(self)
     self.graphWindow.show()
     self.ViewGraph.setEnabled(False)
コード例 #18
0
class LiveTab(QMainWindow):
    def __init__(self, *args, **kwargs):
        super(LiveTab, self).__init__(*args, **kwargs)
        uic.loadUi(os.path.join(sys.path[0], 'UI/MainWindow.ui'), self)

        # self.ViewGraph.setEnabled(False) # Enabled when there is enough data
        self.setFocus()
        self.gameTime = QTime(0, 0, 0)

        self.redData = list()
        self.blueData = list()

        self.StartGame.clicked.connect(self.startGame)
        self.ViewGraph.clicked.connect(self.showGraph)

        self.badStyle = f'background:{badColor}; padding: 5px;'
        self.goodStyle = f'background:{highlightColor}; padding: 5px;'

        # Status monitors for website statuses, None means 'Loading...'
        self.streamUp = None
        self.teams = None
        self.statsUp = None

        self.graphWindow = None  # Defined early so we have a reference if never created
        self.gameOver = False  # Stop data from being collected
        self.accurateSides = None  # Keeps track if teams have swapped sides during a series

        # Create and run the selenium browser to gather data every second about the status and stats
        self.browserThread = BrowserThread(self)
        self.browserThread.start()

    def setStreamStatus(self, status):
        if self.streamUp == status:
            return
        self.streamUp = status
        if status:
            self.StreamStatusLabel.setText('LIVE')
            self.StreamStatusLabel.setStyleSheet(self.goodStyle)
        else:
            self.StreamStatusLabel.setText('Not Available')
            self.StreamStatusLabel.setStyleSheet(self.badStyle)

    def setTeams(self, teamList, blueTeam=None, redTeam=None):
        self.blueTeam = blueTeam
        self.redTeam = redTeam
        if self.teams == teamList:
            return
        self.teams = teamList
        if len(teamList) > 0:
            self.GameStatusLabel.setText(f'{teamList[0]} vs {teamList[1]}')
            self.GameStatusLabel.setStyleSheet(self.goodStyle)
        else:
            self.GameStatusLabel.setText('No Games Available')
            self.GameStatusLabel.setStyleSheet(self.badStyle)
        self.teams = teamList

    def setDataShown(self, dataShown):
        if dataShown is self.statsUp:
            return

        self.statsUp = dataShown
        if dataShown:
            self.StatsStatusLabel.setText('Stats Recording')
            self.StatsStatusLabel.setStyleSheet(self.goodStyle)
        else:
            self.StatsStatusLabel.setText('No Stats Available')
            self.StatsStatusLabel.setStyleSheet(self.badStyle)
        self.dataShown = dataShown

    def addData(self, red, blue):
        # Add data and increase the game clock unless the game is over
        if self.gameOver:
            return
        self.redData.append(red)
        self.blueData.append(blue)
        self.updateTime(1)

        if len(self.blueData) > 3:
            self.ViewGraph.setEnabled(True)

    def showStats(self, x):
        print(f'showing stats: {x}')

    def showGraph(self):
        print('showing graph')
        self.graphWindow = GraphWindow(self)
        self.graphWindow.show()
        self.ViewGraph.setEnabled(False)

    def saveGraph(self):
        print('saving graph')

    def updateTime(self, changeAmt=0):
        self.gameTime = self.gameTime.addSecs(changeAmt)

    def endGame(self):
        # Prevent data from being colleted
        self.gameOver = True
        self.StartGame.setEnabled(True)

    def startGame(self):
        # Clears the data and allows data to be collected again
        self.gameOver = False
        self.StartGame.setEnabled(False)
        self.redData = list()
        self.blueData = list()

    def closeEvent(self, *args, **kwargs):
        super(LiveTab, self).closeEvent(*args, **kwargs)
        try:
            self.graphWindow.close()
        except Exception:
            pass  # The window failed to close because it was already closed
        self.browserThread.closeBrowser()
        self.browserThread.quit()
コード例 #19
0
class vonMisesDistributionGraph(MyQWidget):

    NAME = "von Mises Distribution"

    def __init__(self):
        super().__init__("von Mises Distribution")

        self.initUI()

    def initUI(self):

        self.m = 5
        self.sigma2 = 1

        self.graphVonMises1 = GraphWindow(self, title=self.name)
        self.graphVonMises1.setGeometry(0, 0, 600, 600)
        self.graphVonMises1.setXRange(-1.3, 1.3)
        self.graphVonMises1.setYRange(-1.3, 1.3)

        self.graphVonMises2 = GraphWindow(self, title="von Mises Distribution")
        self.graphVonMises2.setGeometry(0, 0, 600, 600)
        self.graphVonMises2.setXRange(0, 2 * np.pi)
        self.graphVonMises2.setYRange(0, 1.5)

        self.btnData = QPushButton('Add Data', self)
        self.btnData.setGeometry(20, 0, 120, 30)
        self.btnData.clicked.connect(self.clickedAddData)

        self.btnReset = QPushButton('Reset Data', self)
        self.btnReset.setGeometry(150, 0, 120, 30)
        self.btnReset.clicked.connect(self.clickedResetData)

        self.slSigma2 = SliderLabel(self,
                                    func=self.changeValueSigma2,
                                    tag="σ2=")
        self.slSigma2.setGeometry(20, 30, 300, 30)

        self.label_mML = QLabel(self)
        self.label_mML.setGeometry(300, 30, 80, 30)

        self.xs = []
        for i in range(1000):
            x = randn(MU, self.sigma2) % (2 * np.pi)
            self.xs.append(x)

        self.show()
        self.slSigma2.setValue(56)

    def ValueChanged(self):

        thetaML = thetaMean(self.xs)
        mML = search_mML(self.xs, thetaML)
        thetas, ps = p(thetaML, mML)  #θの確率密度関数

        self.label_mML.setText("mML=" + str('%02.2f' % mML))

        self.graphVonMises1.clear()
        self.graphVonMises1.setValuePolar(self.xs)
        self.graphVonMises1.setValuePolar(thetas, ps, color='b')
        self.graphVonMises1.setValue([0, 2 * np.cos(thetaML)],
                                     [0, 2 * np.sin(thetaML)],
                                     color='y')
        self.graphVonMises1.setValue([0, 2 * np.cos(MU)], [0, 2 * np.sin(MU)],
                                     color='r')
        self.graphVonMises1.setHistPolar(self.xs, bins=40)
        self.graphVonMises1.show()

        self.graphVonMises2.clear()
        self.graphVonMises2.setValue(thetas, ps, color='b')
        self.graphVonMises2.setValue([thetaML, thetaML], [0, 10], color='y')
        self.graphVonMises2.setValue([MU, MU], [0, 10], color='r')
        self.graphVonMises2.setHistgram(self.xs,
                                        range_=(0, 2 * np.pi),
                                        bins=40)
        self.graphVonMises2.show()

    def clickedAddData(self):
        for i in range(NUM):
            x = randn(MU, self.sigma2) % (2 * np.pi)
            self.xs.append(x)
        self.xs.append(x)

        self.ValueChanged()

    def clickedResetData(self):
        self.xs = []
        self.ValueChanged()

    def changeValueSigma2(self, value):
        self.sigma2 = 2**(value / 99 * 7 - 4)
        self.ValueChanged()
        return str('%02.1f' % self.sigma2)
コード例 #20
0
 def initServer(self):
     self.listeners = set()
     self.gui = GraphWindow(reactor)
     self.dv = yield self.client.data_vault
コード例 #21
0
class tDistributionGraph(MyQWidget):

    NAME = "t Distribution"
    
    def __init__(self):
        super().__init__("t Distribution")

        self.initUI()

    def initUI(self):

        self.graphT = GraphWindow(self, title="Student's t Distribution")
        self.graphT.setGeometry(0, 0, 600, 600)
        self.graphT.setXRange(MIN, MAX)
        self.graphT.setYRange(0, 1)

        self.btnData = QPushButton('Add Data',self)
        self.btnData.setGeometry(20, 0, 120, 30)
        self.btnData.clicked.connect(self.clickedAddData)

        self.btnNoiseData = QPushButton('Add Noise Data',self)
        self.btnNoiseData.setGeometry(20, 30, 120, 30)
        self.btnNoiseData.clicked.connect(self.clickedAddNoiseData)

        self.btnReset = QPushButton('Reset Data',self)
        self.btnReset.setGeometry(150, 0, 120, 30)
        self.btnReset.clicked.connect(self.clickedResetData)


        self.slNy = SliderLabel(self, func=self.changeValueNy, tag="ν=")
        self.slNy.setGeometry(20, 60, 1000, 30)
        self.slLambda = SliderLabel(self, func=self.changeValueLambda, tag="λ=")
        self.slLambda.setGeometry(20, 90, 1000, 30)

        self.setGeometry(620, 200, 300, 200)
        self.show()
        self.xs = []
        self.lambda_ = 1
        self.ny = 10

        self.ValueChanged()

    def ValueChanged(self):
        mu, sigma2 = getN(self.xs)

        xs = [1/NUM*(MAX-MIN)*x+MIN for x in range(NUM+1)]
        psGauss = [N(x, mu, sigma2) for x in xs]
        psT = [t(x, mu, self.lambda_, self.ny) for x in xs]

        self.graphT.clear()
        self.graphT.setHistgram(self.xs, range_=(MIN, MAX), bins=50)
        self.graphT.setValue(xs, psGauss, color="y")
        self.graphT.setValue(xs, psT, color="r")
        self.graphT.show()

    def clickedAddData(self):
        x = randn(MU, SIGMA2)
        self.xs.append(x)
        self.ValueChanged()

    def clickedAddNoiseData(self):
        x = np.random.rand()*15-5
        self.xs.append(x)
        self.ValueChanged()

    def clickedResetData(self):
        self.xs = []
        self.ValueChanged()

    def changeValueNy(self, value):
        a = value/99*16-8
        self.ny = 2**a
        self.ValueChanged()
        return str('%03.3f' % self.ny)

    def changeValueLambda(self, value):
        self.lambda_ = value/99*9.9+0.1
        self.ValueChanged()
        return str('%02.2f' % self.lambda_)
コード例 #22
0
    def init_main(self):
        # тулбар bg - цвет фона, bb - граница 
        toolbar = TK.Frame(bg="#d7d8e0", bd=2)
        # side=TK.TOP - закрепляет тулбар в верхней части окна
        # fill=TK.X - растягивает по горизонтали
        toolbar.pack(side=TK.TOP, fill=TK.X)
        # END initializing of objects and window widgets
        
        # income_outcome button
        self.add_img = TK.PhotoImage(file="img/add.png")
        btn_open_dialog = TK.Button(toolbar, text="Добавить",
                                    command= lambda: IncomeOutcome(),
                                    bg="#FFFFFF", bd=2,
                                    compound=TK.TOP,
                                    image=self.add_img)
        btn_open_dialog.pack(side=TK.LEFT)
        # END income_outcome button

        # remove record button
        self.remove_img = TK.PhotoImage(file="img/remove.png")
        btn_open_remove_record = TK.Button(toolbar, text="Удалить",
                                           command=lambda: RemoveWindow(),
                                           bg="#FFFFFF", bd=2,
                                           compound=TK.TOP,
                                           image=self.remove_img)
        btn_open_remove_record.pack(side=TK.LEFT)
        # END remove record button

        # filter button
        self.filter_img = TK.PhotoImage(file="img/filter.png")
        btn_open_filter = TK.Button(toolbar, text="Фильтр",
                                    command=lambda: FilterWindow(),
                                    bg="#FFFFFF", bd=2,
                                    compound=TK.TOP,
                                    image=self.filter_img)
        btn_open_filter.pack(side=TK.LEFT)
        # END filter button

        # calc button
        self.calc_img = TK.PhotoImage(file="img/calc.png")
        btn_open_calc = TK.Button(toolbar, text="Калькулятор",
                                  command=lambda: CalcWindow(),
                                  bg="#FFFFFF", bd=2,
                                  compound=TK.TOP,
                                  image=self.calc_img)
        btn_open_calc.pack(side=TK.LEFT)
        # END calc button

        # graph button
        self.graph_img = TK.PhotoImage(file="img/graph.png")
        btn_open_graph = TK.Button(toolbar, text="График",
                                  command=lambda: GraphWindow(),
                                  bg="#FFFFFF", bd=2,
                                  compound=TK.TOP,
                                  image=self.graph_img)
        btn_open_graph.pack(side=TK.LEFT)        
        # END graph button

        # exit button
        self.exit_img = TK.PhotoImage(file="img/exit.png")
        btn_exit = TK.Button(toolbar, text="Выход",
                                command=quit,
                                bg="#FFFFFF", bd=2,
                                compound=TK.TOP,
                                image=self.exit_img)
        btn_exit.pack(side=TK.RIGHT)
        # END exit button

        # refresh button
        self.refresh_img = TK.PhotoImage(file="img/refresh1.png")
        btn_refresh = TK.Button(toolbar, text="Обновить БД",
                                command=lambda: REFRESH(self.tree),
                                bg="#FFFFFF", bd=2,
                                compound=TK.TOP,
                                image=self.refresh_img)
        btn_refresh.pack(side=TK.RIGHT)
        # END refresh button        

        # Upload button
        self.upld_img = TK.PhotoImage(file="img/upld.png")
        btn_upld = TK.Button(toolbar, text="Загрузить файл",
                                command=lambda: WarningWindow(action="загрузить"),
                                bg="#FFFFFF", bd=2,
                                compound=TK.TOP,
                                image=self.upld_img)
        btn_upld.pack(side=TK.RIGHT)        
        # END Upload button        

        # Download button
        self.dnwld_img = TK.PhotoImage(file="img/dwnld.png")
        btn_dwnld = TK.Button(toolbar, text="Скачать файл",
                                command=lambda: WarningWindow(action="скачать"),
                                bg="#FFFFFF", bd=2,
                                compound=TK.TOP,
                                image=self.dnwld_img)
        btn_dwnld.pack(side=TK.RIGHT)
        # END Download button         

        # table with records
        self.tree = TTK.Treeview(self, columns=("id", "creationdata",
                                                "description",
                                                "income_expense",
                                                "total"),
                                 height=15, show="headings")
        self.tree.column("id", width=30, anchor=TK.CENTER)
        self.tree.column("creationdata", width=150, anchor=TK.CENTER)
        self.tree.column("description", width=215, anchor=TK.W)
        self.tree.column("income_expense", width=150, anchor=TK.CENTER)
        self.tree.column("total", width=100, anchor=TK.W)

        # giving displayment names for columns
        self.tree.heading("id", text="id")
        self.tree.heading("creationdata", text="Дата")
        self.tree.heading("description", text="Наименование")
        self.tree.heading("income_expense", text="Доход / Расход")
        self.tree.heading("total", text="Сумма")

        # displaying all data in the table by calling SEL function 
        SEL(self.tree)

        # display table
        self.tree.pack(side=TK.BOTTOM)
コード例 #23
0
class BayesianInferenceGraph(MyQWidget):

    NAME = "Bayesian Inference"
    def __init__(self):
        super().__init__("Bayesian Inference")

        self.initUI()

    def initUI(self):

        self.graph = GraphWindow(self)
        self.graph.setGeometry(0, 0, 600, 600)
        self.graph.setXRange(0, 1)
        self.graph.setYRange(0, 12)

        self.slBeta = SliderLabel(self, func=self.changeValueBeta, tag="beta=")
        self.slBeta.setGeometry(20, 40, 1000, 30)

        self.slW = SliderLabel(self, func=self.changeValueWin, tag="win :")
        self.slW.setGeometry(20, 70, 1000, 30)

        self.slL = SliderLabel(self, func=self.changeValueLose, tag="lose :")
        self.slL.setGeometry(20, 100, 1000, 30)

        self.labelMode = QLabel(self)
        self.labelMode.setGeometry(200, 128, 80, 30)
        self.labelMode.setStyleSheet('color: red')

        self.labelRate = QLabel(self)
        self.labelRate.setGeometry(200, 158, 80, 30)
        self.labelRate.setStyleSheet('color: blue')

        self.setGeometry(700, 300, 280, 200)
        self.setWindowTitle('BayesianInference')
        self.show()

        self.beta = 2
        self.win = 0
        self.lose = 0
        self.ValueChanged()

    def ValueChanged(self):
        xs, ys = p(self.beta, self.win, self.lose)
        mode = xs[ys.index(max(ys))]
        rate = 0.5
        if self.win+self.lose is not 0:
            rate = self.win/(self.win+self.lose)

        self.graph.clear()
        self.graph.setValue(xs, ys)
        self.graph.setValue([mode, mode], [0, 100], 'r')
        self.graph.setValue([rate, rate], [0, 100], 'b')
        self.graph.show()
        self.labelMode.setText("mode:" + str('%01.2f' % mode))
        self.labelRate.setText("rate:" + str('%01.2f' % rate))

    def changeValueBeta(self, value):
        self.beta = value/11+1
        self.ValueChanged()
        return str('%02.1f' % self.beta)

    def changeValueWin(self, value):
        self.win = int(value/99*30)
        self.ValueChanged()
        return str(self.win)

    def changeValueLose(self, value):
        self.lose = int(value/99*30)
        self.ValueChanged()
        return str(self.lose)
コード例 #24
0
 def initServer(self):
     self.listeners = set()
     self.gui = GraphWindow(reactor, cxn=self.client)
     self.gui.setWindowTitle('Real Simple Grapher')
     self.dv = yield self.client.data_vault
     self.pv = yield self.client.parametervault
コード例 #25
0
ファイル: NonParametric.py プロジェクト: tnyo43/PRMLstudy
class NonParametricGraph(MyQWidget):

    NAME = "Non Parametric Method"

    def __init__(self):
        super().__init__("Non Parametric Method")

        self.initUI()

    def initUI(self):

        self.xs, self.ps = sampleDistribution()
        self.Delta = 1 / 25
        self.h = 0
        self.K = 10
        self.data = sampleData()

        self.graphHist = GraphWindow(self, title="Sample Data")
        self.graphHist.setGeometry(0, 0, 600, 600)
        self.graphHist.setXRange(0, 1)
        self.graphHist.setYRange(0, 5)
        self.graphHist.show()

        self.graphKernelDensity = GraphWindow(
            self, title="Kernel Density Estimation")
        self.graphKernelDensity.setGeometry(600, 0, 600, 600)
        self.graphKernelDensity.setXRange(0, 1)
        self.graphKernelDensity.setYRange(0, 5)
        self.graphKernelDensity.show()

        self.graphKNear = GraphWindow(self, title="K nearest neighbor method")
        self.graphKNear.setGeometry(300, 300, 600, 600)
        self.graphKNear.setXRange(0, 1)
        self.graphKNear.setYRange(0, 5)
        self.graphKNear.show()

        self.slDelta = SliderLabel(self, func=self.changeValueDelta, tag="Δ=")
        self.slDelta.setGeometry(20, 0, 250, 30)
        self.slH = SliderLabel(self, func=self.changeValueH, tag="h=")
        self.slH.setGeometry(20, 30, 250, 30)
        self.slK = SliderLabel(self, func=self.changeValueK, tag="K=")
        self.slK.setGeometry(20, 60, 250, 30)

        self.show()
        self.changeValue()

    def changeValue(self):
        self.changeValueDelta(50)
        self.changeValueH(50)
        self.changeValueK(50)

    def changeValueDelta(self, value):
        self.Delta = 2**(value / 99 * 7 - 7)

        self.graphHist.clear()
        self.graphHist.setHistgram(self.data,
                                   range_=(0, 1),
                                   bins=int(1 / self.Delta),
                                   brush=(255, 0, 0, 80))
        self.graphHist.setValue(self.xs, self.ps, color='b')
        return str('%02.2f' % self.Delta)

    def changeValueH(self, value):
        self.h = 2**(value / 99 * 7 - 7)

        xs, psKernel = KernelDensity(self.data, self.h)
        self.graphKernelDensity.clear()
        self.graphKernelDensity.setValue(xs, psKernel, color='r')
        self.graphKernelDensity.setValue(self.xs, self.ps, color='b')
        return str('%02.2f' % self.h)

    def changeValueK(self, value):
        self.K = int(value / 99 * 49) + 1

        xs, psKnear = KNear(self.data, self.K)
        self.graphKNear.clear()
        self.graphKNear.setValue(xs, psKnear, color='r')
        self.graphKNear.setValue(self.xs, self.ps, color='b')
        return str(self.K)
コード例 #26
0
class GaussianDistributionGraph(MyQWidget):

    NAME = "Gaussian Distribution"

    def __init__(self):
        super().__init__("Gaussian Distribution")

        self.initUI()

    def initUI(self):

        self.graphPrior = GraphWindow(self, title="Prior graph")
        self.graphPrior.setGeometry(0, 0, 600, 600)
        self.graphPrior.setYRange(0, 5)

        self.graphLikelihood = GraphWindow(self, title="Likelihood graph")
        self.graphLikelihood.setGeometry(0, 0, 600, 600)
        self.graphLikelihood.setYRange(0, 1)

        self.graphPosterior = GraphWindow(self, title="Posterior graph")
        self.graphPosterior.setGeometry(0, 0, 600, 600)
        self.graphPosterior.setYRange(0, 5)
        self.graphPosterior.setXRange(min_, max_)

        self.sl_sigma0_2 = SliderLabel(self,
                                       func=self.changeValueSigma0_2,
                                       tag="σ0^2=")
        self.sl_sigma0_2.setGeometry(20, 40, 1000, 30)

        self.sl_mu0 = SliderLabel(self, func=self.changeValueMu0, tag="mu0=")
        self.sl_mu0.setGeometry(20, 70, 1000, 30)

        self.btn_data = QPushButton('Add Data', self)
        self.btn_data.setGeometry(20, 0, 120, 30)
        self.btn_data.clicked.connect(self.clickedAddData)

        self.btn_reset = QPushButton('Reset Data', self)
        self.btn_reset.setGeometry(140, 0, 120, 30)
        self.btn_reset.clicked.connect(self.clickedResetData)

        self.labelNum = QLabel(self)
        self.labelNum.setGeometry(20, 100, 200, 30)

        labelMU = QLabel(self)
        labelMU.setGeometry(300, 100, 200, 30)
        labelMU.setText("Actual MU : " + str('%01.4f' % MU))
        labelMU.setStyleSheet('color: red')

        self.labelAverage = QLabel(self)
        self.labelAverage.setGeometry(20, 130, 300, 30)
        self.labelAverage.setStyleSheet('color: orange')

        self.labelPostMode = QLabel(self)
        self.labelPostMode.setGeometry(20, 160, 300, 30)
        self.labelPostMode.setStyleSheet('color: blue')

        self.labelAveDiff = QLabel(self)
        self.labelAveDiff.setGeometry(300, 130, 300, 30)
        self.labelAveDiff.setStyleSheet('color: orange')

        self.labelPMDiff = QLabel(self)
        self.labelPMDiff.setGeometry(300, 160, 300, 30)
        self.labelPMDiff.setStyleSheet('color: blue')

        self.setGeometry(700, 300, 560, 200)
        self.setWindowTitle('GaussianDistribution')

        self.show()

        self.sigma0_2 = SIGMA0_2
        self.mu0 = MU0

        self.xs = []
        self.sl_sigma0_2.setValue(10)
        self.sl_mu0.setValue(50)
        self.ValueChanged()

    def ValueChanged(self):
        mus, psPrior = pPrior(mu0=self.mu0, sigma0_2=self.sigma0_2)
        self.graphPrior.clear()
        self.graphPrior.setValue(mus, psPrior)
        self.graphPrior.show()

        mus, psLikelihood = pL(self.xs)
        self.graphLikelihood.clear()
        self.graphLikelihood.setValue(mus, psLikelihood)
        self.graphLikelihood.show()

        mus, psPosterior = pPosterior(self.xs,
                                      mu0=self.mu0,
                                      sigma0_2=self.sigma0_2)  #理論上の事後関数
        self.graphPosterior.clear()
        self.graphPosterior.setValue(mus, psPosterior)
        self.graphPosterior.setValue([MU, MU], [0, 10], 'r')
        #事後分後∝事前分布*尤度関数から求めた事後分布。理論上の事後分布と完全に一致して草
        """
        psPrior, psLikelihood = list(map(np.array, [psPrior, psLikelihood]))
        psPosteriorCalc = psPrior* psLikelihood #計算して出した事後分布
        psPosteriorCalc *= max(psPosterior) / max(psPosteriorCalc)
        self.graphPosterior.setValue(mus, psPosteriorCalc)
        """
        self.graphPosterior.show()

        mode = mus[psPosterior.index(max(psPosterior))]  #確率密度が最大の点
        self.graphPosterior.setValue([mode, mode], [0, 10], 'b')
        self.labelPostMode.setText("Posterior Distribution Mode : " +
                                   str('%01.4f' % mode))
        self.labelPMDiff.setText("diff : " + str('%01.4f' % abs(mode - MU)))
        if self.xs:
            average = sum(self.xs) / len(self.xs)
            self.labelAverage.setText("Data simple average : " +
                                      str('%01.4f' % average))
            self.labelAveDiff.setText("diff : " +
                                      str('%01.4f' % abs(average - MU)))
            self.graphPosterior.setValue([average, average], [0, 10], 'y')
        else:
            self.labelAverage.setText("Data simple average : -")
            self.labelAveDiff.setText("diff : -")

        self.labelNum.setText("Data Num : " + str(len(self.xs)))

    def changeValueSigma0_2(self, value):
        self.sigma0_2 = value / 99 * 4.99 + 0.01
        self.ValueChanged()
        return str('%02.2f' % self.sigma0_2)

    def changeValueMu0(self, value):
        self.mu0 = (value / 99 - 0.5) * 2
        self.ValueChanged()
        return str('%02.1f' % self.mu0)

    def clickedAddData(self):
        x = randn(mu=MU, sigma2=SIGMA2)
        self.xs.append(x)
        self.ValueChanged()

    def clickedResetData(self):
        self.xs = []
        self.ValueChanged()
コード例 #27
0
    def initUI(self):

        self.graphPrior = GraphWindow(self, title="Prior graph")
        self.graphPrior.setGeometry(0, 0, 600, 600)
        self.graphPrior.setYRange(0, 5)

        self.graphLikelihood = GraphWindow(self, title="Likelihood graph")
        self.graphLikelihood.setGeometry(0, 0, 600, 600)
        self.graphLikelihood.setYRange(0, 1)

        self.graphPosterior = GraphWindow(self, title="Posterior graph")
        self.graphPosterior.setGeometry(0, 0, 600, 600)
        self.graphPosterior.setYRange(0, 5)
        self.graphPosterior.setXRange(min_, max_)

        self.sl_sigma0_2 = SliderLabel(self,
                                       func=self.changeValueSigma0_2,
                                       tag="σ0^2=")
        self.sl_sigma0_2.setGeometry(20, 40, 1000, 30)

        self.sl_mu0 = SliderLabel(self, func=self.changeValueMu0, tag="mu0=")
        self.sl_mu0.setGeometry(20, 70, 1000, 30)

        self.btn_data = QPushButton('Add Data', self)
        self.btn_data.setGeometry(20, 0, 120, 30)
        self.btn_data.clicked.connect(self.clickedAddData)

        self.btn_reset = QPushButton('Reset Data', self)
        self.btn_reset.setGeometry(140, 0, 120, 30)
        self.btn_reset.clicked.connect(self.clickedResetData)

        self.labelNum = QLabel(self)
        self.labelNum.setGeometry(20, 100, 200, 30)

        labelMU = QLabel(self)
        labelMU.setGeometry(300, 100, 200, 30)
        labelMU.setText("Actual MU : " + str('%01.4f' % MU))
        labelMU.setStyleSheet('color: red')

        self.labelAverage = QLabel(self)
        self.labelAverage.setGeometry(20, 130, 300, 30)
        self.labelAverage.setStyleSheet('color: orange')

        self.labelPostMode = QLabel(self)
        self.labelPostMode.setGeometry(20, 160, 300, 30)
        self.labelPostMode.setStyleSheet('color: blue')

        self.labelAveDiff = QLabel(self)
        self.labelAveDiff.setGeometry(300, 130, 300, 30)
        self.labelAveDiff.setStyleSheet('color: orange')

        self.labelPMDiff = QLabel(self)
        self.labelPMDiff.setGeometry(300, 160, 300, 30)
        self.labelPMDiff.setStyleSheet('color: blue')

        self.setGeometry(700, 300, 560, 200)
        self.setWindowTitle('GaussianDistribution')

        self.show()

        self.sigma0_2 = SIGMA0_2
        self.mu0 = MU0

        self.xs = []
        self.sl_sigma0_2.setValue(10)
        self.sl_mu0.setValue(50)
        self.ValueChanged()
コード例 #28
0
class BiasVarianceTradeoffGraph(MyQWidget):

    NAME = "Bias-Variance Tradeoff"

    def __init__(self):
        super().__init__("Bias-Variance Tradeoff")

        self.initUI()

    def initUI(self):

        self.Lambda = 0
        self.BASISFUNCTION = GaussianBasisFunctions

        self.graph1 = GraphWindow(self, "Variance Graph")
        self.graph1.setGeometry(0, 0, 600, 600)
        self.graph1.setXRange(0, 1)
        self.graph1.setYRange(-1.3, 1.3)
        self.graph2 = GraphWindow(self, "Bias Graph")
        self.graph2.setGeometry(600, 0, 600, 600)
        self.graph2.setXRange(0, 1)
        self.graph2.setYRange(-1.3, 1.3)

        self.sineX, self.sineY = Sine()

        self.data = []
        for i in range(NUM):
            xs, ts = randomSine(num=25,sigma2=0.09,regularIntervals=True)
            self.data.append([xs, ts])

        self.graph1.show()
        self.graph2.show()
        self.plot()

        self.slL = SliderLabel(self, func=self.changeValueLambda, tag="lnλ=")
        self.slL.setGeometry(20, 0, 280, 30)
        self.show()

    def changeValueLambda(self, value):
        l = (value/99*6-3)
        self.Lambda = np.exp(l)
        self.plot()
        return str('%02.1f' % l)

    def plot(self):
        self.graph1.clear()
        self.graph1.setValue(self.sineX, self.sineY, color='b')
        self.graph2.clear()
        self.graph2.setValue(self.sineX, self.sineY, color='b')

        WS = np.zeros([M+1])
        for datum in self.data[:20]:
            xs, ts = datum
            ws = shinkage(xs, ts, M, self.Lambda, basisFunction=self.BASISFUNCTION)
            ys = [model(x, ws, M, basisFunction=self.BASISFUNCTION) for x in self.sineX]
            WS += np.array(ws)
            self.graph1.setValue(self.sineX, ys, color='r')
        for datun in self.data[20:]:
            xs, ts = datum
            ws = shinkage(xs, ts, M, self.Lambda, basisFunction=self.BASISFUNCTION)
            WS += np.array(ws)

        WS /= NUM
        ys = [model(x, WS, M, basisFunction=self.BASISFUNCTION) for x in self.sineX]
        self.graph2.setValue(self.sineX, ys, color='r')