Example #1
0
 def OnTreeRightDown(self, evt):
     if wx.Platform == '__WXMAC__':
         forceSibling = evt.AltDown()
     else:
         forceSibling = evt.ControlDown()
     forceInsert = evt.ShiftDown()
     Presenter.popupMenu(forceSibling, forceInsert, evt.GetPosition())
Example #2
0
 def OnTreeLeftDown(self, evt):
     pt = evt.GetPosition();
     item, flags = self.tree.HitTest(pt)
     if flags & wx.TREE_HITTEST_NOWHERE or not item:
         # Unselecting seems to be broken on wxGTK!!!
         Presenter.unselect()
     evt.Skip()
Example #3
0
 def OnCheck(self, evt):
     Presenter.setApplied(False)
     if Listener.testWin.IsShown() and g.conf.autoRefresh and \
             g.conf.autoRefreshPolicy == AUTO_REFRESH_POLICY_FOCUS:
         Listener.testWin.isDirty = True
         wx.CallAfter(Presenter.refreshTestWin)
     evt.Skip()
Example #4
0
    def _bcbcg_blbcg_least_square_exp_b(self):
        """ """
        self._BB_6  = np.random.random( ( self._mat.shape[0],6) )
        self._BX_6  = np.ones ( (self._mat.shape[1],6) )


        #line 1
        blbcg_solver_obj = BLBCG()
        self._final_x_blbcg_m6s6, self._final_r_blbcg_m6s6, self._residual_hist_blbcg_m6s6 = \
                blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 6, self._tol, self._maxiter, 0)
        #line 2
        blbcg_solver_obj = BLBCG()
        self._final_x_blbcg_m6s12, self._final_r_blbcg_m6s12, self._residual_hist_blbcg_m6s12 = \
                blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 12, self._tol, self._maxiter, 0)


        #line 3
        bcbcg_solver_obj = BCBCG()
        self._final_x_bcbcg_m6s6, self._final_r_bcbcg_m6s6, self._residual_hist_bcbcg_m6s6 = \
                bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 6, self._tol, self._maxiter, 0)
        #line 4
        bcbcg_solver_obj = BCBCG()
        self._final_x_bcbcg_m6s12, self._final_r_bcbcg_m6s12, self._residual_hist_bcbcg_m6s12 = \
                bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 12, self._tol, self._maxiter, 0)

        plot_worker = Presenter()
        residual_list = [self._residual_hist_blbcg_m6s6, self._residual_hist_blbcg_m6s12, \
                         self._residual_hist_bcbcg_m6s6, self._residual_hist_bcbcg_m6s12 ]

        legend_list = ["blbcg_m6s6", "blbcg_m6s12", "bcbcg_m6s6", "bcbcg_m6s12"]
        color_list = ["r","k","b","y"]
        #plot_worker.instant_plot_y_log10(residual_list, "Chem97ZtZ", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list)
        plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
Example #5
0
 def OnCheck(self, evt):
     Presenter.setApplied(False)
     if Presenter.panelIsDirty():
         Presenter.registerUndoEdit()
     if g.conf.autoRefresh and g.conf.autoRefreshPolicy == AUTO_REFRESH_POLICY_FOCUS:
         Listener.testWin.isDirty = True
         wx.CallAfter(Presenter.refreshTestWin)
     evt.Skip()
Example #6
0
 def OnCmdPaste(self, evt):
     '''ID.PASTE handler (for Edit menu and shortcuts).'''
     state = wx.GetMouseState()
     forceSibling = state.AltDown()
     forceInsert = state.ShiftDown()
     g.Presenter.updateCreateState(forceSibling, forceInsert)
     g.undoMan.RegisterUndo(undo.UndoGlobal()) 
     Presenter.paste()
Example #7
0
 def OnPasteSibling(self, evt):
     '''ID.PASTE_SIBLING handler.'''
     forceSibling = True
     state = wx.GetMouseState()
     forceInsert = state.ShiftDown()
     g.Presenter.updateCreateState(forceSibling, forceInsert)        
     g.undoMan.RegisterUndo(undo.UndoGlobal()) # !!! TODO
     Presenter.paste()
Example #8
0
 def OnSubclass(self, evt):
     node = self.tree.GetPyData(Presenter.item)
     subclass = node.getAttribute('subclass')
     dlg = wx.TextEntryDialog(self.frame, 'Subclass:', defaultValue=subclass)
     if dlg.ShowModal() == wx.ID_OK:
         subclass = dlg.GetValue()
         Presenter.subclass(Presenter.item, subclass)
     dlg.Destroy()        
Example #9
0
 def OnCollapseAll(self, evt):
     # Prevent multiple calls to setData
     self.tree.Unbind(wx.EVT_TREE_ITEM_COLLAPSED)
     self.tree.UnselectAll()
     self.tree.CollapseAll()
     self.tree.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnTreeItemCollapsed)
     if not Presenter.applied: Presenter.update()
     Presenter.setData(self.tree.root)
Example #10
0
 def OnLeftDown(self, evt):
     data = wx.ColourData()
     data.SetColour(self.GetValue())
     dlg = wx.ColourDialog(self, data)
     if dlg.ShowModal() == wx.ID_OK:
         self.SetValue('#%02X%02X%02X' % dlg.GetColourData().GetColour().Get())
         Presenter.setApplied(False)
     dlg.Destroy()
Example #11
0
 def OnButtonEdit(self, evt):
     dlg = g.res.LoadDialog(self, 'DIALOG_TEXT')
     textCtrl = xrc.XRCCTRL(dlg, 'TEXT')
     textCtrl.SetValue(self.text.GetValue())
     if dlg.ShowModal() == wx.ID_OK:
         self.text.ChangeValue(textCtrl.GetValue())
         Presenter.setApplied(False)
     dlg.Destroy()
Example #12
0
def main():
    # view = View()
    # dim_view = DimensionalView(view.drawing_area_dimensional.get_allocation().width,view.drawing_area_dimensional.get_allocation().height)
    # comp_view = ComplexView(view.drawing_area_complex.get_allocation().width,view.drawing_area_complex.get_allocation().height)
    app = QApplication(sys.argv)
    p = Presenter()
    p.show()
    app.exec_()
