예제 #1
0
	def click_traces(self, x, y):
		t, V_j = self.traces.computeTraces(self.system.load_initial_condition(x, y))
		V_j = np.transpose(V_j)
		ti, d = tl.phase_difference(V_j, V_trigger=type(self).V_trigger)
		last = d[-1, :]
		tl.plot_phase_2D(d[:, 0], d[:, 1], axes=self.ax_traces, color=tl.clmap(tl.PI2*last[1], tl.PI2*last[0]), PI=0.5, arrows=self.PLOT_ARROWS)
		self.fig.canvas.draw()
예제 #2
0
 def click_traces(self, x, y):
     t, V_j = self.traces.compute_traces(
         self.system.load_initial_condition(x, y))
     V_j = np.transpose(V_j)
     ti, d = tl.phase_difference(V_j, V_trigger=type(self).V_trigger)
     last = d[-1, :]
     tl.plot_phase_2D(d[:, 0],
                      d[:, 1],
                      axes=self.ax_traces,
                      c=tl.clmap(tl.PI2 * last[1], tl.PI2 * last[0]),
                      PI=0.5)
     #tl.plot_phase_2D(d[:, 0], d[:, 1], axes=self.ax_traces, c=tl.clmap_patterns(last[1], last[0]), PI=0.5)
     self.fig.canvas.draw()
예제 #3
0
	def sweep_phase_space(self, jitter=False, widget=None, event=None):
		self.dt, self.stride, self.N_output = self.system.dt, self.system.stride, self.system.N_output(self.traces.CYCLES)

		self.echo('computing using '+torus_2D.PROCESSOR[self.USE_GPU]+' ...')

		torus_2D.erase_traces(self)
		self.erase_basins()

		initial_phases = np.arange(0., 1., 1./float(self.GRID))
	
		try:	X = self.system.load_initial_conditions(initial_phases, jitter=jitter) # X[initial_condition, variable]
		except:	X = self.system.load_initial_conditions(initial_phases) # ... not all systems know about jittering.

		t0 = time.time()
		D = compute_phase_trace[self.USE_GPU](self, X)
                self.echo('traces computed.')
	
		# find attractors
		attractors = [att.attractor( [[0., 0.]], initial_state=[0., 0.] ).classify()]
		basin_hash = -np.ones((self.GRID, self.GRID), int)
		for i in xrange(self.GRID):

			for j in xrange(self.GRID):
				trajectory = D[i*self.GRID+j]
				initial_state = initial_phases[[j, i]]

				try:
					new_attractor = att.attractor( trajectory, initial_state=initial_state ).classify()

				except:
					basin_hash[i, j] = 0
					continue
				
				conditions = [attr_i.distance2attractor(new_attractor) > 0.1 for attr_i in attractors]
				for (c, condition) in enumerate(conditions):

					if not condition:
						basin_hash[i, j] = c

				if basin_hash[i, j] < 0:
                			attractors.append(new_attractor)
					basin_hash[i, j] = len(attractors)-1



		# refine attractor
		def refine_attractor(initial_condition):
			t, V_j = self.traces.computeTraces(initial_condition, plotit=False)
			V_j = np.transpose(V_j)
			ti, trajectory = tl.phase_difference(V_j, V_trigger=type(self).V_trigger)

			try:
				new_attr = att.attractor(trajectory).classify()
				return new_attr

			except:
				return att.attractor( [[0., 0.]], initial_state=[0., 0.] ).classify()

			

		initial_conditions = []
		for i in xrange(1, len(attractors), 1):
			attr = attractors[i]
			initial_conditions.append( self.system.load_initial_condition(attr.initial_state[1], attr.initial_state[0]))

		if len(initial_conditions):
			self.traces.CYCLES *= 4
			new_attractors = [att.attractor( [[0., 0.]], initial_state=[0., 0.] ).classify()]
			new_attractors.extend( distribute.distribute(refine_attractor, 'initial_condition', initial_conditions) )
			self.traces.CYCLES /= 4



		attractors = [att.attractor( [[0., 0.]], initial_state=[0., 0.] ).classify()]
                for (j, new_att_j) in enumerate(new_attractors):
                    conditions = [new_att_j.distance2attractor(attr_i) < 0.1 for attr_i in attractors]
		    
                    if any(conditions):
                        which = conditions.index(True)

		    else:
			which = len(attractors)
			attractors.append(new_att_j)

                
		    for l in xrange(basin_hash.shape[0]):

			for m in xrange(basin_hash.shape[1]):

			    if basin_hash[l, m] == j:
				basin_hash[l, m] = which








		basins = np.ones((self.GRID, self.GRID, 4), float)
		for i in xrange(self.GRID):

			for j in xrange(self.GRID):
				basins[j, i, :3] = attractors[basin_hash[i, j]].color[:3]


                # plot attractors
		for attractor in attractors:
                    attractor.plot(self.ax_basins, 'o', mec='w', mew=1.0, ms=7.)

		
                # plot basins
                if self.basin_image == None:
		    self.basin_image = self.ax_basins.imshow(basins, interpolation='nearest', aspect='equal', extent=(0., 1., 0., 1.), origin='lower')

                else:
		    self.basin_image.set_data(basins)
                    self.ax_basins.set_xlim(0., 1.)
                    self.ax_basins.set_ylim(0., 1.)


                # plot traces
		N_ARROW = self.GRID/4	 # Plot <X> arrow symbols in each direction.

		for i in xrange(self.GRID):

			for j in xrange(self.GRID):

				d = D[i*self.GRID+j]
				color = basins[j, i, :3]
				plotArrow = self.PLOT_ARROWS and (i % N_ARROW == 0) and (j % N_ARROW == 0)  # every n-th grid point for the top plot

				try:	tl.plot_phase_2D(d[:, 0], d[:, 1], axes=self.ax_traces, color=color, PI=0.5, arrows=plotArrow)
				except:	pass


		for attractor in attractors:
                    attractor.plot(self.ax_traces, 'o', mec='w', mew=1.0, ms=7.)

		self.fig.canvas.draw()


		self.echo("used %.2g sec" % (time.time()-t0))

                return basin_hash, attractors
