Beispiel #1
0
def perform_draw(names, num_winners=1, num_iterations=32):
    for i in range(1,num_iterations):
        clear_screen() 

        delay = e(i/float(num_iterations))-1.5
        if delay < 0: delay = 0.1

        candidates = random.sample(names, num_winners)

        print_message(", ".join(candidates))

        sleep(delay)

    
    clear_screen() 
    sleep(2.5)
    
    winners = random.sample(names, num_winners)
    
    if num_winners > 1: title = "Vinnerne" 
    else: title = "Vinneren"
    
    message = title + " er: " + ", ".join(winners) + ". Gratulerer!"
    print_message(message, spaces=30)

    raw_input()
Beispiel #2
0
def node_output(inputs, weights):
    # weight[0] is bias weight
    activation = weights[0]
    for i in range(len(inputs)):
        activation += inputs[i] * weights[i + 1]
    try:
        # compute the simoid(sigmoid?) of the activation
        output = 1 / (1 + e(-1 * activation))
    except OverflowError:
        # catch cases where e^-a overflows
        if activation < 0:
            output = 0
        else:
            output = 1
    return output
Beispiel #3
0
def score_plan(plan, const):
    """ Accepts a districting plan in the form of a networkx graph and scores
    it using two sub-scores: population balance and district contiguity. The
    score function takes the form of an energy function: e^-x. A parameterised
    constant is used to appropriately scale the results of the sub-scores """

    # Get population score parameter
    pop_param = score_pop(plan)

    # Get contiguity score parameter
    contig_param = score_contig(plan)

    # Energy function with constant to adjust 'strength' of scoring
    score = e(-const * pop_param * contig_param)

    return score
Beispiel #4
0
def simulated_annealing():
    current = INITIAL_POINT
    t = 0
    while True:
        T = schedule(t)
        x, y = current
        if T == 0:
            print(F(current), t)
            return current
        angle = random.uniform(-180, 180) * math.pi / 180
        next = (x + RADIUS * math.cos(angle), y + RADIUS * math.sin(angle))
        dE = F(next) - F(current)
        if dE > 0:
            current = next
        else:
            p = e(dE / T)
            current = next if random.random() < p else current
        t = t + 1
Beispiel #5
0
def update_variance_winner(i, j, k):

    inner_first_para_upper = worker_quality[k][
        0] * worker_quality[k][1] * e(score[i]) * e(score[j])

    inner_first_para_lower = pow(
        (worker_quality[k][0] * e(score[i]) + worker_quality[k][1] * e(score[j])), 2)

    inner_second_para = e(
        score[i]) * e(score[j]) / pow(e(score[i]) + e(score[j]), 2)

    max_candidate_one = 1 + \
        pow(variance[i], 2) * (inner_first_para_upper /
                               inner_first_para_lower - inner_second_para)

    max_candidate_two = 0.0001

    result = pow(variance[i], 2) * max(max_candidate_one, max_candidate_two)

    return result
Beispiel #6
0
def simulatedAnnealing(M, N, D, W, start, end):
    # Takes Tmax and dT in to allow for experimentation.
    # When everything's done it'll only take the size of a the board, and eggs (M, N, k)
    State = Switchboard(M, N, D, W) # The State to be returned when optimal
    Temp = 0.07
    dT = 0.00001
    targetBoardEvaluation = 0.7
    while (State.evaluateBoard() < targetBoardEvaluation):
        neighbours = State.generateNeighbours()
        newState = None # The best neighbour
        for neighbour in neighbours: # Loop through neighbours to find the best one
            if (neighbour.evaluateBoard() > newState):
                newState = neighbour
        q = ((newState.evaluateBoard()-State.evaluateBoard())/State.evaluateBoard())
        p = math.min(1, math.e((-q)/Temp))
        x = random.random() # Random number between 0 and 1
        if (x > p ):
            State = newState
        else:
            State = neighbours[random.randint(0, len(neighbours))] # None of them were very good, choose a random one
        Temp -= dT
    return State
