def importanceMixing(oldpoints, oldpdf, newpdf, newdistr, forcedRefresh=0.01):
 reuseindices = []
 batch = len(oldpoints)
 for (i, sample) in enumerate(oldpoints):
  r = uniform(0, 1)
  if (r < (((1 - forcedRefresh) * newpdf(sample)) / oldpdf(sample))):
   reuseindices.append(i)
  if ((batch - len(reuseindices)) <= max(1, (batch * forcedRefresh))):
   break
 newpoints = []
 while ((len(reuseindices) + len(newpoints)) < batch):
  r = uniform(0, 1)
  sample = newdistr()
  if (r < forcedRefresh):
   newpoints.append(sample)
  elif (r < (1 - (oldpdf(sample) / newpdf(sample)))):
   newpoints.append(sample)
 return (reuseindices, newpoints)

def importanceMixing ( oldpoints , oldpdf , newpdf , newdistr , forcedRefresh = 0.01 ) : reuseindices = [ ] batch = len ( oldpoints ) for ( i , sample ) in enumerate ( oldpoints ) : r = uniform ( 0 , 1 ) if ( r < ( ( ( 1 - forcedRefresh ) * newpdf ( sample ) ) / oldpdf ( sample ) ) ) : reuseindices . append ( i ) if ( ( batch - len ( reuseindices ) ) <= max ( 1 , ( batch * forcedRefresh ) ) ) : break newpoints = [ ] while ( ( len ( reuseindices ) + len ( newpoints ) ) < batch ) : r = uniform ( 0 , 1 ) sample = newdistr ( ) if ( r < forcedRefresh ) : newpoints . append ( sample ) elif ( r < ( 1 - ( oldpdf ( sample ) / newpdf ( sample ) ) ) ) : newpoints . append ( sample ) return ( reuseindices , newpoints )
implements importance mixing .