Testing...
from conx import Network, Layer, SGD, PCA, scatter
Using TensorFlow backend. /usr/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6 return f(*args, **kwds) conx, version 3.5.15
net = Network("XOR Network", 2, 4, 1, activation="sigmoid")
net.compile(loss='mean_squared_error',
optimizer=SGD(lr=0.3, momentum=0.9))
dataset = [
([0, 0], [0], "0"),
([0, 1], [1], "1"),
([1, 0], [1], "1"),
([1, 1], [0], "0")
]
#net["output"].minmax = (0, 1)
net.dataset.clear()
net.dataset.load(dataset)
net.dataset.summary()
Dataset Split:
Input Summary:
Target Summary:
net.dataset.targets[0]
[0.0]
net.dataset.inputs.shape
[(2,)]
widget = net.dashboard()
widget
Failed to display Jupyter Widget of type Dashboard
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
net.propagate([0, 1], visualize=True)
[0.6359257102012634]
net.reset()
net.train(epochs=2000, accuracy=1.0, report_rate=25, record=True, plot=True)
======================================================================== | Training | Training Epochs | Error | Accuracy ------ | --------- | --------- # 381 | 0.00815 | 1.00000
net.test()
======================================================== Testing validation dataset with tolerance 0.1... Total count: 4 correct: 4 incorrect: 0 Total percentage correct: 1.0
net.playback(lambda net, epoch: (
net.plot_activation_map(interactive=False,
scatter=[
["0", [net.dataset.inputs[i] for i in range(len(net.dataset.inputs)) if net.dataset.labels[i] == "0"]],
["1", [net.dataset.inputs[i] for i in range(len(net.dataset.inputs)) if net.dataset.labels[i] == "1"]]],
symbols={"0": "ko", "1": "k+"},
title="Epoch %s" % epoch),
net.plot('all', end=epoch, interactive=False)))
Failed to display Jupyter Widget of type SequenceViewer
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
WARNING: No acc data available for the specified epochs (0-0) WARNING: No loss data available for the specified epochs (0-0)
states = [net.propagate_to("hidden", input) for input in net.dataset.inputs]
pca = PCA(states)
symbols = {
"0 (correct)": "bo",
"0 (wrong)": "bx",
"1 (correct)": "ro",
"1 (wrong)": "rx",
}
net.playback(lambda net, epoch: scatter(**pca.transform_network_bank(net, "hidden"),
symbols=symbols,
interactive=False))
Failed to display Jupyter Widget of type SequenceViewer
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
net.propagate_to("input", [0, 1])
[0.0, 1.0]
net.propagate([0.5, 0.5])
[0.5085740685462952]
net.propagate_to("hidden", [1, 0])
[0.38418060541152954, 0.572746753692627, 0.43381455540657043, 0.6605902314186096]
net.propagate_to("output", [1, 1])
[0.5351778268814087]
net.propagate_to("input", [0.25, 0.25])
[0.25, 0.25]
net.propagate_from("input", [1.0, 1.0])
[0.5351778]
net.propagate_from("hidden", [1.0, 0.0, 1.0, -1.0])
[0.35672686]
net.test()
======================================================== Testing validation dataset with tolerance 0.1... Total count: 4 correct: 0 incorrect: 4 Total percentage correct: 0.0
from conx import Network, Layer, SGD
net = Network("XOR2 Network")
net.add(Layer("input1", 1))
net.add(Layer("input2", 1))
net.add(Layer("hidden1", 10, activation="sigmoid"))
net.add(Layer("hidden2", 10, activation="sigmoid"))
net.add(Layer("shared-hidden", 5, activation="sigmoid"))
net.add(Layer("output1", 1, activation="sigmoid")) # , minmax=(-1,1)))
net.add(Layer("output2", 1, activation="sigmoid")) # , minmax=(-1,1)))
'output2'
net
<Network name='XOR2 Network' (uncompiled)>
net.connect("input1", "hidden1")
net.connect("input2", "hidden2")
net.connect("hidden1", "shared-hidden")
net.connect("hidden2", "shared-hidden")
net.connect("shared-hidden", "output1")
net.connect("shared-hidden", "output2")
net.layers[2].incoming_connections
[<Layer name='input1', shape=(1,), act='None'>]
net.compile(loss='mean_squared_error',
optimizer=SGD(lr=0.3, momentum=0.9))
net.config["hspace"] = 200
widget = net.dashboard()
widget
Failed to display Jupyter Widget of type Dashboard
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
net.propagate_to("hidden1", [[1], [1]])
[0.5891909003257751, 0.6736063361167908, 0.5231307148933411, 0.41695597767829895, 0.3708018958568573, 0.49578002095222473, 0.33628129959106445, 0.5863265991210938, 0.5555092692375183, 0.49335378408432007]
net.propagate([[1], [1]])
[[0.6283185482025146], [0.2138163298368454]]
dataset = [
([[0],[0]], [[0],[0]]),
([[0],[1]], [[1],[1]]),
([[1],[0]], [[1],[1]]),
([[1],[1]], [[0],[0]])
]
net.dataset.load(dataset)
net.get_weights("hidden2")
[[[-0.17665445804595947, 0.6080862879753113, -0.3233792781829834, -0.6478244066238403, -0.7108033895492554, 0.043866515159606934, 0.20450246334075928, -0.4206157326698303, -0.1701200008392334, -0.6520969271659851]], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]
net.propagate([[1], [1]])
[[0.6283185482025146], [0.2138163298368454]]
widget = net.dashboard()
widget
Failed to display Jupyter Widget of type Dashboard
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
import time
net.reset()
for i in range(20):
(epoch_count, results) = net.train(epochs=100, verbose=0, report_rate=25, plot=True)
for index in range(4):
net.propagate(dataset[index][0])
time.sleep(.1)
net.reset()
net.train(epochs=2000, accuracy=1.0, report_rate=25, plot=True)
======================================================================== | Training | output1 | output2 Epochs | Error | acc | acc ------ | --------- | --------- | --------- # 965 | 0.01142 | 1.00000 | 1.00000
net.propagate_from("shared-hidden", [0.0] * 5)
[[0.7263107], [0.8060964]]
net.propagate_to("hidden1", [[1], [1]])
[0.7431058287620544, 0.8438336849212646, 0.1248035803437233, 0.14310242235660553, 0.7969014048576355, 0.6870737075805664, 0.14280001819133759, 0.7915634512901306, 0.27689337730407715, 0.8801047205924988]
net.test()
======================================================== Testing validation dataset with tolerance 0.1... Total count: 4 correct: 4 incorrect: 0 Total percentage correct: 1.0
net.dataset.slice(2)
net.train(epochs=2000, accuracy=1.0, report_rate=25)
No training required: accuracy already to desired value Training dataset status: | Training | output1 | output2 Epochs | Error | acc | acc ------ | --------- | --------- | --------- # 965 | 0.01142 | 1.00000 | 1.00000
net.plot('all')