Beispiel #7
0
        return ret

    ret = 0
    for i in range(len(points)):
        print("{0}*".format(points[i][1]), end="")
        ret += points[i][1] * L(i)
        if i + 1 < len(points):
            print(" + ", end="")
    if type(x) == float:
        print(" = {0}".format(ret))
        return ret
    return ""


print(
    largrandian_interpolation(((1.2, 1.5095), (1.3, 1.6984), (1.4, 1.9043),
                               (1.5, 2.1293), (1.6, 2.3756)), 1.1))
x = 1.1
print((e(x) - e(-x)) / 2)
print()
print(
    largrandian_interpolation(((1.2, 1.5095), (1.3, 1.6984), (1.4, 1.9043),
                               (1.5, 2.1293), (1.6, 2.3756)), 1.3))
x = 1.3
print((e(x) - e(-x)) / 2)
print()
print(
    largrandian_interpolation(((1.2, 1.5095), (1.3, 1.6984), (1.4, 1.9043),
                               (1.5, 2.1293), (1.6, 2.3756)), 1.6))
x = 1.6
print((e(x) - e(-x)) / 2)
Beispiel #8
0
    R = [[h(1) * (f(a) + f(b))]]
    i, j = 1, 0
    while max_steps > 0:
        if j == 0:
            hi = h(i)
            R.append([0.5 * R[i - 1][0] + hi * (sum_of_f(hi, i))])
            j += 1
        while (j <= i):
            R[i].append(((1 / (pow(4, j) - 1)) *
                         (pow(4, j) * R[i][j - 1] - R[i - 1][j - 1])))
            j += 1
        if R[i][j - 1] == R[i][j - 2]:
            print(
                str(R).replace('],',
                               '\n').replace('[[',
                                             ' ').replace('[',
                                                          '').replace(']', ''))
            return R[i][j - 1]
        j = 0
        i += 1
        max_steps -= 1
    print(
        str(R).replace('],', '\n').replace('[[',
                                           ' ').replace('[',
                                                        '').replace(']', ''))
    return R[i - 1][j - 1]


print(romberg(lambda x: x * e(-x), 0, 2, 10))
Beispiel #9
0
def rejection():
    c, Y, U = 2/e(1), exponential(1/2), random()

    while U >= c * Y * e(- Y / 2):
        Y, U = exponential(1/2), random()
    return(Y)
Beispiel #10
0
def sigmoid(x, sigma=SIGMA):
	return 1/(1 + e(-sigma*x))
Beispiel #11
0
 def compute_function(cls, x: float) -> float:
     return 1 / (1 + e(-x))
 def get_c_value(self, S, d, t, d1, K, r, d2):
     return S * e(-d * t) * norm.cdf(d1) - K * e(-r * t) * norm.cdf(d2)
  60943702770539217176293176752384674818467669405132
  00056812714526356082778577134275778960917363717872
  14684409012249534301465495853710507922796892589235
  42019956112129021960864034418159813629774771309960
  51870721134999999837297804995105973173281609631859
  50244594553469083026425223082533446850352619311881
  71010003137838752886587533208381420617177669147303
  59825349042875546873115956286388235378759375195778
  18577805321712268066130019278766111959092164201989)

			if (UserIPAddress == math.isclose(to your house)) proceed with {
				function(ddos(userip(getip(sendrequest(retreieverequest(parserequest(dumprequest(ddosrequest(((UserIPAddress)))))))))))
			}

			#get mathemeaticals constant
			sum1=sum1+(1/math.factorial(i)) * math.e(12^UserIPAddress / sum)

			#send request to mars rover
			if @bot.command() rover == function->GetMarsRoverName { }
			send::ping + request::to mars.rover 1
			ask mars.rover 1 for image:
				return nasa.api.image


				ip address coordinates: aarray([[[ 0,  1,  2,  3],
        [ 4,  5,  6,  7],
        [ 8,  9, 10, 11]],

       [[12, 13, 14, 15],
        [16, 17, 18, 19],
        [20, 21, 22, 23]]])