Example #13
0
 def OnPanelPageChanged(self, evt):
     TRACE('OnPanelPageChanged: %d=>%d', evt.GetOldSelection(), evt.GetSelection())
     # Register new undo 
     if Presenter.panelIsDirty():
         Presenter.createUndoEdit(page=evt.GetSelection())
     # Refresh test window after finishing
     if g.conf.autoRefresh and self.testWin.IsDirty():
         wx.CallAfter(Presenter.refreshTestWin)
     evt.Skip()
Example #14
0
 def OnComponentCreate(self, evt):
     '''Hadnler for creating new elements.'''
     comp = Manager.findById(evt.GetId())
     g.undoMan.RegisterUndo(undo.UndoGlobal()) # !!! TODO
     if comp.groups[0] == 'component':
         node = Model.createComponentNode('Component')
         Presenter.create(comp, node)
     else:
         Presenter.create(comp)
Example #15
0
 def OnLeftDown(self, evt):
     data = wx.ColourData()
     data.SetColour(self.GetValue())
     dlg = wx.ColourDialog(self, data)
     if dlg.ShowModal() == wx.ID_OK:
         self.SetValue('#%02X%02X%02X' %
                       dlg.GetColourData().GetColour().Get())
         Presenter.setApplied(False)
     dlg.Destroy()
Example #16
0
 def OnCheck(self, evt):
     Presenter.setApplied(False)
     if Presenter.panelIsDirty():
         Presenter.registerUndoEdit()
     if Listener.testWin.IsShown() and g.conf.autoRefresh and \
             g.conf.autoRefreshPolicy == AUTO_REFRESH_POLICY_FOCUS:
         Listener.testWin.isDirty = True
         wx.CallAfter(Presenter.refreshTestWin)
     evt.Skip()
Example #17
0
 def OnPanelPageChanged(self, evt):
     TRACE('OnPanelPageChanged: %d=>%d', evt.GetOldSelection(), evt.GetSelection())
     # Register new undo 
     if Presenter.panelIsDirty():
         Presenter.createUndoEdit(page=evt.GetSelection())
     # Refresh test window after finishing
     if g.conf.autoRefresh and self.testWin.IsDirty():
         wx.CallAfter(Presenter.refreshTestWin)
     evt.Skip()
Example #18
0
 def _db_presenter_a(self):
     plot_worker = Presenter()
     residual_list = [self._residual_hist_a]
     residual_list.append(self._residual_hist_b)
     legend_list = ["bcbcg_s3", "bcbcg_s5"]
     color_list = ["r", "k"]
     # latex style notation
     #plot_worker.instant_plot_y_log10(residual_list, "crystm01 $x_1$")
     #plot_worker.instant_plot_y_log10(residual_list, "crystm01", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list)
     plot_worker.instant_plot_y(residual_list, "crystm01", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list)
 def OnSubclass(self, evt):
     node = self.tree.GetPyData(Presenter.item)
     subclass = node.getAttribute('subclass')
     dlg = wx.TextEntryDialog(self.frame,
                              'Subclass:',
                              defaultValue=subclass)
     if dlg.ShowModal() == wx.ID_OK:
         subclass = dlg.GetValue()
         Presenter.subclass(Presenter.item, subclass)
     dlg.Destroy()
Example #20
0
 def OnDelete(self, evt):
     '''wx.ID_DELETE handler.'''
     if len(self.tree.GetSelections()) == 1:
         item = self.tree.GetSelection()
         index = self.tree.ItemFullIndex(item)
         node = Presenter.delete(self.tree.GetSelection())
         g.undoMan.RegisterUndo(undo.UndoCutDelete(index, node))
     else:
         g.undoMan.RegisterUndo(undo.UndoGlobal())
         Presenter.deleteMany(self.tree.GetSelections())
Example #21
0
 def OnDelete(self, evt):
     '''wx.ID_DELETE handler.'''
     if len(self.tree.GetSelections()) == 1:
         item = self.tree.GetSelection()
         index = self.tree.ItemFullIndex(item)
         node = Presenter.delete(self.tree.GetSelection())
         g.undoMan.RegisterUndo(undo.UndoCutDelete(index, node))
     else:
         g.undoMan.RegisterUndo(undo.UndoGlobal())
         Presenter.deleteMany(self.tree.GetSelections())
Example #22
0
class PresenterTest(unittest.TestCase):
    def setUp(self):
        self.view = MainWindow()
        self.pres = Presenter(self.view, MultiplyModel, ResetModel)

    def test_mul(self):
        self.pres.onInputChanged()

    def test_reset(self):
        self.pres.resetToZero()
Example #23
0
    def _pc_lbcg_vs_cbcg(self):
        """ """
        #print(self._mat)
        self._pc_jacobi = diags(self._mat.diagonal())
        #print ("")
        #print ("dia")
        #print(self._pc_jacobi)
        self._pc_jacobi = np.sqrt(self._pc_jacobi)
        #print ("")
        #print(self._pc_jacobi)
        self._pc_jacobi = inv(self._pc_jacobi)
        #print ("")
        #print ("inverse")
        #print(self._pc_jacobi)
        #print(type(self._pc_jacobi))
        self._left_pcd_mat = aslinearoperator(self._pc_jacobi)(
            self._mat.toarray())
        #print ("")
        #print ("left pcd")
        self._pcd_mat = np.matmul(self._left_pcd_mat,
                                  self._pc_jacobi.toarray())
        #print ("")
        #print (csr_matrix(self._pcd_mat).diagonal())
        #print ("mat cond:", np.linalg.cond(self._mat.toarray()))
        #print ("pcd_mat cond:", np.linalg.cond(self._pcd_mat))

        self._pcd_mat = csr_matrix(self._pcd_mat)
        lbcg_solver_obj = LBCG()
        self._final_x_a, self._final_r_a, self._residual_hist_a = \
                 lbcg_solver_obj.lbcg_solver_least_square(self._pcd_mat, self._SB, self._SX, 8, self._tol, self._maxiter)
        self._final_x_b, self._final_r_b, self._residual_hist_b = \
                 lbcg_solver_obj.lbcg_solver_least_square(self._pcd_mat, self._SB, self._SX, 18, self._tol, self._maxiter)

        cbcg_solver_obj = CBCG()
        self._final_x_c, self._final_r_c, self._residual_hist_c = \
               cbcg_solver_obj.cbcg_solver_least_square(self._pcd_mat, self._SB, self._SX, 8, self._tol, self._maxiter)
        self._final_x_d, self._final_r_d, self._residual_hist_d = \
               cbcg_solver_obj.cbcg_solver_least_square(self._pcd_mat, self._SB, self._SX, 18, self._tol, self._maxiter)

        plot_worker = Presenter()
        residual_list = [
            self._residual_hist_a, self._residual_hist_b,
            self._residual_hist_c, self._residual_hist_d
        ]
        legend_list = [
            "pcd_lbcg_lstsq_s8", "pcd_lbcg_lstsq_s18", "pcd_cbcg_lstsq_s8",
            "pcd_cbcg_lstsq_s18"
        ]
        color_list = ["r", "k", "b", "y"]
        #plot_worker.instant_plot_y_log10(residual_list, "crystm01", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list)
        #plot_worker.instant_plot_y_log10(residual_list, "wathen100", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list)
        plot_worker.instant_plot_y_log10(residual_list, "bodyy06",
                                         "#iteration",
                                         "$\\frac{||x_1||}{||b_1||}$",
                                         legend_list, color_list)
