def setInitYslackViaLineSearch(self):
     res=[]
     for yslack in np.arange(-5,5,0.1):
         self.Yslack__.set_value(yslack)
         res.append((yslack, abs(self.Feedforward_(self.Times[0,:][None,:],self.n,self.theta)[0][0]- self.y.ix[0,0])))
     self.initYslack = pd.DataFrame(res,columns=['yslack','loss']).sort_values('loss').iloc[0].yslack
     self.reset()
 def fit(self,y=None,pos=1,verbose=0):
     timesIDX=y.abs().sum(1)!=0
     self.y= y[timesIDX]
     self.times= self.Times[np.where(timesIDX.values)[0]]
     obj0=self.getZeroObj()
     if self.initSviaLineSearch:
         self.setInitYslackViaLineSearch()
         self.setInitSviaLineSearch()
     self.reset()
     start_time=time.time()
     for i in range(self.maxIter):
         obj=self.Objective_(self.y,self.lr_s, self.lr_nu, self.lr_theta, self.times, (self.final_momentum , self.initial_momentum)[i<5],self.n, self.theta)
         if verbose>1:
             print obj ,self.S__.get_value(), self.Yslack__.get_value(),sig(self.c__.get_value())
     if verbose:
         print obj ,self.S__.get_value(), self.Yslack__.get_value(),sig(self.c__.get_value())
         
     negLogLikelihoodRatio=np.log(obj0)-np.log(self.Loss_(self.y,self.Feedforward_(self.times,self.n,self.theta)))
     s=np.asscalar(self.S__.get_value())
     if s<1e-6:
         negLogLikelihoodRatio=0
         s=0
     self.sol=pd.Series({'s':s,'LR':negLogLikelihoodRatio,'Time':time.time()-start_time,'pos':pos,'nu0':sig(self.c__.get_value()),'slack':np.asscalar(self.Yslack__.get_value()),'obj':float(obj), 'obj0':float(obj0), 'times': self.times, 'y':self.y, 'theta':self.theta, 'n':self.n, 'smoothTimes': np.tile(np.arange(self.times[0][0] , self.times[-1][0]+1),(self.sim.numReplicates,1)).T})
     return self.sol
 def linesearchS(self,y):
     S=np.arange(0,0.15,0.005)
     return pd.DataFrame([(s,self.computeLoss(y,s=s))  for s in S],columns=['s','loss']).sort_values('loss')
 def linesearchS(self,y):
     s=np.arange(0,0.5,0.01)
     return self.evaluate(y, s).sort_values('loss')
 def setInitYslackViaLineSearch(self):
     res=[]
     for yslack in np.arange(-5,5,0.1):
         self.Yslack__.set_value(yslack)
         res.append((yslack, self.Loss_(self.y,self.times,self.n,self.lastGenerationIndex,self.replicateIndex)))
     self.Yslack__.set_value(pd.DataFrame(res,columns=['yslack','loss']).sort_values('loss').iloc[0].yslack)