Beispiel #14
0
def arps_exp_rate(qi, di, b):
    return qi*math.e(-di)
Beispiel #15
0
# EXPRESSION FILE
###########################################################

# The idea is to create a toy dataset including the two types of termination
# we can see in the RNA seq profiles to test two different things:

# 1. The size of the windows required to detect the signals
# 2. The whole approach

max_exp = 200
genome_size = 9000


# We need a decay list of numbers:
decay = []
c = 1/e(2)
x = max_exp

while x >= 0:
    decay.append(x)
    c = c*1.05
    x = x-c


# Arrive to 0
decay = decay[1:]+[0]

# We will put the information in the toyset file
fo = open('./datasets/toyset.txt','w')

# Define the properties of the population and the position for 2 types of
Beispiel #16
0
def f(x):
	return 100*e(-0.0482*x)
Beispiel #17
0
#!/usr/bin/python3

from math import exp as e

print(e(1))

# print(help('modules')) # 当前的第三方库,打印要很久
 def get_p_value(self, S, d, t, d1, K, r, d2):
     return K * e(-r * t) * norm.cdf(-d2) - S * e(-d * t) * norm.cdf(-d1)
print(math.pi) # 内置的圆周率常数
print(' ') 

# 使用别名导入math库进行数学运算
print('使用别名导入math库进行数学运算') 
print(m.sin(1)) # 计算正弦
print(m.cos(1)) # 计算余弦
print(m.tan(1)) # 计算正切
# print(m.cot(0)) # 计算余切
print(m.pi) # 内置的圆周率常数
print(' ') 

# 通过名称导入指定函数
from math import exp as e # 只导入math库中的exp函数,并起别名e
print('通过名称导入指定函数') 
print(e(1)) # 计算指数
# print(sin(1)) # 此时sin(1)和math.sin(1)都会出错,因为没被导入
print(' ') 

# 导入库中所有函数
# 直接导入math库,也就是去掉math.,但如果大量地这样引入第三库,就容易引起命名冲突
# from math import * 
# print('导入库中所有函数') 
# print(sin(1)) 
# print(exp(1))
# print(' ') 

# 导入future特征
# 将print变成函数形式,即用print(a)格式输出
# from __future__ import print_function
 def get_c_delta(self, d, t, d1):
     return e(-d * t) * norm.cdf(d1)
Beispiel #21
0
def sigmoid_prime(x, sigma=SIGMA):
	return (sigma*e(sigma*x))/((e(sigma*x) + 1)**2)
 def get_p_delta(self, d, t, d1):
     return e(-d * t) * (norm.cdf(d1) - 1)
Beispiel #23
0
def F(point):
    x, y = point
    return 4 * e(-(x**2 + y**2)) + e(-((x - 5)**2 + (y - 5)**2)) + e(-(
        (x + 5)**2 + (y - 5)**2)) + e(-((x - 5)**2 +
                                        (y + 5)**2)) + e(-((x + 5)**2 +
                                                           (y + 5)**2))
 def get_gamma(self, d, d1, S, iv, t):
     return e(-d * t) * norm().pdf(d1) / (S * iv * sqrt(t))
Beispiel #25
0
def schedule(t):
    return T0 * e(-t / 1000)
 def get_vega(self, S, d, t, d1):
     return 0.01 * S * e(-d * t) * sqrt(t) * norm.pdf(-d1)
Beispiel #27
0
def arps_exponential_rate(qi, di, b):
    return qi * math.e(-di)
 def get_p_theta(self, S, iv, d, d1, t, r, K, d2, days):
     return (1 / days) * (-(S * iv * e(-d * t) * norm.pdf(-d1) /
                            (2 * sqrt(t))) +
                          (r * K * e(-r * t) * norm.cdf(-d2)) -
                          (d * S * e(-d * t) * norm.cdf(-d1)))
#import math              math.exp(i)
from math import exp as e

def fac(x):
    if x <= 1:
        return 1
    else:
        val = fac(x-1)
        val *= x                 #val = val * x
        return val

# def fac(x):
    #return 1 if x <= 1 else x*fac(x-1)              #Equivalente a operadores ternaros en Java

def serie(x):
    limit = 21
    acu = 1 + x
    for i in range(2,limit):
        acu += x**i / fac(i)
    return acu


if __name__ == '__main__':
    for i in range(1,11):
        valor_a = serie(i)
        valor_r = e(i)
        e_v = valor_r - valor_a
        print("Valor real: " + str(valor_r) + "\nValor aprox: " + str(valor_a) + "\nError verdadero: " + str(e_v))

Beispiel #30
0
import matplotlib.pyplot as plt
import numpy as np
import math
from math import exp as e
from math import pi as pi

x = np.linspace(-3, 3, 5000)
y = []

xo = np.linspace(0, 1, 25)
yo = [e(i) - 1 for i in xo]
x1 = [1, 3]
y1 = [e(1) - 1, e(1) - 1]

for t in x:
    ima = 1.3867495867890338
    for n in range(1, 101):
        wolfram = (2 / 3) * math.cos(n * t * (2 * pi / 3)) * (
            (e(1) * n * (2 * pi / 3) * math.sin(n * (2 * pi / 3)) +
             e(1) * math.cos(n * (2 * pi / 3)) - 1) /
            (n * n * (2 * pi / 3) *
             (2 * pi / 3) + 1) - math.sin(n * (2 * pi / 3)) / (n *
                                                               (2 * pi / 3)) +
            ((e(1) - 1) *
             (math.sin(3 * n * (2 * pi / 3)) - math.sin(n * (2 * pi / 3)))) /
            (n * (2 * pi / 3))) + (2 / 3) * math.sin(n * t * (2 * pi / 3)) * (
                ((1 - (e(1) - 1) * n * n * (2 * pi / 3) *
                  (2 * pi / 3)) * math.cos(n * (2 * pi / 3)) + e(1) * n *
                 (2 * pi / 3) * math.sin(n * (2 * pi / 3)) - 1) /
                (n * n * n * (2 * pi / 3) * (2 * pi / 3) * (2 * pi / 3) + n *
                 (2 * pi / 3)) + (2 * (e(1) - 1) * math.sin(n * (2 * pi / 3)) *
Beispiel #31
0
def normal_dist(x,u,sigma):
	a = 1./sigma*sqrt(2*pi)
	b = -(u-x)**2
	c = 2*sigma**2
	return a * e(b/c)
Beispiel #32
0
 def sigmoid(z):
     return 1 / (1 + e(-z))
Beispiel #33
0
def function(theta, n):
    for i in range(n):
        mu = random()
        theta += e(-(1. / mu - 1.) ** 2) / (mu ** 2)
    theta /= n * 2.
    print("Interaciones: {}, Resultado: {}".format(n, theta))
Beispiel #34
0
def sig(z):
    return 1 / (1 + e(-z))
Beispiel #35
0
def f(x):
  fr = (1/(1+e(-x)))
  min = fr - 0.5
  return 2*min
Beispiel #36
0
#--------------------------------------------------

# Python is very parsimonious in its use of memory. 
# Many basic mathematical functions -besides operators- have to be imported from modules

import math

math.e

math.pi



math.log(math.e)

math.e(math.log(0))


math.e**math.log(7)


must_be_true = math.e**math.log(7) == 7

must_be_true = (math.e**math.log(7) - 7) < 0.0000001


# When you import a module, you can use any object in the module by using the module name and dot before the object (usually a function or a constant).


# You can choose your own abbreviations for modules