Example #24
0
    def _bcbcg_blbcg_least_square_exp_b(self):
        """ figure 2"""
        print("_bcbcg_blbcg_least_square_exp_b starting ... ")

        m = 3
        self._BB = np.random.random((self._mat.shape[0], m))
        self._BX = np.ones((self._mat.shape[1], m))

        #line 1
        blbcg_solver_obj = BLBCG()
        self._final_x_blbcg_a, self._final_r_blbcg_a, self._residual_hist_blbcg_a = \
                blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB, self._BX, 16, self._tol, self._maxiter, 0)
        #line 2
        blbcg_solver_obj = BLBCG()
        self._final_x_blbcg_b, self._final_r_blbcg_b, self._residual_hist_blbcg_b = \
                blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB, self._BX, 32, self._tol, self._maxiter, 0)

        #line addition
        #blbcg_solver_obj = BLBCG()
        #self._final_x_blbcg_c, self._final_r_blbcg_c, self._residual_hist_blbcg_c = \
        #        blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 32, self._tol, self._maxiter, 0)

        #line 3
        bcbcg_solver_obj = BCBCG()
        self._final_x_bcbcg_a, self._final_r_bcbcg_a, self._residual_hist_bcbcg_a = \
                bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB, self._BX, 16, self._tol, self._maxiter, 0)
        #line 4
        bcbcg_solver_obj = BCBCG()
        self._final_x_bcbcg_b, self._final_r_bcbcg_b, self._residual_hist_bcbcg_b = \
                bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB, self._BX, 32, self._tol, self._maxiter, 0)

        #line addition
        #bcbcg_solver_obj = BCBCG()
        #self._final_x_bcbcg_c, self._final_r_bcbcg_c, self._residual_hist_bcbcg_c = \
        #        bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 32, self._tol, self._maxiter, 0)

        plot_worker = Presenter()
        #residual_list = [self._residual_hist_blbcg_a, self._residual_hist_blbcg_b, self._residual_hist_blbcg_c, \
        #                 self._residual_hist_bcbcg_a, self._residual_hist_bcbcg_b, self._residual_hist_bcbcg_c  ]
        residual_list = [self._residual_hist_blbcg_a, self._residual_hist_blbcg_b,  \
                         self._residual_hist_bcbcg_a, self._residual_hist_bcbcg_b  ]

        #legend_list = ["blbcg_m4s4", "blbcg_m4s8", "blbcg_m4s12", "bcbcg_m4s4", "bcbcg_m4s8", "bcbcg_m4s12"]
        legend_list = [
            "blbcg_m3s16", "blbcg_m3s32", "bcbcg_m3s16", "bcbcg_m3s32"
        ]

        #color_list = ["r","k","b","y","g","m"]
        color_list = ["r", "k", "b", "g"]
        #plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
        plot_worker.instant_plot_y_log10(
            residual_list, "bodyy6", "#iteration",
            "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list,
            color_list)
 def OnComponentCreate(self, evt):
     '''Hadnler for creating new elements.'''
     state = self.tree.GetFullState()  # state just before
     comp = Manager.findById(evt.GetId())
     if comp.groups[0] == 'component':
         node = Model.createComponentNode('Component')
         item = Presenter.create(comp, node)
     else:
         item = Presenter.create(comp)
     itemIndex = self.tree.ItemFullIndex(item)
     g.undoMan.RegisterUndo(undo.UndoPasteCreate(itemIndex, state))
 def OnCollapse(self, evt):
     # Prevent multiple calls to setData
     self.tree.Unbind(wx.EVT_TREE_ITEM_COLLAPSED)
     if self.tree.GetSelection():
         map(self.tree.CollapseAllChildren, self.tree.GetSelections())
     else:
         self.tree.CollapseAll()
     self.tree.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnTreeItemCollapsed)
     if not self.tree.GetSelection():
         if not Presenter.applied: Presenter.update()
         Presenter.setData(self.tree.root)
Example #27
0
 def OnComponentCreate(self, evt):
     '''Hadnler for creating new elements.'''
     state = self.tree.GetFullState() # state just before
     comp = Manager.findById(evt.GetId())
     if comp.groups[0] == 'component':
         node = Model.createComponentNode('Component')
         item = Presenter.create(comp, node)
     else:
         item = Presenter.create(comp)
     itemIndex = self.tree.ItemFullIndex(item)
     g.undoMan.RegisterUndo(undo.UndoPasteCreate(itemIndex, state))
Example #28
0
 def OnCollapse(self, evt):
     # Prevent multiple calls to setData
     self.tree.Unbind(wx.EVT_TREE_ITEM_COLLAPSED)
     if self.tree.GetSelection(): 
         map(self.tree.CollapseAllChildren, self.tree.GetSelections())
     else: 
         self.tree.CollapseAll()
     self.tree.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnTreeItemCollapsed)
     if not self.tree.GetSelection():
         if not Presenter.applied: Presenter.update()
         Presenter.setData(self.tree.root)
