Skip to content

Commit

Permalink
chore(opytimizer): Runs the pre-commit hooks for the first time.
Browse files Browse the repository at this point in the history
  • Loading branch information
gugarosa committed May 3, 2022
1 parent 2a5d2a5 commit 75b21ca
Show file tree
Hide file tree
Showing 334 changed files with 4,831 additions and 4,915 deletions.
69 changes: 36 additions & 33 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

import opytimizer

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath("."))


# -- Project information -----------------------------------------------------

project = 'opytimizer'
copyright = '2020, Gustavo de Rosa'
author = 'Gustavo de Rosa'
project = "opytimizer"
copyright = "2020, Gustavo de Rosa"
author = "Gustavo de Rosa"

# The short X.Y version
version = opytimizer.__version__
Expand All @@ -45,33 +45,33 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None
Expand All @@ -82,7 +82,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -100,9 +100,9 @@
# documentation.
#
html_theme_options = {
'collapse_navigation': False,
'display_version': True,
'logo_only': True,
"collapse_navigation": False,
"display_version": True,
"logo_only": True,
}

# Custom sidebar templates, must be a dictionary that maps document names
Expand All @@ -119,7 +119,7 @@
# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'opytimizer_doc'
htmlhelp_basename = "opytimizer_doc"


# -- Options for LaTeX output ------------------------------------------------
Expand All @@ -128,15 +128,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -146,19 +143,21 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'opytimizer.tex', 'Opytimizer Documentation',
'Gustavo de Rosa', 'manual'),
(
master_doc,
"opytimizer.tex",
"Opytimizer Documentation",
"Gustavo de Rosa",
"manual",
),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'opytimizer', 'Opytimizer Documentation',
[author], 1)
]
man_pages = [(master_doc, "opytimizer", "Opytimizer Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------------
Expand All @@ -167,9 +166,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'opytimizer', 'Opytimizer Documentation',
author, 'opytimizer', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"opytimizer",
"Opytimizer Documentation",
author,
"opytimizer",
"One line description of project.",
"Miscellaneous",
),
]


Expand All @@ -188,12 +193,10 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]


# -- Extension configuration -------------------------------------------------
autodoc_default_options = {
'exclude-members': '__weakref__'
}
autodoc_default_options = {"exclude-members": "__weakref__"}

autodoc_member_order = 'bysource'
autodoc_member_order = "bysource"
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sphinx>=3.1.0
sphinx-rtd-theme>=0.4.3
sphinx-rtd-theme>=0.4.3
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@

# Loads the task from file and resumes it
# Note that the following lines achieves the same results as a 35-iteration running
opt = Opytimizer.load('iter_10_checkpoint.pkl')
opt = Opytimizer.load("iter_10_checkpoint.pkl")
opt.start(n_iterations=25)
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@

# Parameters for the optimizer
params = {
'c1': r.generate_binary_random_number(size=(n_variables, 1)),
'c2': r.generate_binary_random_number(size=(n_variables, 1))
"c1": r.generate_binary_random_number(size=(n_variables, 1)),
"c2": r.generate_binary_random_number(size=(n_variables, 1)),
}

# Creates the space, optimizer and function
space = BooleanSpace(n_agents, n_variables)
optimizer = BPSO(params)
function = Function(Knapsack(values=(55, 10, 47, 5, 4), weights=(95, 4, 60, 32, 23), max_capacity=100))
function = Function(
Knapsack(values=(55, 10, 47, 5, 4), weights=(95, 4, 60, 32, 23), max_capacity=100)
)