예제 #4
0
    def sweep_phase_space(self, widget=None, event=None):
        self.dt, self.stride, self.N_output = self.system.dt, self.system.stride, self.system.N_output(
            self.traces.CYCLES)

        self.echo('computing using ' + torus_2D.PROCESSOR[self.USE_GPU] +
                  ' ...')

        torus_2D.erase_traces(self)
        self.erase_basins()

        initial_phases = np.arange(0., 1., 1. / float(self.GRID))

        X = self.system.load_initial_conditions(
            initial_phases)  # X[initial_condition, variable]

        t0 = time.time()
        D = compute_phase_trace[self.USE_GPU](self, X)
        self.echo('traces computed.')

        # find attractors
        attractors = [
            att.attractor([[0., 0.]], initial_state=[0., 0.]).classify()
        ]
        basin_hash = -np.ones((self.GRID, self.GRID), int)
        for i in xrange(self.GRID):

            for j in xrange(self.GRID):
                trajectory = D[i * self.GRID + j]
                initial_state = initial_phases[[j, i]]

                try:
                    new_attractor = att.attractor(
                        trajectory, initial_state=initial_state).classify()

                except:
                    basin_hash[i, j] = 0
                    continue

                conditions = [
                    attr_i.distance2attractor(new_attractor) > 0.1
                    for attr_i in attractors
                ]
                for (c, condition) in enumerate(conditions):

                    if not condition:
                        basin_hash[i, j] = c

                if basin_hash[i, j] < 0:
                    attractors.append(new_attractor)
                    basin_hash[i, j] = len(attractors) - 1

        # refine attractor
        #"""
        def refine_attractor(initial_condition):
            t, V_j = self.traces.compute_traces(initial_condition,
                                                plotit=False)
            V_j = np.transpose(V_j)
            ti, trajectory = tl.phase_difference(
                V_j, V_trigger=type(self).V_trigger)

            try:
                new_attr = att.attractor(trajectory).classify()
                return new_attr

            except:
                return att.attractor([[0., 0.]],
                                     initial_state=[0., 0.]).classify()

        initial_conditions = []
        for i in xrange(1, len(attractors), 1):
            attr = attractors[i]
            initial_conditions.append(
                self.system.load_initial_condition(attr.initial_state[1],
                                                   attr.initial_state[0]))

        if len(initial_conditions):
            self.traces.CYCLES *= 4
            new_attractors = [
                att.attractor([[0., 0.]], initial_state=[0., 0.]).classify()
            ]
            new_attractors.extend(
                fm.distribute(refine_attractor, 'initial_condition',
                              initial_conditions))
            self.traces.CYCLES /= 4
        #"""

        attractors = [
            att.attractor([[0., 0.]], initial_state=[0., 0.]).classify()
        ]
        for (j, new_att_j) in enumerate(new_attractors):
            conditions = [
                new_att_j.distance2attractor(attr_i) < 0.1
                for attr_i in attractors
            ]

            if any(conditions):
                which = conditions.index(True)

            else:
                which = len(attractors)
                attractors.append(new_att_j)

            for l in xrange(basin_hash.shape[0]):

                for m in xrange(basin_hash.shape[1]):

                    if basin_hash[l, m] == j:
                        basin_hash[l, m] = which

        basins = np.ones((self.GRID, self.GRID, 4), float)
        for i in xrange(self.GRID):

            for j in xrange(self.GRID):
                basins[j, i, :3] = attractors[basin_hash[i, j]].color[:3]

    # plot attractors
        for attractor in attractors:
            attractor.plot(self.ax_basins, 'o', mec='w', mew=1.0, ms=7.)

    # plot basins
        if self.basin_image == None:
            self.basin_image = self.ax_basins.imshow(basins,
                                                     interpolation='nearest',
                                                     aspect='equal',
                                                     extent=(0., 1., 0., 1.),
                                                     origin='lower')

        else:
            self.basin_image.set_data(basins)
            self.ax_basins.set_xlim(0., 1.)
            self.ax_basins.set_ylim(0., 1.)

    # plot traces
        for i in xrange(self.GRID):
            for j in xrange(self.GRID):
                d = D[i * self.GRID + j]
                color = basins[j, i, :3]
                #"""
                try:
                    tl.plot_phase_2D(d[:, 0],
                                     d[:, 1],
                                     axes=self.ax_traces,
                                     c=color,
                                     PI=0.5)
                    #last = d[-1, :]
                    #tl.plot_phase_2D(d[:, 0], d[:, 1], axes=self.ax_traces, c=tl.clmap(tl.PI2*last[1], tl.PI2*last[0]), PI=0.5)
                    #tl.plot_phase_2D(d[:, 0], d[:, 1], axes=self.ax_traces, c=tl.clmap_patterns(last[1], last[0]), PI=0.5)

                except:
                    pass
                #"""

        for attractor in attractors:
            attractor.plot(self.ax_traces, 'o', mec='w', mew=1.0, ms=7.)

        self.fig.canvas.draw()

        self.echo("used %.2g sec" % (time.time() - t0))

        return basin_hash, attractors
