def propagate(self, segments):

        A, B, C, x0 = self.A, self.B, self.C, self.x0

        n_segs = len(segments)

        coords = numpy.empty((n_segs, self.coord_len, self.coord_ndim),
                             dtype=self.coord_dtype)

        for iseg, segment in enumerate(segments):
            coords[iseg, 0] = segment.pcoord[0]

        twopi_by_A = 2 * PI / A
        half_B = B / 2
        sigma = self.sigma
        gradfactor = self.sigma * self.sigma / 2
        coord_len = self.coord_len
        reflect_at = self.reflect_at
        all_displacements = numpy.zeros(
            (n_segs, self.coord_len, self.coord_ndim), dtype=self.coord_dtype)

        sink1 = -2.0
        sink2 = 0.0
        for istep in xrange(1, coord_len):
            x = coords[:, istep - 1, 0]

            #xarg = twopi_by_A*(x - x0)
            xarg = x

            eCx = numpy.exp(C * x)
            eCx_less_one = eCx - 1.0

            all_displacements[:, istep, 0] = displacements = random_normal(
                scale=sigma, size=(n_segs, ))
            #grad = half_B / (eCx_less_one*eCx_less_one)*(twopi_by_A*eCx_less_one*sin(xarg)+C*eCx*cos(xarg))
            grad = -2.0 * xarg * (1.0 - xarg * xarg)

            newx = x.copy()

            #Absorb trajectories reaching end point
            to_absorb1 = x > sink2
            to_absorb2 = x < sink1

            #propagete all trajectories
            newx = x - gradfactor * grad + displacements

            #absorb trajectories which reached sink
            newx[to_absorb1] = x[to_absorb1]
            newx[to_absorb2] = x[to_absorb2]

            coords[:, istep, 0] = newx

        for iseg, segment in enumerate(segments):
            segment.pcoord[...] = coords[iseg, :]
            segment.data['displacement'] = all_displacements[iseg]
            segment.status = segment.SEG_STATUS_COMPLETE

        return segments
Beispiel #2
0
    def propagate(self, segments):

        A, B, C, x0 = self.A, self.B, self.C, self.x0

        n_segs = len(segments)

        coords = np.empty((n_segs, self.coord_len, self.coord_ndim),
                          dtype=self.coord_dtype)

        for iseg, segment in enumerate(segments):
            coords[iseg, 0] = segment.pcoord[0]

        twopi_by_A = 2 * PI / A
        half_B = B / 2
        sigma = self.sigma
        gradfactor = self.sigma * self.sigma / 2
        coord_len = self.coord_len
        reflect_at = self.reflect_at
        all_displacements = np.zeros((n_segs, self.coord_len, self.coord_ndim),
                                     dtype=self.coord_dtype)
        for istep in range(1, coord_len):
            x = coords[:, istep - 1, 0]

            xarg = twopi_by_A * (x - x0)

            eCx = np.exp(C * x)
            eCx_less_one = eCx - 1.0

            all_displacements[:, istep, 0] = displacements = random_normal(
                scale=sigma, size=(n_segs, ))
            grad = half_B / (eCx_less_one * eCx_less_one) * (
                twopi_by_A * eCx_less_one * np.sin(xarg) +
                C * eCx * np.cos(xarg))

            newx = x - gradfactor * grad + displacements
            if reflect_at is not None:
                # Anything that has moved beyond reflect_at must move back that much

                # boolean array of what to reflect
                to_reflect = newx > reflect_at

                # how far the things to reflect are beyond our boundary
                reflect_by = newx[to_reflect] - reflect_at

                # subtract twice how far they exceed the boundary by
                # puts them the same distance from the boundary, on the other side
                newx[to_reflect] -= 2 * reflect_by
            coords[:, istep, 0] = newx

        for iseg, segment in enumerate(segments):
            segment.pcoord[...] = coords[iseg, :]
            segment.data['displacement'] = all_displacements[iseg]
            segment.status = segment.SEG_STATUS_COMPLETE

        return segments
