Esempio n. 1
0
File: Quad.py Progetto: burner/e3rt
def createHeightMap(depth, oct, range, side):
	steps = 0
	if range[0] > range[1]:
		steps = (range[0]-range[1]) / (math.pow(2,depth+1)-1)
	else:
		steps = (range[1]-range[0]) / (math.pow(2,depth+1)-1)

	global heightMap

	#print steps
	for i in frange(range[0], range[1], steps):
		tmpList = []
		for j in frange(range[0], range[1], steps):
			tmp = 0.0
			if side == 0: #top
				tmp = fbm(i,j,1, oct)
			elif side == 1: #bottom
				tmp == fbm(i,j,-1, oct)
			elif side == 2: #frond
				tmp == fbm(i,1,j, oct)
			elif side == 3: #back
				tmp == fbm(i,-1,j, oct)
			elif side == 4: #right
				tmp == fbm(1,i,j, oct)
			elif side == 5: #left
				tmp == fbm(-1,i,j, oct)
			else:
				print "createHeighMap side not in range 0...5"

			tmpList.append(tmp)

		heightMap.append(tmpList)
Esempio n. 2
0
    def shiftToColor(self, newColor):
        curValues = self.rgb

        diffs = [abs(newColor[i] - curValues[i]) for i in range(3)]

        for i in range(len(diffs)):
            diffs[i] = round(diffs[i] * 1000) / 1000

        shiftVals = [0, 0, 0]
        for c in range(3):
            if (diffs[c] != 0):
                shiftVals[c] = [
                    i for i in frange(curValues[c], newColor[c], diffs[c] /
                                      self.shiftSteps)
                ]
            else:
                shiftVals[c] = [self.rgb[c]] * (self.shiftSteps + 1)

        shiftr = shiftVals[0]
        shiftg = shiftVals[1]
        shiftb = shiftVals[2]

        for s in range(self.shiftSteps + 1):
            shiftr[s] = round(shiftr[s] * 1000) / 1000
            shiftg[s] = round(shiftg[s] * 1000) / 1000
            shiftb[s] = round(shiftb[s] * 1000) / 1000

            self.setColor([shiftr[s], shiftg[s], shiftb[s]])
            time.sleep(.003)
 def __init__(self):
     self._regressor = linear_model.Ridge()
     self._regressor_name = 'ridge'
     self._grid_params = [dict(ridge__alpha=util.frange(0, 20, 0.1))]
     self._name = 'Ridge'
     self._color = 'red'
     Model.__init__(self)
Esempio n. 4
0
	def __init__(self, plane):
		self.plane = plane
		self.step_size = plane.step_size
		self.sites = plane.sites
		self.scanned_sites = []
		self.sweep_line = []
		self.beach_line = [Point(x, 0) for x in util.frange(0, self.plane.width, self.step_size)]
		self.beach_line_by_sites = dict()
 def __init__(self):
     self._regressor = ensemble.GradientBoostingRegressor()
     self._regressor_name = 'gbm'
     self._grid_params = [
         dict(gbm__learning_rate=util.frange(0.05, 1, 0.05),
              gbm__n_estimators=range(20, 300, 20),
              gbm__max_depth=range(2, 7))
     ]
     self._name = 'Gradient Boosted Model'
     self._color = 'yellow'
     Model.__init__(self)
Esempio n. 6
0
	def run(self):
		for level in util.frange(0, self.plane.height, self.step_size):
			# Sweep line
			sweep_line = self.build_sweep_line(level)

			# Encounter a site event
			if self.site_event():



			# TODO: Not sure it works properly or not
			if (level > self.sites[0].point.y):
				site = self.sites.pop(0)
				self.scanned_sites.append(site)

			# Build parabola for each of the scanned sites
			for site in self.scanned_sites:
				site.parabolas[level] = self.build_parabola(site, sweep_line)


	def site_event(self, sweep_line):



	def build_sweep_line(self, level):
		return [Point(x, level) for x in util.frange(0, self.plane.width, self.step_size)]

	def build_beach_line(self, site, index, parabola_point):
		
		if (parabola_point.y >= self.beach_line[index].y):
			if (parabola_point.y > self.beach_line[index].y):
				self.beach_line[index] = parabola_point

			if site in self.beach_line_by_sites:
				self.beach_line_by_sites[site].append(parabola_point)
			else:
				self.beach_line_by_sites[site] = [parabola_point]

	def build_parabola(self, site, sweep_line):
		parabola = []
		for index, sweep_line_point in enumerate(sweep_line):
			parabola_point = self.find_parabola_point(site.point, sweep_line_point)
			parabola.append(parabola_point)
			self.build_beach_line(site, index, parabola_point)
		return parabola

	def find_parabola_point(self, point, sweep_line_point):
		return Point(sweep_line_point.x, -0.5 * (((sweep_line_point.x-point.x)**2/(sweep_line_point.y-point.y)) - (sweep_line_point.y+point.y)))
