Skip to content
Snippets Groups Projects
Commit d807c596 authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

wip

parent 19fb2910
Branches
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@
<a href=http://www.gnu.org/s/bash/>Bash</a>, <a href=http://www.tcl.tk/>Tcl</a>
<a href=http://www.perl.org/>Perl</a>, <a href=http://www.ruby-lang.org/en/>Ruby</a>
<a href=http://tryapl.org>APL</a>
<a href=http://www.python.org/>Python</a>, <a href=http://docs.python.org/tutorial/>tutorial</a>, <a href=https://xkcd.com/1987>environment</a>, <a href=https://www.jetbrains.com/pycharm/>PyCharm</a>
<a href=http://www.python.org/>Python</a>, <a href=http://docs.python.org/tutorial/>tutorial</a>, <a href=https://xkcd.com/1987>environment</a>, <a href=https://docs.conda.io/en/latest/>Conda</a>, <a href=https://www.jetbrains.com/pycharm/>PyCharm</a>
<a href=http://processing.org/>Processing</a>, <a href=http://www.wiring.org.co/>Wiring</a>, <a href=http://www.arduino.cc/>Arduino</a>, <a href=http://p5js.org>p5.js</a>
<a href=http://www.java.com/>Java</a>, <a href=http://openjdk.java.net/>OpenJDK</a>, <a href=http://icedtea.classpath.org/wiki/Main_Page>IcedTea</a>, <a href=http://tomcat.apache.org>Tomcat</a>
<a href=https://developer.mozilla.org/en-US/docs/Web/JavaScript>JavaScript</a> <a href=https://developer.mozilla.org/en-US/Learn/Getting_started_with_the_web/JavaScript_basics>tutorial</a>, <a href=http://nodejs.org/>Node.js</a>, <a href=https://developers.google.com/v8/>V8</a>, <a href=https://www.npmjs.org/>npm</a>, <a href=http://asmjs.org/>asm.js</a>, <a href=https://webassembly.github.io>WebAssembly</a>, <a href=https://coffeescript.org>CoffeeScript</a>
......@@ -115,7 +115,7 @@
<a href=https://github.com/jeromeetienne/AR.js>AR.js</a>
<a href=https://github.com/aframevr/aframe>A-Frame</a>
<b>math, machine learning</b>
<b><a href=http://fab.cba.mit.edu/classes/MAS.864>math, machine learning</a></b>
<a href=http://www.netlib.org/>Netlib</a>, <a href=http://www.netlib.org/blas/>BLAS</a>, <a href=http://www.netlib.org/linpack/>LINPACK</a>, <a href=http://www.netlib.org/lapack/>LAPACK</a>
<a href=http://www.mathworks.com/>MATLAB</a>, <a href=http://www.gnu.org/software/octave/>Octave</a>
<a href=http://www.numpy.org/>NumPy</a>, <a href=http://www.scipy.org/>SciPy</a>
......@@ -129,8 +129,8 @@
<a href=https://plot.ly>Plotly</a> <a href=https://plot.ly/python/>Python</a> <a href=https://plot.ly/javascript>JavaScript</a>
<a href=programs/plotline.html>plotline.html</a>
<a href=http://d3js.org/>D3</a>, <a href=http://www.jqplot.com/>jqPlot</a>, <a href=http://www.highcharts.com/>Highcharts</a>, <a href=http://www.chartjs.org>Chart.js</a>, <a href=http://mpld3.github.io>mpld3</a>, <a href=http://docs.bokeh.org/en/latest/>Bokeh</a>
<a href=http://deeplearning.net/software/theano>Theano</a>, <a href=https://pytorch.org>PyTorch</a>, <a href=https://keras.io>Keras</a>, <a href=https://www.tensorflow.org>TensorFlow</a>, <a href=https://js.tensorflow.org>TensorFlow.js<a>, <a href=https://www.tensorflow.org/lite/microcontrollers>TensorFlow Lite</a>, <a href=https://github.com/espressif/esp-dl>ESP-DL</a>, <a href=https://www.edgeimpulse.com/>Edge Impulse</a>
<a href=http://www.rle.mit.edu/dspg/pub_books.html>signal processing</a>, <a href=http://fab.cba.mit.edu/classes/MAS.864>mathematical modeling</a>
<a href=https://pytorch.org>PyTorch</a>, <a href=https://www.tensorflow.org>TensorFlow</a>, <a href=https://js.tensorflow.org>TensorFlow.js<a>
<a href=xor.py>xor.py</a> <a href=xor.txt>output</a>
<a href=https://gitlab.cba.mit.edu/pub/pi/blob/master/README.md><b>performance</b></a>
<a href=https://gitlab.cba.mit.edu/pub/pi/-/blob/master/Python/pi.py>pi.py</a>, <a href=https://gitlab.cba.mit.edu/pub/pi/-/blob/master/Python/numpi.py>numpi.py</a>
......@@ -152,7 +152,7 @@
<b>deploy</b>
<a href=https://restfulapi.net/>REST</a>, <a href=https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Introduction>PWA</a>
<a href=https://aws.amazon.com>Amazon AWS</a>, <a href=https://aws.amazon.com/ec2>EC2</a>, <a href=https://aws.amazon.com/lambda>Lambda</a>, <a href=https://github.com/aws/aws-parallelcluster>ParallelCluster</a>, <a href=https://aws.amazon.com/sagemaker>SageMaker</a>, <a href=https://www.honeycode.aws>Honeycode</a>, <a href=remote.html>remote desktop</a>
<a href=https://aws.amazon.com>Amazon AWS</a>, <a href=https://aws.amazon.com/ec2>EC2</a>, <a href=https://aws.amazon.com/lightsail/>Lightsail</a>, <a href=https://aws.amazon.com/lambda>Lambda</a>, <a href=https://github.com/aws/aws-parallelcluster>ParallelCluster</a>, <a href=remote.html>remote desktop</a>
<a href=https://cloud.google.com>Google Cloud</a>, <a href=https://www.google.com/script/start>Apps Script</a>
<a href=https://azure.microsoft.com>Microsoft Azure</a>, <a href=https://powerapps.microsoft.com>Power Apps</a>
<a href=https://www.digitalocean.com>DigitalOcean</a>
......
#
# xor.py
# Neil Gershenfeld 4/27/23
# XOR PyTorch example
#
import torch
import torch.nn as nn
#
# construct data
#
x = torch.tensor([[0, 0],[0, 1],[1, 0],[1, 1]],dtype=torch.float)
y = torch.tensor([0, 1, 1, 0],dtype=torch.float).view(-1, 1)
#
# define model
#
model = torch.nn.Sequential(
nn.Linear(2,2),
nn.Tanh(),
nn.Linear(2,1),
)
#
# initialize model
#
def init(layer):
if type(layer) == torch.nn.Linear:
nn.init.normal_(layer.weight)
model.apply(init)
#
# define training
#
loss = nn.MSELoss(reduction='sum')
optimizer = torch.optim.Adam(model.parameters(),lr=0.01)
#
# training loop
#
for n in range(1000):
ypred = model(x)
error = loss(ypred,y)
if n % 100 == 0:
print(n,error.item())
optimizer.zero_grad()
error.backward()
optimizer.step()
#
# print output
#
ypred = model(x)
print(ypred.detach().numpy())
0 1.8111252784729004
100 0.6191580891609192
200 0.1057029515504837
300 0.0007048047264106572
400 6.663513829607837e-08
500 3.538502824085299e-12
600 2.0037305148434825e-12
700 1.4068746168049984e-12
800 1.5063505998114124e-12
900 1.0516032489249483e-12
[[-3.5762787e-07]
[ 1.0000005e+00]
[ 1.0000006e+00]
[-3.5762787e-07]]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment