Beispiel #1
0
 def Global_Pollination(self, popu, BestValue):
     pop = []
     step = []
     for i in range(self.func.dimension):
         step.append(levy.pdf(1.5))
     for i in range(self.func.dimension):
         temp = popu[i] + step[i] * (BestValue[i] - popu[i])
         pop.append(temp)
     return pop
def butterfly_adjusting_operator(subpopulation2, Xbest, Maxgen, Smax, t, p,
                                 BAR, v, w):  #return subpopulation2
    NP2 = subpopulation2.shape[0]
    d = int((subpopulation2.shape[1] - 2) / 2)
    dx = np.empty(d)
    omega = Smax / (t**2)  #t is the current generation
    for i in range(d):
        StepSize = math.ceil(np.random.exponential(2 * Maxgen))
        dx[i] = levy.pdf(StepSize)
    for i in range(NP2):  #for all monarch in subpopulation 2
        for j in range(d):  # for all elements in monarch
            rand = np.random.uniform(0, 1)
            if rand <= p:
                subpopulation2[i, j] = Xbest[j]
            else:
                r3 = np.random.randint(0, NP2)
                subpopulation2[i, j] = subpopulation2[r3, j]
                if rand > BAR:
                    subpopulation2[
                        i, j] = subpopulation2[i, j] + omega * (dx[j] - 0.5)

    update_array(subpopulation2, v, w)
    return subpopulation2
from scipy.stats import levy
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 1)

# Calculate a few first moments:

mean, var, skew, kurt = levy.stats(moments='mvsk')

# Display the probability density function (``pdf``):

x = np.linspace(levy.ppf(0.01), levy.ppf(0.99), 100)
ax.plot(x, levy.pdf(x), 'r-', lw=5, alpha=0.6, label='levy pdf')

# Alternatively, the distribution object can be called (as a function)
# to fix the shape, location and scale parameters. This returns a "frozen"
# RV object holding the given parameters fixed.

# Freeze the distribution and display the frozen ``pdf``:

rv = levy()
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

# Check accuracy of ``cdf`` and ``ppf``:

vals = levy.ppf([0.001, 0.5, 0.999])
np.allclose([0.001, 0.5, 0.999], levy.cdf(vals))
# True

# Generate random numbers:
Beispiel #4
0
from scipy.stats import levy

print(levy.pdf(6, 3, 3))
Beispiel #5
0
from scipy.stats import levy
print(levy.pdf(6,3,3))