Пример #1
0
  def do_svd(self):
    # make data array
    data = flex.double()
    for set in self.stored_series: 
      data.extend( set.as_1d() )

    cols = self.stored_series[0].size()
    rows = len(self.stored_series) 

    data.reshape( flex.grid(rows,cols) )
    from scitbx.linalg import svd
    svd_obj = svd.real( data.deep_copy(),True,True )
    for ii,ss in enumerate(svd_obj.sigma):
      print ii,ss, ss/flex.sum(svd_obj.sigma) 

   
    from scitbx.linalg import svd
    svd_obj = svd.real( self.m.deep_copy(),True,True )
    m_pseudo_inverse = svd_obj.pseudo_inverse()
    
    cols = len(self.stored_series)
    rows = 3
    print rows,cols, m_pseudo_inverse.focus() 
    deconvol = []
    for ith in range(rows):
      result = self.stored_series[0]*0.0
      for jset in range(cols):
        result += m_pseudo_inverse[ (ith,jset) ]*self.stored_series[jset]
      deconvol.append( result )
    write_generic_image(deconvol,'deconvol_series.data')

    write_generic_image(self.stored_series, 'series.dat')
Пример #2
0
  def do_all_series(self):
    for ii in range(self.navg):
      self.do_series()
    for ii in range(len(self.stored_series)):
      self.stored_series[ii]=self.stored_series[ii]/self.navg

    # do an svd analyses to find out what is going on
    mean = self.stored_series[0]*0.0
    new_data = flex.double()
    n = len(self.stored_series)
    for ii in range(n):
      mean = mean+self.stored_series[ii]
    mean = mean/n
    for ii in range(n):
      new_data.extend( (self.stored_series[ii]-mean).as_1d() )
    new_data.reshape( self.grid(n,mean.size() ) )
    
    from scitbx.linalg import svd
    svd_obj = svd.real( new_data.deep_copy(),True,True )
    for ii,ss in enumerate(svd_obj.sigma):
      print ii,ss, ss/flex.sum(svd_obj.sigma) , "MEAN EDUCED EV's"




    
    # get accurate fractions / kinetic data
    self.m = flex.double()
    for jj in range(len(self.stored_series)):
      print self.vals[jj], 'series vals'
      for oo in self.vals[jj]:
        self.m.append(oo/self.Ntot)
    self.m.reshape( flex.grid(len(self.stored_series),3) )
 def rank(cls, a):
   """ row rank of a """
   rank_revealing = svd.real(a.deep_copy(),
                             accumulate_u=False, accumulate_v=False)
   return rank_revealing.numerical_rank(rank_revealing.sigma[0]*1e-9)
Пример #4
0
 def rank(cls, a):
   """ row rank of a """
   rank_revealing = svd.real(a.deep_copy(),
                             accumulate_u=False, accumulate_v=False)
   return rank_revealing.numerical_rank(rank_revealing.sigma[0]*1e-9)