예제 #5
0
	N = 10**3
	N_initials = 100

	#coupling = 0.001*ones((12), float)
	coupling = 0.001*ones((6), float)

	#single_orbit(verbose=1)
	#show()

	#params.update(shift=2.)
	#X = integrate_one_rk4(INITIAL_ORBIT, dt/float(stride), N, stride)
	#print X[:, -1]
	#plot(X[0], X[1])
	#show()

	X = cuda_crossing_three(randn(N_initials*N_EQ4), coupling, 0.0, 3, dt/float(stride), stride)
	#X = cuda_integrate_four_rk4(randn(N_initials*N_EQ4), coupling, dt/float(stride), N, stride)
        for i in xrange(X.shape[0]):
            ti, d = tl.compute_phase_difference(transpose(X[i]))
            tl.plot_phase_2D(d[:, 0], d[:, 1])
        show()
	exit(0)
	#X = integrate_four_rk4(randn(N_EQ4), coupling, dt/float(stride), N, stride)


	plot(X[:, 0], 'b-')
	plot(X[:, 1]-1., 'g-')
	plot(X[:, 2]-2., 'r-')
	plot(X[:, 3]-3., 'y-')
	show()
예제 #6
0
    N = 10**3
    N_initials = 100

    #coupling = 0.001*ones((12), float)
    coupling = 0.001 * ones((6), float)

    #single_orbit(verbose=1)
    #show()

    #params.update(shift=2.)
    #X = integrate_one_rk4(INITIAL_ORBIT, dt/float(stride), N, stride)
    #print X[:, -1]
    #plot(X[0], X[1])
    #show()

    X = cuda_crossing_three(randn(N_initials * N_EQ4), coupling, 0.0, 3,
                            dt / float(stride), stride)
    #X = cuda_integrate_four_rk4(randn(N_initials*N_EQ4), coupling, dt/float(stride), N, stride)
    for i in xrange(X.shape[0]):
        ti, d = tl.compute_phase_difference(transpose(X[i]))
        tl.plot_phase_2D(d[:, 0], d[:, 1])
    show()
    exit(0)
    #X = integrate_four_rk4(randn(N_EQ4), coupling, dt/float(stride), N, stride)

    plot(X[:, 0], 'b-')
    plot(X[:, 1] - 1., 'g-')
    plot(X[:, 2] - 2., 'r-')
    plot(X[:, 3] - 3., 'y-')
    show()