Beispiel #3
0
 def propagate(self, segments):
     
     A, B, C, x0 = self.A, self.B, self.C, self.x0
     
     n_segs = len(segments)
 
     coords = numpy.empty((n_segs, self.coord_len, self.coord_ndim), dtype=self.coord_dtype)
     
     for iseg, segment in enumerate(segments):
         coords[iseg,0] = segment.pcoord[0]
         
     twopi_by_A = 2*PI/A
     half_B = B/2
     sigma = self.sigma
     gradfactor = self.sigma*self.sigma/2
     coord_len = self.coord_len
     reflect_at = self.reflect_at
     all_displacements = numpy.zeros((n_segs, self.coord_len, self.coord_ndim), dtype=self.coord_dtype)
     for istep in xrange(1,coord_len):
         x = coords[:,istep-1,0]
         
         xarg = twopi_by_A*(x - x0)
         
         eCx = numpy.exp(C*x)
         eCx_less_one = eCx - 1.0
        
         all_displacements[:,istep,0] = displacements = random_normal(scale=sigma, size=(n_segs,))
         grad = half_B / (eCx_less_one*eCx_less_one)*(twopi_by_A*eCx_less_one*sin(xarg)+C*eCx*cos(xarg))
         
         newx = x - gradfactor*grad + displacements
         if reflect_at is not None:
             # Anything that has moved beyond reflect_at must move back that much
             
             # boolean array of what to reflect
             to_reflect = newx > reflect_at
             
             # how far the things to reflect are beyond our boundary
             reflect_by = newx[to_reflect] - reflect_at
             
             # subtract twice how far they exceed the boundary by
             # puts them the same distance from the boundary, on the other side
             newx[to_reflect] -= 2*reflect_by
         coords[:,istep,0] = newx
         
     for iseg, segment in enumerate(segments):
         segment.pcoord[...] = coords[iseg,:]
         segment.data['displacement'] = all_displacements[iseg]
         segment.status = segment.SEG_STATUS_COMPLETE
 
     return segments
Beispiel #4
0

for istep in range(1,coord_len):
    x = coords[istep-1]
    
    xarg = twopi_by_A*(x - x0)
    
    #print repr(istep), repr(x), repr(x0)
    #print repr(C)
    #print repr(x)
    #print repr(xarg)

    eCx = numpy.exp(C*x)
    eCx_less_one = eCx - 1.0
   
    all_displacements[istep] = displacements = random_normal(scale=sigma, size=(1,))
    grad = half_B / (eCx_less_one*eCx_less_one)*(twopi_by_A*eCx_less_one*sin(xarg)+C*eCx*cos(xarg))
    
    newx = x - gradfactor*grad + displacements
    newy = x - gradfactor*grad + displacements #KFW

    if reflect_at is not None:
        # Anything that has moved beyond reflect_at must move back that much

        # boolean array of what to reflect
        to_reflect = newx > reflect_at

        # how far the things to reflect are beyond our boundary
        reflect_by = newx[to_reflect] - reflect_at

        # subtract twice how far they exceed the boundary by