Пример #5
0
def tst_shapes():
  N=80
  length = 70
  width=10
  radius = 15
  from sastbx.fXS import basic_shapes
  rod = basic_shapes.rod(N,length,width,1.5)
  ball = basic_shapes.ball(N,radius,1.0)
  sball = basic_shapes.single_ball(N,radius,1.0)
  combo = rod+ball
  print "Building Rod"
  rod   = pad_around( enlarge(rod,1,sigma=3.0,full=True),   N  )
  print "Building Balls" 
  ball  = pad_around( enlarge(sball,1,sigma=3.0,full=True),  N  )
  print "Building Combo"
  combo = pad_around( enlarge(combo,1,sigma=3.0,full=True), N  )

  
  write_generic_image(rod,'rod.dat')
  write_generic_image(ball,'ball.dat')
  write_generic_image(combo,'combo.dat')

  frod   = build_scat_pat(rod) 
  fball  = build_scat_pat(ball)
  fcombo = build_scat_pat(combo)

  rod_lib   =  scat_pat_lib(frod,N=45)
  ball_lib  =  scat_pat_lib(fball,N=45)
  combo_lib =  scat_pat_lib(fcombo,N=45)


  #lets build c2 functiosn for each of these buggers
  np,np = fcombo.focus() 
  int_obj   = integration_object( np )
  c2_fball  = int_obj.build_c2_function(fball)
  c2_frod   = int_obj.build_c2_function(frod)
  c2_fcombo = int_obj.build_c2_function(fcombo)
  write_generic_image(c2_fball,  "c2_ball.dat")
  write_generic_image(c2_frod,   "c2_rod.dat")
  write_generic_image(c2_fcombo, "c2_combo.dat")


  t0_s = flex.double( [4, 5, 5] )
  t1_s = flex.double( [1, 11, 7] )
  t2_s = flex.double( [0, 9,  0] )
  t3_s = flex.double( [0,  0, 9] )

  eg = experiment_gen( [combo_lib,ball_lib,rod_lib] )

  mp = mixture_prep(eg, int_obj)
  mp.do_all_series()
  mp.do_svd()


  sys.exit()

  # build synthetic images
  t0_c2 =  c2_fcombo*t0_s[0] + c2_fball*t0_s[1] + c2_frod*t0_s[2]
  t1_c2 =  c2_fcombo*t1_s[0] + c2_fball*t1_s[1] + c2_frod*t1_s[2]
  t2_c2 =  c2_fcombo*t2_s[0] + c2_fball*t2_s[1] + c2_frod*t2_s[2]
  t3_c2 =  c2_fcombo*t3_s[0] + c2_fball*t3_s[1] + c2_frod*t3_s[2]
  a = flex.double( [4, 5, 5,1, 11, 7,0, 9,  0,0,  0, 9] )

  




  a.reshape( flex.grid(4,3) )
  from scitbx.linalg import svd
  svd_obj = svd.real( a.deep_copy(),True,True )
  a_pseudo_inverse = svd_obj.pseudo_inverse()
  print list( a_pseudo_inverse )
  print list(svd_obj.sigma) 

  rows,cols =  a_pseudo_inverse.focus()
  print rows, cols
  cal_back = []
  obs_sets = [ t0_c2 ,  t1_c2 ,  t2_c2,  t3_c2 ]
  deconvol = []
  for ith in range(rows):
    result = t0_c2*0.0
    for jset in range(cols):
      result += a_pseudo_inverse[ (ith,jset) ]*obs_sets[jset]
    deconvol.append( result )
  write_generic_image(deconvol,'deconvol.data')  


  MM = 10
  # DO T=0

  all_images = []

  res = c2_fball.deep_copy()*0.0
  synth = c2_fcombo*t0_s[0] + c2_fball*t0_s[1] + c2_frod*t0_s[2]
  write_generic_image(synth,"t0_calc.dat")

  for ii in range(MM):
    print "Do image ", ii+1
    ri =  eg.generate_random_image(t0_s,1.0)
    pc2 = int_obj.build_c2_function( ri )
    res += pc2
  res = res/MM
  t0_c2_obs = res.deep_copy()
  write_generic_image(res,"t0_obs.dat") 
    

  # Do T=1
  res = c2_fball.deep_copy()*0.0
  synth = c2_fcombo*t1_s[0] + c2_fball*t1_s[1] + c2_frod*t1_s[2]
  write_generic_image(synth,"t1_calc.dat")
  for ii in range(MM):
    print "Do image ", ii+1
    ri =  eg.generate_random_image(t1_s,1.0)
    res += int_obj.build_c2_function( ri )
  res = res/MM
  t1_c2_obs = res.deep_copy()
  write_generic_image(res,"t1_obs.dat") 

  # DO T=2
  res = c2_fball.deep_copy()*0.0
  synth = c2_fcombo*t2_s[0] + c2_fball*t2_s[1] + c2_frod*t2_s[2]
  write_generic_image(synth,"t2_calc.dat")
  for ii in range(MM):
    print "Do image ", ii+1
    ri =  eg.generate_random_image(t2_s,1.0)
    res += int_obj.build_c2_function( ri )
  res = res/MM
  t2_c2_obs = res.deep_copy()
  write_generic_image(res,"t2_obs.dat") 


  # DO T=3
  res = c2_fball.deep_copy()*0.0
  synth = c2_fcombo*t3_s[0] + c2_fball*t3_s[1] + c2_frod*t3_s[2]
  write_generic_image(synth,"t3_calc.dat")
  for ii in range(MM):
    print "Do image ", ii+1
    ri =  eg.generate_random_image(t3_s,1.0)
    res += int_obj.build_c2_function( ri )
  res = res/MM
  t3_c2_obs = res.deep_copy()
  write_generic_image(res,"t3_obs.dat")

  cal_back = []
  obs_sets = [ t0_c2_obs ,  t1_c2_obs ,  t2_c2_obs,  t3_c2_obs ]
  #deconvol = []
  for ith in range(rows):
    result = t0_c2*0.0
    for jset in range(cols):
      result += a_pseudo_inverse[ (ith,jset) ]*obs_sets[jset]
    deconvol.append( result )
  write_generic_image(deconvol,'deconvol_obs.data')