# Bundles every piece into Opytimizer class
opt = Opytimizer(space, optimizer, function, save_agents=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@
opt = Opytimizer(space, optimizer, function, save_agents=False)

# Runs the optimization task
opt.start(n_iterations=5, callbacks=[DiscreteSearchCallback(allowed_values=allowed_values)])
opt.start(
n_iterations=5, callbacks=[DiscreteSearchCallback(allowed_values=allowed_values)]
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@
max_depth = 5

# Functions nodes, lower and upper bounds
functions = ['SUM', 'MUL', 'DIV']
functions = ["SUM", "MUL", "DIV"]
lower_bound = [-10, -10]
upper_bound = [10, 10]

# Creates the space, optimizer and function
space = TreeSpace(n_agents, n_variables, lower_bound, upper_bound,
n_terminals, min_depth, max_depth, functions)
space = TreeSpace(
n_agents,
n_variables,
lower_bound,
upper_bound,
n_terminals,
min_depth,
max_depth,
functions,
)
optimizer = GP()
function = Function(Sphere())

Expand Down
4 changes: 2 additions & 2 deletions examples/core/create_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ def test_function(z):
f = Function(test_function)

# Prints out some properties
print(f'x: {x}')
print(f'f(x): {f(x)}')
print(f"x: {x}")
print(f"f(x): {f(x)}")
12 changes: 7 additions & 5 deletions examples/core/create_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
from opytimizer.core.node import Node

# Creates two new Nodes
n1 = Node(name='0', category='TERMINAL', value=np.array(1))
n2 = Node(name='1', category='TERMINAL', value=np.array(2))
n1 = Node(name="0", category="TERMINAL", value=np.array(1))
n2 = Node(name="1", category="TERMINAL", value=np.array(2))

# Outputting information about one of the nodes
print(n1)
print(f'Post Order: {n1.post_order} | Size: {n1.n_nodes}.')
print(f"Post Order: {n1.post_order} | Size: {n1.n_nodes}.")

# Additionally, one can stack nodes to create a tree
t = Node(name='SUM', category='FUNCTION', left=n1, right=n2)
t = Node(name="SUM", category="FUNCTION", left=n1, right=n2)

# Defines `n1` and `n2` parent as `t`
n1.parent = t
n2.parent = t

# Outputting information about the tree
print(t)
print(f'Post Order: {t.post_order} | Size: {t.n_nodes} | Minimum Depth: {t.min_depth} | Maximum Depth: {t.max_depth}.')
print(
f"Post Order: {t.post_order} | Size: {t.n_nodes} | Minimum Depth: {t.min_depth} | Maximum Depth: {t.max_depth}."
)
4 changes: 2 additions & 2 deletions examples/functions/create_constrained_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def c_1(z):
f = ConstrainedFunction(test_function, [c_1], 10000.0)

# Prints out some properties
print(f'x: {x}')
print(f'f(x): {f(x)}')
print(f"x: {x}")
print(f"f(x): {f(x)}")
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_function2(z):
h = MultiObjectiveFunction([test_function1, test_function2])

# Testing out your new Function class
print(f'x: {x}')
print(f'f(x): {h.functions[0](x)}')
print(f'g(x): {h.functions[1](x)}')
print(f'h(x) = [f(x), g(x)]: {h(x)}')
print(f"x: {x}")
print(f"f(x): {h.functions[0](x)}")
print(f"g(x): {h.functions[1](x)}")
print(f"h(x) = [f(x), g(x)]: {h(x)}")
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_function2(z):
h = MultiObjectiveWeightedFunction([test_function1, test_function2], [0.5, 0.5])

# Testing out your new Function class
print(f'x: {x}')
print(f'f(x): {h.functions[0](x)}')
print(f'g(x): {h.functions[1](x)}')
print(f'h(x) = 0.5f(x) + 0.5g(x): {h(x)}')
print(f"x: {x}")
print(f"f(x): {h.functions[0](x)}")
print(f"g(x): {h.functions[1](x)}")
print(f"h(x) = 0.5f(x) + 0.5g(x): {h(x)}")
19 changes: 16 additions & 3 deletions examples/integrations/learnergy/dropout_rbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,29 @@

# Creates training and testing dataset
train = torchvision.datasets.MNIST(
root='./data', train=True, download=True, transform=torchvision.transforms.ToTensor())
root="./data",
train=True,
download=True,
transform=torchvision.transforms.ToTensor(),
)


def dropout_rbm(opytimizer):
# Gathers params
dropout = opytimizer[0][0]

# Creates an RBM
model = DropoutRBM(n_visible=784, n_hidden=128, steps=1, learning_rate=0.1,
momentum=0, decay=0, temperature=1, dropout=dropout, use_gpu=False)
model = DropoutRBM(
n_visible=784,
n_hidden=128,
steps=1,
learning_rate=0.1,
momentum=0,
decay=0,
temperature=1,
dropout=dropout,
use_gpu=False,
)

# Training an RBM
error, _ = model.fit(train, batch_size=128, epochs=5)
Expand Down
18 changes: 15 additions & 3 deletions examples/integrations/learnergy/rbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

# Creates training and testing dataset
train = torchvision.datasets.MNIST(
root='./data', train=True, download=True, transform=torchvision.transforms.ToTensor())
root="./data",
train=True,
download=True,
transform=torchvision.transforms.ToTensor(),
)


def rbm(opytimizer):
Expand All @@ -18,8 +22,16 @@ def rbm(opytimizer):
decay = opytimizer[2][0]

# Creates an RBM
model = RBM(n_visible=784, n_hidden=128, steps=1, learning_rate=lr,
momentum=momentum, decay=decay, temperature=1, use_gpu=False)
model = RBM(
n_visible=784,
n_hidden=128,
steps=1,
learning_rate=lr,
momentum=momentum,
decay=decay,
temperature=1,
use_gpu=False,
)

# Training an RBM
error, _ = model.fit(train, batch_size=128, epochs=5)
Expand Down
Loading

0 comments on commit 75b21ca

Please sign in to comment.