Example #29
0
 def OnButtonEdit(self, evt):
     if self.textModified:  # text has newer value
         self.value = self.GetValue()
     dlg = ContentDialog(self, self.value)
     if dlg.ShowModal() == wx.ID_OK:
         value = []
         for i in range(dlg.list.GetCount()):
             value.append(dlg.list.GetString(i))
         self.SetValue(value)
         Presenter.setApplied(False)
         self.textModified = False
     dlg.Destroy()
Example #30
0
 def OnButtonEdit(self, evt):
     if self.textModified:           # text has newer value
         self.value = self.GetValue()
     dlg = ContentCheckListDialog(self, self.value)
     if dlg.ShowModal() == wx.ID_OK:
         value = []
         for i in range(dlg.list.GetCount()):
             value.append((dlg.list.GetString(i), int(dlg.list.IsChecked(i))))
         self.SetValue(value)
         Presenter.setApplied(False)
         self.textModified = False
     dlg.Destroy()
Example #31
0
    def _cg_bcg_bcbcg_least_square_exp(self):
        """ """
        print("_cg_bcg_bcbcg_least_square_exp starting, ... ")
        self._BB_1  = np.random.random( ( self._mat.shape[0],1) )

        self._BX_1  = np.ones ( (self._mat.shape[1],1) )
        self._BB_4  = np.random.random( ( self._mat.shape[0],4) )
        self._BX_4  = np.ones ( (self._mat.shape[1],4) )
        self._BB_12 = np.random.random( ( self._mat.shape[0],12) )
        self._BX_12 = np.ones ( (self._mat.shape[1],12) )

        #line 1
        bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_1, self._BB_1, self._tol, self._maxiter)
        self._final_X_cg, self._final_R_cg, self._residual_hist_cg = bcg_solver_obj.bcg_variant_lstsq_run(0)

        ##line 2
        bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_12, self._BB_12, self._tol, self._maxiter)
        self._final_X_bcg_m12, self._final_R_bcg_m12, self._residual_hist_bcg_m12 = bcg_solver_obj.bcg_variant_lstsq_run(0)

        ##line 3
        #bcbcg_solver_obj = BCBCG()
        #self._final_x_bcbcg_m1s2, self._final_r_bcbcg_m1s2, self._residual_hist_bcbcg_m1s2 = \
        #        bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, 2, self._tol, self._maxiter, 0)

        ##line 4
        #bcbcg_solver_obj = BCBCG()
        #self._final_x_bcbcg_m1s8, self._final_r_bcbcg_m1s8, self._residual_hist_bcbcg_m1s8 = \
        #        bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, 8, self._tol, self._maxiter, 0)

        ##line 5
        #bcbcg_solver_obj = BCBCG()
        #self._final_x_bcbcg_m4s2, self._final_r_bcbcg_m4s2, self._residual_hist_bcbcg_m4s2 = \
        #        bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 2, self._tol, self._maxiter, 0)

        ##line 6
        #bcbcg_solver_obj = BCBCG()
        #self._final_x_bcbcg_m4s8, self._final_r_bcbcg_m4s8, self._residual_hist_bcbcg_m4s8 = \
        #        bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 8, self._tol, self._maxiter, 0)

        plot_worker = Presenter()
        #residual_list = [self._residual_hist_cg, self._residual_hist_bcg_m12,  \
        #                 self._residual_hist_bcbcg_m1s2, self._residual_hist_bcbcg_m1s8, \
        #                 self._residual_hist_bcbcg_m4s2, self._residual_hist_bcbcg_m4s8 ]
        residual_list = [self._residual_hist_cg, self._residual_hist_bcg_m12]

        #legend_list = ["cg","bcg_m12", "bcbcg_m1s2", "bcbcg_m1s8", "bcbcg_m4s2", "bcbcg_m4s8"]
        legend_list = ["cg","bcg_m12"]
        #color_list = ["r","k","b","y","m","g"]
        color_list = ["r","k"]
        #plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
        #plot_worker.instant_plot_y_log10(residual_list, "wathen100(dim=30,401, nnz=471,601, cond=5816.01 )", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
        plot_worker.instant_plot_y_log10(residual_list, "MG", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
Example #32
0
    def _cg_bcg_bcbcg_least_square_exp(self):
        """ """
        print("_cg_bcg_bcbcg_least_square_exp starting, ... ")
        self._BB_1  = np.random.random( ( self._mat.shape[0],1) )

        self._BX_1  = np.ones ( (self._mat.shape[1],1) )
        self._BB_4  = np.random.random( ( self._mat.shape[0],4) )
        self._BX_4  = np.ones ( (self._mat.shape[1],4) )
        self._BB_12 = np.random.random( ( self._mat.shape[0],12) )
        self._BX_12 = np.ones ( (self._mat.shape[1],12) )

        #line 1
        bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_1, self._BB_1, self._tol, self._maxiter)
        self._final_X_cg, self._final_R_cg, self._residual_hist_cg = bcg_solver_obj.bcg_variant_lstsq_run(0)

        ##line 2
        bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_12, self._BB_12, self._tol, self._maxiter)
        self._final_X_bcg_m12, self._final_R_bcg_m12, self._residual_hist_bcg_m12 = bcg_solver_obj.bcg_variant_lstsq_run(0)

        ##line 3
        #bcbcg_solver_obj = BCBCG()
        #self._final_x_bcbcg_m1s2, self._final_r_bcbcg_m1s2, self._residual_hist_bcbcg_m1s2 = \
        #        bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, 2, self._tol, self._maxiter, 0)

        ##line 4
        #bcbcg_solver_obj = BCBCG()
        #self._final_x_bcbcg_m1s8, self._final_r_bcbcg_m1s8, self._residual_hist_bcbcg_m1s8 = \
        #        bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, 8, self._tol, self._maxiter, 0)

        ##line 5
        #bcbcg_solver_obj = BCBCG()
        #self._final_x_bcbcg_m4s2, self._final_r_bcbcg_m4s2, self._residual_hist_bcbcg_m4s2 = \
        #        bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 2, self._tol, self._maxiter, 0)

        ##line 6
        #bcbcg_solver_obj = BCBCG()
        #self._final_x_bcbcg_m4s8, self._final_r_bcbcg_m4s8, self._residual_hist_bcbcg_m4s8 = \
        #        bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 8, self._tol, self._maxiter, 0)

        plot_worker = Presenter()
        #residual_list = [self._residual_hist_cg, self._residual_hist_bcg_m12,  \
        #                 self._residual_hist_bcbcg_m1s2, self._residual_hist_bcbcg_m1s8, \
        #                 self._residual_hist_bcbcg_m4s2, self._residual_hist_bcbcg_m4s8 ]
        residual_list = [self._residual_hist_cg, self._residual_hist_bcg_m12]

        #legend_list = ["cg","bcg_m12", "bcbcg_m1s2", "bcbcg_m1s8", "bcbcg_m4s2", "bcbcg_m4s8"]
        legend_list = ["cg","bcg_m12"]
        #color_list = ["r","k","b","y","m","g"]
        color_list = ["r","k"]
        #plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
        #plot_worker.instant_plot_y_log10(residual_list, "wathen100(dim=30,401, nnz=471,601, cond=5816.01 )", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
        plot_worker.instant_plot_y_log10(residual_list, "MG", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
Example #33
0
    def OnComponentTool(self, evt):
        '''Hadnler for creating new elements.'''
        comp = Manager.findById(evt.GetId())

        # Check compatibility
        if Presenter.checkCompatibility(comp):
            g.undoMan.RegisterUndo(undo.UndoGlobal())  # !!! TODO
            if comp.groups[0] == 'component':
                node = Model.createComponentNode('Component')
                Presenter.create(comp, node)
            else:
                Presenter.create(comp)
        evt.Skip()
Example #34
0
    def _db_bcbcg_lstsq (self):
        """ """
        bcbcg_solver_obj = BCBCG()
        self._final_X_a, self._final_R_a, self._residual_hist_a = \
               bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB, self._BX, self._step_val, self._tol, self._maxiter,0)
        self._final_X_b, self._final_R_b, self._residual_hist_b = \
               bcbcg_solver_obj.bcbcg_solver(self._mat, self._BB, self._BX, self._step_val, self._tol, self._maxiter,0)

        plot_worker = Presenter()
        residual_list = [self._residual_hist_a, self._residual_hist_b]
        legend_list = ["bcbcg_s20b4_lstsq","bcbcg_s20b4"]
        color_list = ["r","k"]
        plot_worker.instant_plot_y_log10(residual_list, "crystm02", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list)
