class PCABasisProcessor(object): def __init__(self,*args, **kwargs): self.args=args self.kwargs=kwargs self.directory=None def process(self,v): self.ipca=IncrementalPCAdimred(-1,*self.args, **self.kwargs) self.ipca.add_train(v) self.ipca.recompute() return self.ipca.M
def init(self,odim, burnin=300,*args, **kwargs): self.pcafilename=self.directory+"/pca.pcl" try: self.ipca=IncrementalPCAdimred.load(self.pcafilename) if (self.ibow==None): raise Exception self.model_node.status=genericmodel.STATUS_READY pycvf_debug(10, "loaded"+ self.pcafilename+"...") except: self.ipca=IncrementalPCAdimred(-1,odim,*args, **kwargs) #self.ibow.set_filename(self.bowfilename) self.model_node.status=genericmodel.STATUS_NOT_READY self.totrain=burnin
class IPCAProcessor(object): def __init__(self,*args, **kwargs): self.args=args self.kwargs=kwargs self.directory=None def init(self,odim, burnin=300,*args, **kwargs): self.pcafilename=self.directory+"/pca.pcl" try: self.ipca=IncrementalPCAdimred.load(self.pcafilename) if (self.ibow==None): raise Exception self.model_node.status=genericmodel.STATUS_READY pycvf_debug(10, "loaded"+ self.pcafilename+"...") except: self.ipca=IncrementalPCAdimred(-1,odim,*args, **kwargs) #self.ibow.set_filename(self.bowfilename) self.model_node.status=genericmodel.STATUS_NOT_READY self.totrain=burnin def set_model_node(self,model): self.model_node=model self.directory=model.get_directory() self.init(*self.args,**self.kwargs) def on_model_destroy(self,model): self.save() self.model_node=None def process(self,v): if (self.totrain): q=min(v.shape[0],self.totrain) self.totrain-=q self.ipca.add_train(v[:q]) if (self.totrain==0): self.ipca.recompute() self.save() if (v.shape[0]==q): self.model_node.status=genericmodel.STATUS_NOT_READY raise NotReady else: v=v[q:] try: assert(v.ndim==2) r=self.ipca.dimred(v) except KeyboardInterrupt: raise except Exception,e: print e self.model_node.status=genericmodel.STATUS_NOT_READY raise NotReady self.model_node.status=genericmodel.STATUS_READY return r
def process(self,v): self.ipca=IncrementalPCAdimred(-1,*self.args, **self.kwargs) self.ipca.add_train(v) self.ipca.recompute() return self.ipca.M