Beispiel #5
0
    def propagate(self, segments):
        start_time = time.time()
        
        well_1, well_2, well_3 = self.well_1, self.well_2, self.well_3
        sig = self.sigma
        gradfactor = 2*sig*sig
        cos45 = np.cos(np.pi/4)
        sin45 = np.sin(np.pi/4)
        
        n_segs = len(segments)
    
        coords = np.empty((n_segs, self.coord_len, self.coord_ndim),
                          dtype=self.coord_dtype)
        
        for iseg, segment in enumerate(segments):
            coords[iseg,:] = segment.pcoord[:]
            
        coord_len = self.coord_len
        reflect_at_1 = self.reflect_at_1
        reflect_at_2 = self.reflect_at_2
        all_displacements = np.zeros((n_segs, self.coord_len, self.coord_ndim),
                                     dtype=self.coord_dtype)
        for istep in xrange(1,coord_len):
            x = coords[:,istep-1,:]
           
            all_displacements[:,istep,:] = displacements = \
                random_normal(scale=sig, size=(n_segs,self.coord_ndim))
            # We have 3 wells
            mod_x = (cos45*x[:,0]+sin45*x[:,1])
            mod_y = (cos45*x[:,0]-sin45*x[:,1])
            grad_x = self.grad_x(well_1[0], well_1[3], well_1[4],  well_1[1], well_1[2], x[:,0], x[:,1]) + \
                     self.grad_x(well_2[0], well_2[3], well_2[4],  well_2[1], well_2[2], x[:,0], x[:,1]) + \
                     self.grad_x(well_3[0], well_3[3], well_3[4],  well_3[1], well_3[2], mod_x, mod_y)
            grad_y = self.grad_y(well_1[0], well_1[3], well_1[4],  well_1[1], well_1[2], x[:,0], x[:,1]) + \
                     self.grad_y(well_2[0], well_2[3], well_2[4],  well_2[1], well_2[2], x[:,0], x[:,1]) + \
                     self.grad_y(well_3[0], well_3[3], well_3[4],  well_3[1], well_3[2], mod_x, mod_y)
            grad = np.array([grad_x,grad_y]).T
            
            newx = x - gradfactor*grad + displacements
            if reflect_at_1 is not None:
                # Anything that has moved beyond reflect_at must move back that much
                
                # boolean array of what to reflect
                to_reflect_1 = newx > reflect_at_1
                to_reflect_2 = newx < reflect_at_2
                
                # how far the things to reflect are beyond our boundary
                reflect_by_1 = newx[to_reflect_1] - reflect_at_1
                reflect_by_2 = newx[to_reflect_2] - reflect_at_2
                
                # subtract twice how far they exceed the boundary by
                # puts them the same distance from the boundary, on the other side
                newx[to_reflect_1] -= 2*reflect_by_1
                newx[to_reflect_2] -= 2*reflect_by_2
            coords[:,istep,:] = newx
        cputime_end = time.time()
            
        for iseg, segment in enumerate(segments):

            segment.pcoord[...] = coords[iseg,:]
            segment.data['displacement'] = all_displacements[iseg]
            segment.cputime = cputime_end - start_time
            end_time = time.time()
            segment.walltime = end_time - start_time
            segment.status = segment.SEG_STATUS_COMPLETE
    
        return segments
    def propagate(self, segments):

        A, B, C, x0 = self.A, self.B, self.C, self.x0

        n_segs = len(segments)

        coords = numpy.empty((n_segs, self.coord_len, self.coord_ndim),
                             dtype=self.coord_dtype)

        for iseg, segment in enumerate(segments):
            coords[iseg, 0] = segment.pcoord[0]

        twopi_by_A = 2 * PI / A
        half_B = B / 2
        sigma = self.sigma
        gradfactor = self.sigma * self.sigma / 2
        coord_len = self.coord_len
        reflect_at = self.reflect_at
        all_displacements = numpy.zeros(
            (n_segs, self.coord_len, self.coord_ndim), dtype=self.coord_dtype)

        sink = -1.0
        for istep in xrange(1, coord_len):
            x = coords[:, istep - 1, 0]

            #xarg = twopi_by_A*(x - x0)
            xarg = x

            eCx = numpy.exp(C * x)
            eCx_less_one = eCx - 1.0

            all_displacements[:, istep, 0] = displacements = random_normal(
                scale=sigma, size=(n_segs, ))
            #grad = half_B / (eCx_less_one*eCx_less_one)*(twopi_by_A*eCx_less_one*sin(xarg)+C*eCx*cos(xarg))
            grad = -2.0 * xarg * (1.0 - xarg * xarg)

            newx = x

            #Absorb trajectories reaching end point
            to_absorb = x > sink

            newx[to_absorb] = x[to_absorb]

            #Propagate trajectories which didn't reach end point

            not_to_absorb = x < sink

            newx[not_to_absorb] = x[not_to_absorb] - gradfactor * grad[
                not_to_absorb] + displacements[not_to_absorb]

            #            if reflect_at is not None:
            # Anything that has moved beyond reflect_at must move back that much

            # boolean array of what to reflect
            #                to_reflect = newx > reflect_at

            # how far the things to reflect are beyond our boundary
            #                reflect_by = newx[to_reflect] - reflect_at

            # subtract twice how far they exceed the boundary by
            # puts them the same distance from the boundary, on the other side
            #                newx[to_reflect] -= 2*reflect_by
            coords[:, istep, 0] = newx

        for iseg, segment in enumerate(segments):
            segment.pcoord[...] = coords[iseg, :]
            segment.data['displacement'] = all_displacements[iseg]
            segment.status = segment.SEG_STATUS_COMPLETE

        return segments
Beispiel #7
0

for istep in xrange(1,coord_len):
    x = coords[istep-1]
    
    xarg = twopi_by_A*(x - x0)
    
    #print repr(istep), repr(x), repr(x0)
    #print repr(C)
    #print repr(x)
    #print repr(xarg)

    eCx = numpy.exp(C*x)
    eCx_less_one = eCx - 1.0
   
    all_displacements[istep] = displacements = random_normal(scale=sigma, size=(1,))
    grad = half_B / (eCx_less_one*eCx_less_one)*(twopi_by_A*eCx_less_one*sin(xarg)+C*eCx*cos(xarg))
    
    newx = x - gradfactor*grad + displacements
    newy = x - gradfactor*grad + displacements #KFW

    if reflect_at is not None:
        # Anything that has moved beyond reflect_at must move back that much

        # boolean array of what to reflect
        to_reflect = newx > reflect_at

        # how far the things to reflect are beyond our boundary
        reflect_by = newx[to_reflect] - reflect_at

        # subtract twice how far they exceed the boundary by