Beispiel #1
0
def np_logistic_distribution():
    x = random.logistic(loc=1, scale=2, size=(2, 3))
    print(x)
    # sns.distplot(random.logistic(size=1000), hist=False)
    sns.distplot(random.normal(scale=2, size=1000), hist=False, label='normal')
    sns.distplot(random.logistic(size=1000), hist=False, label='logistic')
    plt.show()
Beispiel #2
0
def synthetic_data():
    mixing_0 = empirical_mn([1, 1, 1], eye(3), size=500)
    mixing_1 = empirical_mn([-1, -1, -1], eye(3), size=500)
    sources = logistic(0, 1, size=(3, 50000))

    data = dot(vstack((mixing_0,mixing_1)), sources) +\
           uniform(low=1, high=2,  size=(1, 50000))
    labels = [0] * 500 + [1] * 500

    return (data, labels)
Beispiel #3
0
def synthetic_data():
    mixing_0 = empirical_mn([1,1,1], eye(3), size = 500)
    mixing_1 = empirical_mn([-1,-1,-1], eye(3), size = 500)
    sources = logistic(0,1, size=(3,50000))
    
    data = dot(vstack((mixing_0,mixing_1)), sources) +\
           uniform(low=1, high=2,  size=(1, 50000))
    labels = [0]*500 + [1]*500

    return (data,labels)
Beispiel #4
0
 def time_to_mutation_rate(tree):
     if not hasattr(GC, "NUMPY_SEEDED"):
         from numpy.random import seed as numpy_seed
         numpy_seed(seed=GC.random_number_seed)
         GC.random_number_seed += 1
         GC.NUMPY_SEEDED = True
     t = read_tree_newick(tree)
     for node in t.traverse_preorder():
         if node.edge_length is not None:
             node.edge_length *= logistic(loc=GC.tree_rate_loc,
                                          scale=GC.tree_rate_scale)
     return str(t)
Beispiel #5
0
def logistic_regression_simulation_ystars(nobs,
                                          xs,
                                          param_matrix,
                                          ymeans,
                                          yvars=None):
    """
    Method 3: underlying latent variable approach.
    Can specify a conditional mean for y here
    beta should NOT contain an intercept
    Y_i* = beta*x + e where e ~ logistic(b0, 1)
    """
    y_stars = xs.dot(param_matrix) + random.logistic(ymeans, 1, nobs).reshape(
        nobs, 1)
    ys = vint(y_stars > 0.)
    return ys
Beispiel #6
0
    def getImpliedPotOdds(self):
        impliedPot = self.potSize
        for action in self.actions:
            if "CALL" in action:
                callSize = int(action.split(':')[1])
            elif "RAISE" in action or "BET" in action:
                minRaise = int(action.split(':')[1])
                maxRaise = int(action.split(':')[2])+minRaise #if we raise
                enumRaises = list(range(minRaise,maxRaise+1))
        try:
            #enumRaises = [0]+[callSize]+enumRaises  fold,call,raise
            #we shift 0->callSize-1 because statistics
            enumRaises = [callSize-1]+[callSize]+enumRaises

        except:
            pass

        try:
            if len(enumRaises)>1: #not just callSize-1
                expectedActions = dict()
                for opponent in self.opponents:
                    currOpp = self.opponents[opponent]
                    randomAction  = 0 
                    samples = 1000
                    for i in range(samples):
                        #scale chosen by inspection
                        randomAction +=int(abs(logistic(currOpp.AF*maxRaise,1)))
                    randomAction /= samples
                    expectedActions[currOpp.name] = Player.closestInt(enumRaises,randomAction)
                for oppAction in expectedActions:
                    if expectedActions[oppAction]==callSize-1:
                        continue
                    else:
                        impliedPot+=expectedActions[oppAction]
                self.impliedPotOdds = callSize/impliedPot
            else:
                pass
        except:
            #no CALL or RAISE in histories
            pass
#
# * Python Numpy Logisitic Distribution

#%%
import numpy as np
from numpy import random
import matplotlib.pyplot as pt
import seaborn as sb

x = random.logistic(loc=1, scale=2, size=(4, 7))
print(x)
# %%
sb.distplot(random.logistic(size=1000))
pt.show()

# %%
# * Normal and Logistic distribution

sb.distplot(random.normal(scale=2, size=1000), label='normal')
sb.distplot(random.logistic(size=1000), label='logistic')
pt.show()

# %%
Beispiel #8
0
 def rvs(self, size=None):
     return random.logistic(loc=self.loc,
                            scale=self.scale,
                            size=self.shape(size))
Beispiel #9
0
def logistic_plus(mu, s):
    result = logistic(mu, s)
    while result < 0:
        result = logistic(mu, s)
    return result
# logistic distribution is used to describe growth
# used extensively in machine learning in logistic regression, neural networks, etc
# loc   - mean, where the peak is (default 0)
# scale - standard deviation, the flatness of distribution (default 1)
# size  - the shape of the returned array

from numpy import random

x = random.logistic(loc = 1, scale = 2, size = (2, 3))
print(x)

from numpy import random
import matplotlib.pyplot as plt
import seaborn as sns

sns.distplot(random.logistic(size = 1000), hist=False)
plt.show()
Beispiel #11
0
    
    timecost.append([mid_time-start_time,time.time()-mid_time])

    #laplace
    start_time=time.time()
    a=dsg.laplace(2,2,times)
    mid_time=time.time()
    b=nr.laplace(2,2,times)
    
    timecost.append([mid_time-start_time,time.time()-mid_time])

    #logistic
    start_time=time.time()
    a=dsg.logistic(2,2,times)
    mid_time=time.time()
    b=nr.logistic(2,2,times)
    
    timecost.append([mid_time-start_time,time.time()-mid_time])

    #lognormal
    start_time=time.time()
    a=dsg.lognormal(1,1,times)
    mid_time=time.time()
    b=nr.lognormal(1,1,times)
    
    timecost.append([mid_time-start_time,time.time()-mid_time])

    #normal
    start_time=time.time()
    a=dsg.normal(1,1,times)
    mid_time=time.time()
Beispiel #12
0
def logistic(size, params):
    try:
        return random.logistic(params['loc'], params['scale'], size)
    except ValueError as e:
        exit(e)
Beispiel #13
0
#discrete distribution, tells how how manz times something 
# _can happen given that we know it happens certain amout of time = lam

x = random.poisson(lam = 4, size = 100000)
sns.distplot(x)

# again poisson is similar to normal
sns.distplot(random.normal(loc=30, scale=5, size=10000), hist = False, label='normal')
sns.distplot(random.poisson(lam=30, size=10000), hist = False, label='poisson')

#%% Uniform distribution
x = random.uniform(1, 10, size = (1000))
sns.distplot(x, kde = False)

#%% logistic and lognormal
random.logistic(loc = 1, scale =2, size = 1000)
sns.distplot(random.normal(loc = 0, scale =1, size = 1000), hist = False, label = 'Normal')
sns.distplot(random.logistic(loc = 0, scale =1, size = 1000), hist= False, label = 'logistic')
sns.distplot(random.lognormal(mean = 0.0, sigma = 1, size = 1000)) # can not be negative
# ligistic distribution has more area in the tails, atherwise the distributions are similar

#%% exponential dist

sns.distplot(random.exponential(scale = 2, size = (10, 10)))

#%% Vectorization - ufuncs

a = [1, 2, 3, 4]
b = [10, 20, 30, 40]
z = []
Beispiel #14
0
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sb
from numpy import random

if __name__ == '__main__':
    # arr = np.arange(1, 101)
    # sb.distplot(arr)
    # print(arr)

    arr = random.normal(loc=50, scale=20, size=100)
    print(arr)
    # sb.histplot(arr, color="lightblue")
    sb.distplot(arr, kde=True)

    # x = random.binomial(n=100, p=0.8, size=100)
    # print(x)
    # sb.distplot(x, hist=True, kde=False)

    # x = random.poisson(lam=5, size=100)
    # print(x)
    # sb.distplot(x, hist=True, kde=False)

    x = random.logistic(loc=50, scale=10, size=100)
    print(x)
    # sb.histplot(x, color="darkorange")
    sb.distplot(x, kde=True)

    plt.show()
 def _calculate_noise_for_node(self, node):
     loc = 0
     scale = power(pi, 2) / 3 * power(self.NOISE, 2)
     noise = random.logistic(loc, scale)
     return noise
Beispiel #16
0
from numpy import random

x = random.logistic(loc=1, scale=2, size=(2, 3))
print(x)
Beispiel #17
0
    for i in range(10):
        points = data[data[:, -1] == i]
        plt.scatter(points[:, 0], points[:, 1])
    plt.show()
    np.save("data/2.npy", data)

    # 3
    data = rdm.uniform([9, 10], [9, 50], (600, 2))
    lm = rdm.uniform(0, 2 * np.pi, 600)
    data[:, 0] = data[:, 0] + lm * 5
    data[:, -1] = data[:, -1] + np.sin(lm) * 50
    data = np.vstack((data, rdm.uniform([27, 50], [27, 80], (600, 2))))
    lm = np.linspace(0, 2 * np.pi, 600)
    data[600:, 0] = data[600:, 0] + lm * 5
    data[600:, -1] = data[600:, -1] + np.sin(lm) * 50
    data = np.vstack((data, rdm.logistic(34, 0.5, (300, 2))))
    data[1200:, -1] = data[1200:, -1] * 4 - 80
    data = np.vstack((data, rdm.uniform([15, -35], [20, 30], (300, 2))))
    data = np.vstack((data, rdm.normal((50, 90), (2, 8), (300, 2))))
    data[:, -1] = data[:, -1] / 3 + 20
    tags = np.vstack((np.ones((600, 1)), np.ones(
        (600, 1)) * 2, np.ones((300, 1)) * 3, np.ones(
            (300, 1)) * 4, np.ones((300, 1)) * 5))
    index = np.arange(2100)
    data = np.hstack((data, tags))
    rdm.shuffle(data)
    for i in range(10):
        points = data[data[:, -1] == i]
        plt.scatter(points[:, 0], points[:, 1])
    plt.xlim(0, 70)
    plt.ylim(0, 70)
Beispiel #18
0
from numpy import random
import matplotlib.pyplot as plt
import seaborn as sns

arr=random.logistic(size=(2,4))

print(arr)
sns.distplot(arr,hist=False)

plt.show()
1. ye growth ko show karne ke liye use hota hai.
2. ye bahot jaruri hai because aage chal ke ye ml aur neural networking me use hoga.
3. ye continuous probability distribution hai
4. isme 2 parameters hote hain pdf (probability density function) and cdf (cumulative density function)

Logistic distribution arg: 
    loc: mean , deafult me ye 0 (zero)
    scale: standard deviation, default value is 1
    size: matrix 
'''

from numpy import random as r
import seaborn as sns
import matplotlib.pyplot as plt

logistcVar = r.logistic(loc=1, scale=2, size=(2,3))
print('\n\n',logistcVar,'\n')

# use seaborn to get plto point
# sns.distplot(r.logistic(loc=1, scale=1, size=(100)), hist=False)
# use plt.show() to show graph
sns.distplot(r.normal(loc=1, scale=2, size=(100)), hist=False, label='noraml')
sns.distplot(r.logistic(loc=1, scale=1, size=(100)), hist=False, label='logstic')
plt.show()


'''
Diff b/w Logistc and Normal Distribution

1. logict jo hai ye normal ke comapristion me thoda log distance tak result deta hai.
2. logistic and noraml both center pont result will be like same.
#Generate a random integer from 0 to 100
print(rd.randint(100))

#Generate a 1-D array containing 5 random integers from 0 to 100:
print(rd.randint(100, size=(5)))

#Generate a 2-D array with 3 rows, each row containing 5 random integers from 0 to 100:
print(rd.randint(100, size=(3, 5)))

#Return one of the values in an array:
print(rd.choice([3, 5, 7, 9]))

#Generate a 2-D array that consists of the values in the array parameter (3, 5, 7, and 9):
print(rd.choice([3, 5, 7, 9], size=(3, 5)))
print(rd.choice([3, 5, 7, 9], p=[0.1, 0.3, 0.6, 0.0], size=(100)))
print(rd.choice([3, 5, 7, 9], p=[0.1, 0.3, 0.6, 0.0], size=(3, 5)))

# Draw three numbers greater than or equal to 1.0 and less than 2.0
print(rd.uniform(1.0, 2.0, 3))

# Draw three numbers from a normal distribution with mean 0.0
# and standard deviation of 1.0
print(rd.normal(0.0, 1.0, 3))

# Draw three numbers from a logistic distribution with mean 0.0 and scale of 1.0
print(rd.logistic(0.0, 1.0, 3))

# Set seed
rd.seed(0)
# Generate three random floats between 0.0 and 1.0
print(rd.random(3))
 def logistic(self, mean, scale):
     '''
     Parameters:\n
     mean: float. scale: float, >=0.
     '''
     return r.logistic(mean, scale, self.size)
# logistic distribution is used to describe growth.
# used extensively in machine learning in logistic regression, neural networks etc.
# it has three parameters:
# loc = mean, where peak is. Default = 0.
# scale = standard deviation, flatness of distribution. Default 1.
# size = Shape of returned array.

from numpy import random
import matplotlib.pyplot as plt
import seaborn as sns

arr1 = random.logistic(loc=10, scale=2, size=10)
print(arr1)
arr2 = random.normal(loc=10, scale=2, size=10)
print(arr2)
sns.distplot(arr1, hist=False, label='logistic')
sns.distplot(arr2, hist=False, label='normal')
plt.show()

# both are near identical, but logistic has more area under tails.
# i.e. possibility of more occurrence of number that are futher away from mean