Example #35
0
    def _db_bcbcg_lstsq (self):
        """ """
        bcbcg_solver_obj = BCBCG()
        self._final_X_a, self._final_R_a, self._residual_hist_a = \
               bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB, self._BX, self._step_val, self._tol, self._maxiter,0)
        self._final_X_b, self._final_R_b, self._residual_hist_b = \
               bcbcg_solver_obj.bcbcg_solver(self._mat, self._BB, self._BX, self._step_val, self._tol, self._maxiter,0)

        plot_worker = Presenter()
        residual_list = [self._residual_hist_a, self._residual_hist_b]
        legend_list = ["bcbcg_s20b4_lstsq","bcbcg_s20b4"]
        color_list = ["r","k"]
        plot_worker.instant_plot_y_log10(residual_list, "crystm02", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list)
Example #36
0
    def _db_cbcg_lstsq (self):
        cbcg_solver_obj = CBCG()
        self._final_x_a, self._final_r_a, self._residual_hist_a = \
               cbcg_solver_obj.cbcg_solver_least_square(self._mat, self._SB, self._SX, self._step_val, self._tol, self._maxiter)

        self._final_x_b, self._final_r_b, self._residual_hist_b = \
               cbcg_solver_obj.cbcg_solver_least_square(self._mat, self._SB, self._SX, self._step_val, self._tol, self._maxiter)

        plot_worker = Presenter()
        residual_list = [self._residual_hist_a, self._residual_hist_b]
        legend_list = ["cbcg_s2_lstsq","blbcg_s2"]
        color_list = ["r","k"]
        plot_worker.instant_plot_y_log10(residual_list, "bodyy6", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list)
Example #37
0
 def OnToolPaste(self, evt):
     '''frame.ID_TOOL_PASTE handler.'''
     state = wx.GetMouseState()
     # Ctrl+click does not work with tools on Mac, Alt+click often
     # bound to window move on wxGTK
     if wx.Platform == '__WXMAC__':
         forceSibling = state.AltDown()
     else:
         forceSibling = state.ControlDown()
     forceInsert = state.ShiftDown()
     g.Presenter.updateCreateState(forceSibling, forceInsert)
     g.undoMan.RegisterUndo(undo.UndoGlobal()) 
     Presenter.paste()
Example #38
0
 def OnToolPaste(self, evt):
     '''frame.ID_TOOL_PASTE handler.'''
     state = wx.GetMouseState()
     # Ctrl+click does not work with tools on Mac, Alt+click often
     # bound to window move on wxGTK
     if wx.Platform == '__WXMAC__':
         forceSibling = state.AltDown()
     else:
         forceSibling = state.ControlDown()
     forceInsert = state.ShiftDown()
     g.Presenter.updateCreateState(forceSibling, forceInsert)
     g.undoMan.RegisterUndo(undo.UndoGlobal())
     Presenter.paste()
Example #39
0
    def _db_cbcg_lstsq (self):
        cbcg_solver_obj = CBCG()
        self._final_x_a, self._final_r_a, self._residual_hist_a = \
               cbcg_solver_obj.cbcg_solver_least_square(self._mat, self._SB, self._SX, self._step_val, self._tol, self._maxiter)

        self._final_x_b, self._final_r_b, self._residual_hist_b = \
               cbcg_solver_obj.cbcg_solver_least_square(self._mat, self._SB, self._SX, self._step_val, self._tol, self._maxiter)

        plot_worker = Presenter()
        residual_list = [self._residual_hist_a, self._residual_hist_b]
        legend_list = ["cbcg_s2_lstsq","blbcg_s2"]
        color_list = ["r","k"]
        plot_worker.instant_plot_y_log10(residual_list, "bodyy6", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list)
