mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-17 14:58:10 +00:00
Remove code with side effects from main (#1577)
* Remove code with side effects from main When running tests withy pytest, some modules execute code in main scope and open plot or browser windows. Moves such code under `if __name__ == "__main__"`. * fixup! Format Python code with psf/black push
This commit is contained in:
parent
5616fa9e62
commit
12f69a86f5
|
@ -6,14 +6,15 @@ Requirements:
|
|||
Python:
|
||||
- 3.5
|
||||
"""
|
||||
# Create universe of discourse in python using linspace ()
|
||||
import numpy as np
|
||||
import skfuzzy as fuzz
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Create universe of discourse in python using linspace ()
|
||||
X = np.linspace(start=0, stop=75, num=75, endpoint=True, retstep=False)
|
||||
|
||||
# Create two fuzzy sets by defining any membership function (trapmf(), gbellmf(),gaussmf(), etc).
|
||||
import skfuzzy as fuzz
|
||||
|
||||
abc1 = [0, 25, 50]
|
||||
abc2 = [25, 50, 75]
|
||||
young = fuzz.membership.trimf(X, abc1)
|
||||
|
@ -42,7 +43,6 @@ bdd_difference = fuzz.fuzzy_or(X, zero, X, young - middle_aged)[1]
|
|||
# max-min composition
|
||||
# max-product composition
|
||||
|
||||
|
||||
# Plot each set A, set B and each operation result using plot() and subplot().
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ def viz_polymonial():
|
|||
return
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
viz_polymonial()
|
||||
|
||||
# Predicting a new result with Polymonial Regression
|
||||
|
|
|
@ -59,6 +59,7 @@ def plot(samples):
|
|||
return fig
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 1. Load Data and declare hyper
|
||||
print("--------- Load Data ----------")
|
||||
mnist = input_data.read_data_sets("MNIST_data", one_hot=False)
|
||||
|
@ -71,25 +72,28 @@ G_input = 100
|
|||
hidden_input, hidden_input2, hidden_input3 = 128, 256, 346
|
||||
hidden_input4, hidden_input5, hidden_input6 = 480, 560, 686
|
||||
|
||||
|
||||
print("--------- Declare Hyper Parameters ----------")
|
||||
# 2. Declare Weights
|
||||
D_W1 = (
|
||||
np.random.normal(size=(784, hidden_input), scale=(1.0 / np.sqrt(784 / 2.0))) * 0.002
|
||||
np.random.normal(size=(784, hidden_input), scale=(1.0 / np.sqrt(784 / 2.0)))
|
||||
* 0.002
|
||||
)
|
||||
# D_b1 = np.random.normal(size=(128),scale=(1. / np.sqrt(128 / 2.))) *0.002
|
||||
D_b1 = np.zeros(hidden_input)
|
||||
|
||||
D_W2 = (
|
||||
np.random.normal(size=(hidden_input, 1), scale=(1.0 / np.sqrt(hidden_input / 2.0)))
|
||||
np.random.normal(
|
||||
size=(hidden_input, 1), scale=(1.0 / np.sqrt(hidden_input / 2.0))
|
||||
)
|
||||
* 0.002
|
||||
)
|
||||
# D_b2 = np.random.normal(size=(1),scale=(1. / np.sqrt(1 / 2.))) *0.002
|
||||
D_b2 = np.zeros(1)
|
||||
|
||||
|
||||
G_W1 = (
|
||||
np.random.normal(size=(G_input, hidden_input), scale=(1.0 / np.sqrt(G_input / 2.0)))
|
||||
np.random.normal(
|
||||
size=(G_input, hidden_input), scale=(1.0 / np.sqrt(G_input / 2.0))
|
||||
)
|
||||
* 0.002
|
||||
)
|
||||
# G_b1 = np.random.normal(size=(128),scale=(1. / np.sqrt(128 / 2.))) *0.002
|
||||
|
@ -97,7 +101,8 @@ G_b1 = np.zeros(hidden_input)
|
|||
|
||||
G_W2 = (
|
||||
np.random.normal(
|
||||
size=(hidden_input, hidden_input2), scale=(1.0 / np.sqrt(hidden_input / 2.0))
|
||||
size=(hidden_input, hidden_input2),
|
||||
scale=(1.0 / np.sqrt(hidden_input / 2.0)),
|
||||
)
|
||||
* 0.002
|
||||
)
|
||||
|
@ -106,7 +111,8 @@ G_b2 = np.zeros(hidden_input2)
|
|||
|
||||
G_W3 = (
|
||||
np.random.normal(
|
||||
size=(hidden_input2, hidden_input3), scale=(1.0 / np.sqrt(hidden_input2 / 2.0))
|
||||
size=(hidden_input2, hidden_input3),
|
||||
scale=(1.0 / np.sqrt(hidden_input2 / 2.0)),
|
||||
)
|
||||
* 0.002
|
||||
)
|
||||
|
@ -115,7 +121,8 @@ G_b3 = np.zeros(hidden_input3)
|
|||
|
||||
G_W4 = (
|
||||
np.random.normal(
|
||||
size=(hidden_input3, hidden_input4), scale=(1.0 / np.sqrt(hidden_input3 / 2.0))
|
||||
size=(hidden_input3, hidden_input4),
|
||||
scale=(1.0 / np.sqrt(hidden_input3 / 2.0)),
|
||||
)
|
||||
* 0.002
|
||||
)
|
||||
|
@ -124,7 +131,8 @@ G_b4 = np.zeros(hidden_input4)
|
|||
|
||||
G_W5 = (
|
||||
np.random.normal(
|
||||
size=(hidden_input4, hidden_input5), scale=(1.0 / np.sqrt(hidden_input4 / 2.0))
|
||||
size=(hidden_input4, hidden_input5),
|
||||
scale=(1.0 / np.sqrt(hidden_input4 / 2.0)),
|
||||
)
|
||||
* 0.002
|
||||
)
|
||||
|
@ -133,7 +141,8 @@ G_b5 = np.zeros(hidden_input5)
|
|||
|
||||
G_W6 = (
|
||||
np.random.normal(
|
||||
size=(hidden_input5, hidden_input6), scale=(1.0 / np.sqrt(hidden_input5 / 2.0))
|
||||
size=(hidden_input5, hidden_input6),
|
||||
scale=(1.0 / np.sqrt(hidden_input5 / 2.0)),
|
||||
)
|
||||
* 0.002
|
||||
)
|
||||
|
@ -173,7 +182,6 @@ v16, m16 = 0, 0
|
|||
v17, m17 = 0, 0
|
||||
v18, m18 = 0, 0
|
||||
|
||||
|
||||
beta_1, beta_2, eps = 0.9, 0.999, 0.00000001
|
||||
|
||||
print("--------- Started Training ----------")
|
||||
|
|
|
@ -5,6 +5,8 @@ from bs4 import BeautifulSoup
|
|||
from fake_useragent import UserAgent
|
||||
import requests
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Googling.....")
|
||||
url = "https://www.google.com/search?q=" + " ".join(sys.argv[1:])
|
||||
res = requests.get(url, headers={"UserAgent": UserAgent().random})
|
||||
|
|
Loading…
Reference in New Issue
Block a user