Esempio n. 7
0
 def _createCogwheel(self, size):
     """Creates the points that are part of the cogwheel polygon"""
     self.points = []
     r1 = (size / 2.0) - 1.0
     r2 = 0.80
     teeth = 9
     out = False
     for t in frange(0.0, 2 * math.pi, 2 * math.pi / (teeth * 2.0)):
         x = r1 * math.cos(t)
         y = r1 * math.sin(t)
         if out:
             self.points.append(QtCore.QPointF(x, y))
             self.points.append(QtCore.QPointF(r2 * x, r2 * y))
         else:
             self.points.append(QtCore.QPointF(r2 * x, r2 * y))
             self.points.append(QtCore.QPointF(x, y))
         out = not out
Esempio n. 8
0
def generate_random_environments(eparams):
    """Generate a number of random environments.

    :param eparams:          the evolutionparams python module name

    """
    random.seed()
    params = [
        util.convert_string_to_param_t(env)
        for env in eparams.params_as_environment
    ]
    pvalues = []
    for n in xrange(eparams.environments):
        pvalues.append([])
        for param in params:
            value = random.choice(
                [f for f in util.frange(param.minv, param.maxv, param.step)])
            pvalues[-1].append(value)
    return (params, pvalues)
Esempio n. 9
0
def float_categorize(float, threds_list = None, n_level = 4):
    '''
    convert float features into categorical ones by quantization

    :param float: float features
    :param threds_list: thresholds used to quantizing, if not automatic quantization is applied
    :param n_level: when automatic quantization is applied, the number of level of each feature
    :return: quantized version of float
    '''
    n, d = float.shape
    if(threds_list is None):
        #use automatic quantization
        result = []
        for i in range(0,d):
            current_col = float[:, i]
            ub = max(current_col)
            lb = min(current_col)
            step = (ub - lb) / (n_level - 1)
            thresh = util.frange(lb + step, ub, step)
            transformed_col = []
            for j in range(0, n):
                current_e = current_col[j]
                compare_res = thresh - current_e
                transformed_col.append(np.argmax(compare_res > 0) + 1)

            result.append(transformed_col)

    else:
        result = []
        for i in range(0,d):
            current_col = float[:, i]
            thresh = threds_list[i]
            transformed_col = []
            for j in range(0, n):
                current_e = current_col[j]
                compare_res = thresh - current_e
                transformed_col.append(np.argmax(compare_res > 0) + 1)

            result.append(transformed_col)

    return np.array(result).T
Esempio n. 10
0
def preprocess(increment, hospitals, schools):
    """Breaks the data down into pre-processed classes for fast delivery to a
    web client.
    """
    classes = []
    MAX = 250

    for i in util.frange(increment, MAX, increment):
        print(i)
        classes.append([i])
        for hospital in hospitals.iterShapes():
            for school in schools:
                point = hospital.points[0]
                hpos = (point[0], point[1])
                spos = (school["latitude"], school["longitude"])

                d = distance(spos, hpos)
                if (d < i) and (d > i - increment):
                    classes[-1].append(school)
                    schools.remove(school)
                    print(len(schools))

    return classes
Esempio n. 11
0
	def build_sweep_line(self, level):
		return [Point(x, level) for x in util.frange(0, self.plane.width, self.step_size)]
__author__ = 'Eddie Pantridge'

import scipy.integrate as ode
import numpy as np
import math
import util as u
import draw
import analize_system

# Global simulation variables
gravity = 1
dt = .01
T = 10
N = T/dt+1
times = u.frange(0, T, dt)

def four_body_func(vecs, t, *args):

    pos_1 = vecs[0:2]
    pos_2 = vecs[2:4]
    pos_3 = vecs[4:6]
    pos_4 = vecs[6:8]
    vel_1 = vecs[8:10]
    vel_2 = vecs[10:12]
    vel_3 = vecs[12:14]
    vel_4 = vecs[14:16]

    acc_1_2 = u.position_div_scalars(u.position_mult_scalars( (u.position_sub(pos_2, pos_1)), [args[1]] ),
                                     math.pow(u.length(u.position_sub(pos_2, pos_1)), 3))
    acc_2_1 = u.position_div_scalars(u.position_mult_scalars( (u.position_sub(pos_1, pos_2)), [args[0]] ),
                                     math.pow(u.length(u.position_sub(pos_2, pos_1)), 3))