Example #40
0
class View():
    def __init__(self):
        self.presenter = Presenter()

    def cli(self):
        choice = 0
        while choice != 3:
            choice = self.__endless_menu(self.__main_menu)
            if choice == 1:
                self.presenter.load_data()
                print('обновлено')

            elif choice == 2:
                day = self.__endless_menu(self.__compare_menu)

                while not (1 <= day <= 7):
                    print('неверный параметр')
                    day = self.__endless_menu(self.__compare_menu)

                result = self.presenter.compare_two_date(day)
                if result is None:
                    print('ошибка')
                    continue

                print(
                    'разница сегодняшней погоды и погоды через {} дня составляет {}%'
                    .format(day, result))

    def __endless_menu(self, menu):

        choice = menu()

        while not choice.isdigit():
            if not choice.isdigit():
                print('неверный параметр')

            choice = menu()

        return int(choice)

    def __main_menu(self):
        return input("""
        1 - обновить базу
        2 - указать день
        3 - выход
        """)

    def __compare_menu(self):
        return input("""
        за какой день нужно узнать? (1-7)
        """)
Example #41
0
    def _cg_bcg_bcbcg_least_square_exp(self):
        """ """
        self._BB_1  = np.random.random( ( self._mat.shape[0],1) )
        self._BX_1  = np.ones ( (self._mat.shape[1],1) )
        self._BB_6  = np.random.random( ( self._mat.shape[0],6) )
        self._BX_6  = np.ones ( (self._mat.shape[1],6) )
        self._BB_12 = np.random.random( ( self._mat.shape[0],12) )
        self._BX_12 = np.ones ( (self._mat.shape[1],12) )

        #line 1
        bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_1, self._BB_1, self._tol, self._maxiter)
        self._final_X_cg, self._final_R_cg, self._residual_hist_cg = bcg_solver_obj.bcg_variant_lstsq_run(0)

        #line 2
        bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_12, self._BB_12, self._tol, self._maxiter)
        self._final_X_bcg_m12, self._final_R_bcg_m12, self._residual_hist_bcg_m12 = bcg_solver_obj.bcg_variant_lstsq_run(0)

        #line 3
        bcbcg_solver_obj = BCBCG()
        self._final_x_bcbcg_m1s2, self._final_r_bcbcg_m1s2, self._residual_hist_bcbcg_m1s2 = \
                bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, 2, self._tol, self._maxiter, 0)

        #line 4
        #bcbcg_solver_obj = BCBCG()
        #self._final_x_bcbcg_m1s6, self._final_r_bcbcg_m1s6, self._residual_hist_bcbcg_m1s6 = \
        #        bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, 6, self._tol, self._maxiter, 0)
        bcbcg_solver_obj = BCBCG()
        self._final_x_bcbcg_m1s6, self._final_r_bcbcg_m1s6, self._residual_hist_bcbcg_m1s6 = \
                bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, 8, self._tol, self._maxiter, 0)

        #line 5
        bcbcg_solver_obj = BCBCG()
        self._final_x_bcbcg_m6s2, self._final_r_bcbcg_m6s2, self._residual_hist_bcbcg_m6s2 = \
                bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 2, self._tol, self._maxiter, 0)

        #line 6
        #bcbcg_solver_obj = BCBCG()
        #self._final_x_bcbcg_m6s6, self._final_r_bcbcg_m6s6, self._residual_hist_bcbcg_m6s6 = \
        #        bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 6, self._tol, self._maxiter, 0)
        bcbcg_solver_obj = BCBCG()
        self._final_x_bcbcg_m6s6, self._final_r_bcbcg_m6s6, self._residual_hist_bcbcg_m6s6 = \
                bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 8, self._tol, self._maxiter, 0)

        plot_worker = Presenter()
        residual_list = [self._residual_hist_cg, self._residual_hist_bcg_m12,  \
                         self._residual_hist_bcbcg_m1s2, self._residual_hist_bcbcg_m1s6, \
                         self._residual_hist_bcbcg_m6s2, self._residual_hist_bcbcg_m6s6 ]

        legend_list = ["cg","bcg_m12", "bcbcg_m1s2", "bcbcg_m1s6", "bcbcg_m6s2", "bcbcg_m6s6"]
        color_list = ["r","k","b","y","m","g"]
        plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
