def next(self):
                X = self.XIterator.next()
                
                #Return the matrices P, Q as the learnt model
                if self.ZListSGD == None:
                    # assumption : training matrix centered by row and column
                    self.ZListSGD = self.baseLearner.learnModel(X, storeAll=False)
                else:
                    #In the case the matrix size changes, we alter P and Q to fit the new data     
                    P, Q = self.ZListSGD[0]
                                        
                    if X.shape[0] > P.shape[0]:
                        P = Util.extendArray(P, (X.shape[0], P.shape[1]))
                    elif X.shape[0] < P.shape[0]:
                        P = P[0:X.shape[0], :]

                    if X.shape[1] > Q.shape[0]:
                        Q = Util.extendArray(Q, (X.shape[1], Q.shape[1]))
                    elif X.shape[1] < Q.shape[0]:
                        Q = Q[0:X.shape[1], :]
                        
                    self.ZListSGD = [(P, Q)]
                    
                    try:
                        self.ZListSGD = self.baseLearner.learnModel(X, Z=self.ZListSGD, storeAll=False)
                    except FloatingPointError:
                        logging.warning("FloatingPointError encountered, reinitialise the matrix decomposition")
                        self.ZListSGD = self.baseLearner.learnModel(X, storeAll=False)
                    except ValueError:
                        logging.warning("ValueError encountered, reinitialise the matrix decomposition")
                        self.ZListSGD = self.baseLearner.learnModel(X, storeAll=False)
                    except SGDNorm2Reg.ArithmeticError:
                        logging.warning("ArithmeticError encountered, reinitialise the matrix decomposition")
                        self.ZListSGD = self.baseLearner.learnModel(X, storeAll=False)
                return self.ZListSGD
示例#2
0
            def next(self):
                X = self.XIterator.next()

                #Return the matrices P, Q as the learnt model
                if self.ZListSGD == None:
                    # assumption : training matrix centered by row and column
                    self.ZListSGD = self.baseLearner.learnModel(X,
                                                                storeAll=False)
                else:
                    #In the case the matrix size changes, we alter P and Q to fit the new data
                    P, Q = self.ZListSGD[0]

                    if X.shape[0] > P.shape[0]:
                        P = Util.extendArray(P, (X.shape[0], P.shape[1]))
                    elif X.shape[0] < P.shape[0]:
                        P = P[0:X.shape[0], :]

                    if X.shape[1] > Q.shape[0]:
                        Q = Util.extendArray(Q, (X.shape[1], Q.shape[1]))
                    elif X.shape[1] < Q.shape[0]:
                        Q = Q[0:X.shape[1], :]

                    self.ZListSGD = [(P, Q)]

                    try:
                        self.ZListSGD = self.baseLearner.learnModel(
                            X, Z=self.ZListSGD, storeAll=False)
                    except FloatingPointError:
                        logging.warning(
                            "FloatingPointError encountered, reinitialise the matrix decomposition"
                        )
                        self.ZListSGD = self.baseLearner.learnModel(
                            X, storeAll=False)
                    except ValueError:
                        logging.warning(
                            "ValueError encountered, reinitialise the matrix decomposition"
                        )
                        self.ZListSGD = self.baseLearner.learnModel(
                            X, storeAll=False)
                    except SGDNorm2Reg.ArithmeticError:
                        logging.warning(
                            "ArithmeticError encountered, reinitialise the matrix decomposition"
                        )
                        self.ZListSGD = self.baseLearner.learnModel(
                            X, storeAll=False)
                return self.ZListSGD