Example #42
0
    def _bcbcg_blbcg_least_square_exp_b(self):
        """ figure 2"""
        print("_bcbcg_blbcg_least_square_exp_b starting ... ")

        m=3
        self._BB  = np.random.random( ( self._mat.shape[0],m) )
        self._BX  = np.ones ( (self._mat.shape[1],m) )


        #line 1
        blbcg_solver_obj = BLBCG()
        self._final_x_blbcg_a, self._final_r_blbcg_a, self._residual_hist_blbcg_a = \
                blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB, self._BX, 16, self._tol, self._maxiter, 0)
        #line 2
        blbcg_solver_obj = BLBCG()
        self._final_x_blbcg_b, self._final_r_blbcg_b, self._residual_hist_blbcg_b = \
                blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB, self._BX, 32, self._tol, self._maxiter, 0)

        #line addition 
        #blbcg_solver_obj = BLBCG()
        #self._final_x_blbcg_c, self._final_r_blbcg_c, self._residual_hist_blbcg_c = \
        #        blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 32, self._tol, self._maxiter, 0)

        #line 3
        bcbcg_solver_obj = BCBCG()
        self._final_x_bcbcg_a, self._final_r_bcbcg_a, self._residual_hist_bcbcg_a = \
                bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB, self._BX, 16, self._tol, self._maxiter, 0)
        #line 4
        bcbcg_solver_obj = BCBCG()
        self._final_x_bcbcg_b, self._final_r_bcbcg_b, self._residual_hist_bcbcg_b = \
                bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB, self._BX, 32, self._tol, self._maxiter, 0)

        #line addition
        #bcbcg_solver_obj = BCBCG()
        #self._final_x_bcbcg_c, self._final_r_bcbcg_c, self._residual_hist_bcbcg_c = \
        #        bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 32, self._tol, self._maxiter, 0)


        plot_worker = Presenter()
        #residual_list = [self._residual_hist_blbcg_a, self._residual_hist_blbcg_b, self._residual_hist_blbcg_c, \
        #                 self._residual_hist_bcbcg_a, self._residual_hist_bcbcg_b, self._residual_hist_bcbcg_c  ]
        residual_list = [self._residual_hist_blbcg_a, self._residual_hist_blbcg_b,  \
                         self._residual_hist_bcbcg_a, self._residual_hist_bcbcg_b  ]

        #legend_list = ["blbcg_m4s4", "blbcg_m4s8", "blbcg_m4s12", "bcbcg_m4s4", "bcbcg_m4s8", "bcbcg_m4s12"]
        legend_list = ["blbcg_m3s16", "blbcg_m3s32", "bcbcg_m3s16", "bcbcg_m3s32"]

        #color_list = ["r","k","b","y","g","m"]
        color_list = ["r","k","b","g"]
        #plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
        plot_worker.instant_plot_y_log10(residual_list, "bodyy6", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
Example #43
0
    def OnDismiss(self):
        combo = self.GetCombo()
        value = []
        for i in range(self.GetCount()):
            if self.IsChecked(i):
                value.append(self.values[i])
        # Add ignored flags
        value.extend(self.ignored)
        strValue = '|'.join(value)
        if combo.GetValue() != strValue:
            combo.SetValue(strValue)
            Presenter.setApplied(False)

        wx.combo.ComboPopup.OnDismiss(self)
Example #44
0
    def _db_power_iteration(self):
        pi_worker = PowerIteration();
        tol = 1e-4
        maxiters = 1000
        self._v_eigen, self._lambda_eigen, self._lambda_eigen_list = pi_worker.naive_power_iteration (self._mat, self._X, maxiters, tol)

        self._v_shift_eigen, self._lambda_shift_eigen, self._lambda_shift_eigen_list = pi_worker.power_iteration_with_shifting (self._mat, self._X, self._lambda_eigen, maxiters, tol)
        print ("lambda ", self._lambda_shift_eigen)

        plot_worker = Presenter()
        ratio_list = [ [x+self._lambda_eigen for x in self._lambda_shift_eigen_list] ]
        legend_list = ["naive power iteration"]
        color_list = ["k"]
        plot_worker.instant_plot_y_log10(ratio_list, "crystm01" , "#iteration", "$\\frac{\\lambda_{old} - \\lambda_{new}}{\\lambda_i{old} }$", legend_list, color_list)
Example #45
0
def find_data(user_id):
    """
    Return user's data in JSON.
    """
    presenter = Presenter(user_id)

    response = {
        'user_id': user_id,
        'top_favorites': presenter.get_data('TF'),
        'nearest_neighbours': presenter.get_data('NN'),
        'latent_factors': presenter.get_data('LF')
    }

    return jsonify(response)
Example #46
0
def find_poster_raw(user_id):
    """
    Return User's Profile in JSON.
    """
    presenter = Presenter(user_id)

    response = {
        'user_id': user_id,
        'top_favorites': presenter.get_posters('TF', 8),
        'nearest_neighbours': presenter.get_posters('NN', 8),
        'latent_factors': presenter.get_posters('LF', 8)
    }

    return jsonify(response)
Example #47
0
    def OnDismiss(self):
        combo = self.GetCombo()
        value = []
        for i in range(self.GetCount()):
            if self.IsChecked(i):
                value.append(self.values[i])
        # Add ignored flags
        value.extend(self.ignored)
        strValue = '|'.join(value)
        if combo.GetValue() != strValue:
            combo.SetValue(strValue)
            Presenter.setApplied(False)

        wx.combo.ComboPopup.OnDismiss(self)
Example #48
0
 def OnButtonEdit(self, evt):
     if self.textModified:  # text has newer value
         self.value = self.GetValue()
     dlg = ContentHelpListDialog(self, self.value)
     if dlg.ShowModal() == wx.ID_OK:
         value = []
         for i in range(dlg.list.GetItemCount()):
             value.append((str(dlg.list.GetItem(i, 0).GetText()),
                           str(dlg.list.GetItem(i, 1).GetText()),
                           str(dlg.list.GetItem(i, 2).GetText())))
         self.SetValue(value)
         Presenter.setApplied(False)
         self.textModified = False
     dlg.Destroy()
Example #49
0
class View:
    def __init__(self):
        self.presenter = Presenter(self)
        self.tkinter = tk.Tk()
        self.app = application.Application(tkinter=self.tkinter, view=self)
        self.auto_update()
        self.app.mainloop()

    def update(self, seconds, state):
        time_string = time.strftime(TIME_FORMAT, time.gmtime(seconds))
        is_running = state == State.RUNNING
        is_idle = state == State.IDLE
        self.app.update_widgets(time_string, is_running, is_idle)

    def auto_update(self):
        self.presenter.update_time()
        self.presenter.update_view()

        # schedule a call to auto_update() after some time interval
        self.app.after(UPDATE_TIME_MSEC, self.auto_update)

    # Widget interaction handlers

    def handle_start(self):
        self.presenter.handle_event(Button.START)

    def handle_reset(self):
        self.presenter.handle_event(Button.RESET)

    def handle_quit(self):
        self.tkinter.destroy()
Example #50
0
 def OnButtonEdit(self, evt):
     if self.textModified:           # text has newer value
         self.value = self.GetValue()
     dlg = ContentHelpListDialog(self, self.value)
     if dlg.ShowModal() == wx.ID_OK:
         value = []
         for i in range(dlg.list.GetItemCount()):
             value.append((str(dlg.list.GetItem(i, 0).GetText()),
                           str(dlg.list.GetItem(i, 1).GetText()),
                           str(dlg.list.GetItem(i, 2).GetText())))
         self.SetValue(value)
         Presenter.setApplied(False)
         self.textModified = False
     dlg.Destroy()
Example #51
0
 def OnPickFont(self, evt):
     font = evt.GetFont()
     if font.GetEncoding() == wx.FONTENCODING_SYSTEM:
         encName = ''
     else:
         encName = wx.FontMapper.GetEncodingName(font.GetEncoding()).encode()
     value = {'size': str(font.GetPointSize()),
              'family': fontFamiliesWx2Xml.get(font.GetFamily(), "default"),
              'style': fontStylesWx2Xml.get(font.GetStyle(), "normal"),
              'weight': fontWeightsWx2Xml.get(font.GetWeight(), "normal"),
              'underlined': str(int(font.GetUnderlined())),
              'face': font.GetFaceName().encode(),
              'encoding': encName}
     self.SetValue(value)
     Presenter.setApplied(False)
Example #52
0
 def OnButtonEdit(self, evt):
     if self.textModified:           # text has newer value
         try:
             self.value = self.text.GetValue().split('|')
         except ValueError:
             self.value = []
     dlg = IntListDialog(self, self.value)
     if dlg.ShowModal() == wx.ID_OK:
         value = []
         for i in range(dlg.list.GetCount()):
             value.append(dlg.list.GetString(i))
         self.SetValue(value)
         Presenter.setApplied()
         self.textModified = False
     dlg.Destroy()
Example #53
0
 def OnPickFont(self, evt):
     font = evt.GetFont()
     if font.GetEncoding() == wx.FONTENCODING_SYSTEM:
         encName = ''
     else:
         encName = wx.FontMapper.GetEncodingName(font.GetEncoding()).encode()
     value = {'size': str(font.GetPointSize()),
              'family': fontFamiliesWx2Xml.get(font.GetFamily(), "default"),
              'style': fontStylesWx2Xml.get(font.GetStyle(), "normal"),
              'weight': fontWeightsWx2Xml.get(font.GetWeight(), "normal"),
              'underlined': str(int(font.GetUnderlined())),
              'face': font.GetFaceName().encode(),
              'encoding': encName}
     self.SetValue(value)
     Presenter.setApplied(False)
Example #54
0
def find_poster(user_id):
    """
    User's Profile Page.
    """
    presenter = Presenter(user_id)

    response = {
        'header': 'OpenREC',
        'user_id': user_id,
        'top_favorites': presenter.get_posters('TF', 8),
        'nearest_neighbours': presenter.get_posters('NN', 8),
        'latent_factors': presenter.get_posters('LF', 8)
    }

    return render_template('user.html', data=response)
Example #55
0
 def OnButtonEdit(self, evt):
     if self.textModified:  # text has newer value
         try:
             self.value = self.text.GetValue().split('|')
         except ValueError:
             self.value = []
     dlg = IntListDialog(self, self.value)
     if dlg.ShowModal() == wx.ID_OK:
         value = []
         for i in range(dlg.list.GetCount()):
             value.append(dlg.list.GetString(i))
         self.SetValue(value)
         Presenter.setApplied()
         self.textModified = False
     dlg.Destroy()
Example #56
0
    def _cg_bcg_bcbcg_blcg_exp(self, block_size):
        """ """
        print("_cg_bcg_bcbcg_least_square_exp starting, ... ")
        self._BB_1 = np.random.random((self._mat.shape[0], 1))
        self._BX_1 = np.ones((self._mat.shape[1], 1))
        self._BB_X = np.random.random((self._mat.shape[0], block_size))
        self._BX_X = np.ones((self._mat.shape[1], block_size))

        #line 1
        bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_1,
                                                      self._BB_1, self._tol,
                                                      self._maxiter)
        self._final_X_cg, self._final_R_cg, self._residual_hist_cg = bcg_solver_obj.bcg_variant_lstsq_run(
            0)

        ##line 2
        bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_X,
                                                      self._BB_X, self._tol,
                                                      self._maxiter)
        self._final_X_bcg_mX, self._final_R_bcg_mX, self._residual_hist_bcg_mX = bcg_solver_obj.bcg_variant_lstsq_run(
            0)

        #line 3
        bcbcg_solver_obj = BCBCG()
        self._final_x_bcbcg_m1sY, self._final_r_bcbcg_m1sY, self._residual_hist_bcbcg_m1sY = \
                bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, self._step_val, self._tol, self._maxiter, 0)

        #line 4
        bcbcg_solver_obj = BCBCG()
        self._final_x_bcbcg_mXsY, self._final_r_bcbcg_mXsY, self._residual_hist_bcbcg_mXsY = \
                bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_X, self._BX_X, self._step_val, self._tol, self._maxiter, 0)

        #line 5
        blbcg_solver_obj = BLBCG()
        self._final_x_blbcg_mXsY, self._final_r_blbcg_mXsY, self._residual_hist_blbcg_mXsY = \
                blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB_X, self._BX_X, self._step_val, self._tol, self._maxiter, 0)

        plot_worker = Presenter()
        residual_list = [self._residual_hist_cg, self._residual_hist_bcg_mX, self._residual_hist_bcbcg_m1sY, \
                self._residual_hist_bcbcg_mXsY, self._residual_hist_blbcg_mXsY]

        legend_list = ["cg","bcg_m"+str(block_size), "bcbcg_m1_s"+str(self._step_val), \
                "bcbcg_m"+str(block_size)+"s"+str(self._step_val), "blbcg_m"+str(block_size)+"s"+str(self._step_val)]
        color_list = ["r", "k", "b", "g", "m"]
        plot_worker.instant_plot_y_log10(
            residual_list, "MG", "#iteration",
            "$\\mathbf{log_{10}\\frac{||r_1||}{||b_1||}}$", legend_list,
            color_list)
 def OnTreeSelChanging(self, evt):
     #TRACE('OnTreeSelChanging: %s=>%s', evt.GetOldItem(), evt.GetItem())
     #TRACE('Selection: %s', self.tree.GetSelections())
     if not self.tree.GetSelections(): return
     # Permit multiple selection for same level only
     state = wx.GetMouseState()
     oldItem = evt.GetOldItem()
     if oldItem and (state.ShiftDown() or state.ControlDown()) and \
        self.tree.GetItemParent(oldItem) != self.tree.GetItemParent(evt.GetItem()):
         evt.Veto()
         self.frame.SetStatusText('Veto selection (not same level)')
         return
     # If panel has a pending undo, register it
     if Presenter.panelIsDirty():
         Presenter.registerUndoEdit()
     evt.Skip()