Resources on String Diagrams, and Adjunctions, and Kan Extensions

I’ve been trying to figure out Kan Extensions

Ralf Hinze on Kan Extensions

https://www.cs.ox.ac.uk/ralf.hinze/Kan.pdf

 

But while doing that I went down a rabbit hole on String Diagrams

This post is the first one on String Diagrams that made sense to me.

https://parametricity.com/posts/2015-07-18-braids.html

I had seen this stuff before, but I hadn’t appreciated it until I saw what Haskell expressions it showed equivalence between. They are not obvious equivalences

 

In Summary, it is an excellent notation for talking about transformations of a long sequence of composed Functors  F G H … into some other long sequence of Functors. The conversion of functors runs from up to down. The composition of functors procedes left to right.  F eta is the fmap of eta, and eta F is eta with the forall’ed type unified to be of the form F a.

Adjunctions L -| R are asymmetric between cups and caps. L is on the left in cups and on the right in caps. That’s what makes squiggles pull straightable

I think I have an interesting idea for a linear algebra library based on this stuff

 

John Baez and Mike Stay’s Rosetta Stone (A touch stone I keep returning to)

math.ucr.edu/home/baez/rosetta.pdf

Dan Piponi gave a talk which is another touch stone of mine that I come back to again and again. There is a set of corresponding blog posts.

Other resources:

NCatLab article

https://ncatlab.org/nlab/show/string+diagram

John Baez hosted seminars

http://www.math.ucr.edu/home/baez/QG.html

Catsters

https://www.youtube.com/view_play_list?p=50ABC4792BD0A086

 

Dan Marsden’s Article

https://arxiv.org/abs/1401.7220

Marsden and Hinze have been collaborating

events.inf.ed.ac.uk/wf2016/slides/hinze.pdf

https://link.springer.com/chapter/10.1007/978-3-319-30936-1_8

Stephen Diehl on Adjunctions

http://www.stephendiehl.com/posts/adjunctions.html

 

A Section From an old Oregon Programming Language Summer School (a rich set of resources)

 

Marsden and Hinze have been collaborating

events.inf.ed.ac.uk/wf2016/slides/hinze.pdf

https://link.springer.com/chapter/10.1007/978-3-319-30936-1_8

 

Mike Stay doing a very interesting series of Category Theory in Javascript. He uses contracts in place of types. Defeats one of the big points of types (static analysis), but still pretty cool

 

 

I think that about covers everything I know about.

Oh yeah, there is the whole Coecke and Abramsky categorical quantum mechanics stuff too.

Using the Purescript Servant Bridge

Alright, here is some garbage code. Hope it helps you, sorry if it confuses you.

Checkout the Counter example

https://github.com/eskimor/servant-purescript/tree/master/examples/central-counter

that is where I pulled everything from. I ripped out just about everything fancy just so you and I can see the truly bare bones example.

It’s mostly boiler plate on the generator side.

He does a couple fancier things that you may want, like rearranging names and changing folders. Here is a more basic example

This goes in app/PSGenerator.ps if you’re using a stack template

Mostly things can just be the defaults. Look at the Counter Example for some more config stuff you can do.

You do need to separate out the user json api by itself. If you hand writeAPIModuleWithSettings an api that has the RAW serving the index.html, it freaked out. Maybe there is a way to handle that, but it’s not like that is probably what you want anyhow.

The myTypes Sum Type you want to add to for every type that you want to export over to purescript. frontEndRoot is where the generated files will go.

The Proxy business is a bunch of typelevel programming boilerplate. So is the empty MyBridge type.

There is basically no content to this code.

You also need to add this app/PSGenerator.hs file to your cabal file.

 

Every time you want to run the generator, you need to run

stack exec psGenerator

 

This then will put an API file and a Data type file into your purescript source in frontend/src

Using the API is a touch annoying but correct. If you look at the generated signature

There are a lot of constraints you need to satisfy in the monad m in order to call this thing. You need a monad that is Reader-like for getting the SPSettings_, needs to handle a Possible AjaxError, and needs to be an Aff-like monad. Woof.

It makes sense that you’d want to do all of this, but it is a burdensome mental overhead to get started.

Here’s some very basic source that shows how to at least get to the stage where you can log it the resulting request. I’m just dumping the error like a bad boy.

Note that you have to install purescript-servant-support as it tells you when you run psGenerator. I’ve been using psc-package. It is often helpful to go in to the psc-package.json file and update to the latest package-set. Just a little tip.

You see that the ExceptT handles the AjaxError and the ReaderT supplies the settings, which uses the defaults + a baseURL to point the request to

The whole thing is run inside an Aff monad.

 

Here’s the basic servant code

 

Again, I started using the stack servant template, whose directory structure I’m complying with.

 

Edit: Some more comments: Purescript bridge is a seperate project from servant-purescript. Purescript bridge will translate your Haskell types. Servant purescript writes your api calls. The two lines in the main of PSGenerator.hs do these sepearte tasks. the writeAPI writes the API calls and  writePSTypes writes the types.

If you want to transport a parametrized data type like (Maybe a) in the myTypes things, hand the type a special type from here

https://hackage.haskell.org/package/purescript-bridge-0.11.1.2/docs/Language-PureScript-Bridge-TypeParameters.html

works like a charm

 

 

Downloading and Collecting Coursera videos

I like to watch and listen to my coursera videos on my commute. The app has download functionality but the quizzes and crap require your intervention. I need just a block of stuff so I can be hands free.

coursera-dl is a command line tool to download coursera content

https://github.com/coursera-dl/coursera-dl

basic usage is like so

coursera-dl -h is a help menu

you can pass in your username and password with -u and -p or setup a ~/.netrc file as described in the README

coursera-dl –list-courses -n

I think it should list courses by default honestly.

This downloads all mp4 videos

coursera-dl cloud-computing -n -f “mp4”

 

I then made a dirty script that will go through each week and concatenate the videos of that week hopefully in order into a single mp4 file. It is not a clean script. It will throw some errors and build some weird extra files, but it gets the job done. Run it in the course directory

 

 

 

 

Deep Learning Coursera Notes

 

cross-entropy – expectation value of log(p).

initialization – randn for weights. use 2/sqrt(input size) if using relu. See He. Avoids blow up

epoch – one run through all data

mini-batch – break up data into 1 gpus worth chunks. Worth trying different values to see

momentum – smooths gradients that are oscillating and lets build up

Adam – combined momentum and RMS prop. Works better often? 0.9 for beta1 and 0.999 for beta2 are common parameters.

 

Hyperparameter search – random points use log scales for some things.

reevalute your hyperparametrs occasionally

batch normalization – adds a normalization and mean subtraction at every hidden layer. makes later neurons less susceptible to earlier changes

tensorflow – variables – placeholder, make sessions, run a trainer

strategy – fit training set, dev set, test set, real world

use better optimizer bigger network if not fitting training

use more dat, rgularize if not

satisficing metric

add weight to realyy important examples

bias  – perforance on triainig set – human level is good benchmark

error analysis – ceiling on performance. Find out how many of some kind of problem are happening to figure out what is worthwhile. Do it manually

reasonably robust to random errors in training set

build first fast, iterate fast

if you need to use a different distro from training set, use the real stuff mostly in your dev and test

Break up into train dev and train-dev. so that you can know if the problem is due to mismatch or due to overfitting

manually try to make training set more like dev set on problem cases. Maybe add noise or find more examples of the error prone thing

Transfer learning

Multi-task learning

end to end – use subproblems if you have data for subproblems

 

And… I can’t access the two last ones yet. Poo.

 

 

Fixing up some jekyll problems for jupyter

the jupyer jekyll plugin supposedly won’t work on github pages

https://briancaffey.github.io/2016/03/14/ipynb-with-jekyll.html

jupyter nbconvert –to markdown jekyll_test.ipynb

To get latex (including the $ tags) to work on the minima layout I added

into an _includes/head.html

 

 

I added a pynb  directory and added the following into my _config file? Not sure this was necessary.

 

replace all

fermions_part_1_files

with

/pynb/fermions_part_1_files

in the markdown file.

could also add syntax highlighting but maybe this is good enough.

Maker Faire NYC

My first Maker Faire. Saw some neat stuff. Good energy. Declan made a write up.

Things to investigate:

CircuitStudio / circuitmaker – circuit design software a la Fusion 360 business model from altium. Windows only? Don’t like that

OctoPart – electronic components footprints and BOM

Mesh – Little IoT buttons and sensors

Sam Zeloof – Smart ass kid making his own IC sam.zeloof.xyz

Tindie – Can I buy useful boards from here?

www.photogrammetry.today – Maybe some photogrammetry tips? Hmm. Not anything there yet

plantum.ai another really smart kid doing machine learning

Makerlogic – www.makerlogic.com A guy pushing FPGA education. Max10 based board. Not much there yet

https://shop.openh.io/collections/all – 4G enabled rapsberry pi shields

www.up-board.org – small form factor intel computers and accessories. Keep an eye out for update in realsense in October.

makerscad.com – an interesting combo scratch and openscad javascript kind of thing. Also has physics engines?

 

 

Cellular Automata in Haskell

Ben recently tried this and I wanted to see if I could do it my way

I’ve seen this done (Bartosz?) before but I tried to do it without looking anything up.

The comonad is an interesting pattern to use. It automates the translation invariant nature off the cellular automata. This would also be useful for translationally invariant PDEs like the simple wave equation or others.

I used the laziness of Haskell to start with an infinite plane of zeros. Of course if you ever want to look at it, you need to pick a finite slice at the end using dtake

 

 

Ordered pairs in Idris

I implemented an ordered pair type in Idris. Took me a while.

https://github.com/idris-lang/Idris-dev/blob/master/libs/prelude/Prelude/Nat.idr

Already has an inequality type. That may have been better to use.

Exploration and guesswork was necessary. How the heck do I get a hotkey for holes in atom?

The first couple Opairs are ordinary pairs. Just exploring the syntax.

I switched out of InEq which explicitly stores the number it is talking about to better match the equality type.

The Inequality type acts something like a mix of Nat and Equality.

My head hurts and I’m dehydrated.

 

 

Position Tracking using Wifi

http://web.stanford.edu/~mkotaru/wicapture

I have been aware of machine learning projects that use RSSI (signal strength) (for example, try typing iwconfig in a linux terminal. You can grep that for signal strength.)

CSI (channel state information) is more though. Uses alternative firmware. Gets you phase sensitivity.

https://dhalperi.github.io/linux-80211n-csitool/index.html#external

mini PCIe is a pain. Many laptops support it and mini pcs. But still, that is a ~100$ investment or so.

plausible but unconfirmed alternative for atheros cards

http://pdcc.ntu.edu.sg/wands/Atheros/#PLT

Another paper describing localization

http://cs229.stanford.edu/proj2015/110_report.pdf

https://www.usenix.org/system/files/conference/nsdi16/nsdi16-paper-vasisht.pdf

LimeSDR, gettin going

 

I had trouble installing the ppa the first time I tried about a month ago. It seemed to go through the second time around

Install LimeSuite using the ppa instructions for ubuntu. I have 16.04

https://wiki.myriadrf.org/Lime_Suite

lsusb shows OpenMoko as the device. Odd.

https://wiki.myriadrf.org/LimeSDR_Quick_Start

 

Ok. A capitalized command LimeSuiteGUI is insane. No commands are capitalized.

It brings up some spaceship of cryptic options.

Some of the stuff in the top menu bar seems good. Connecting, Programming, FFT, etc.

The commands

LimeUtil –info

LimeUtil –find

Lists a device. So that’s good. Also does updating?

 

Added a myriad RF ppa for gnuradio

https://wiki.myriadrf.org/Packaging

sudo apt-get install gnuradio gnuradio-dev

Also installed gqrx. This is very useful for determining if the goddamn thing is working at all

Install Gqrx SDR on Ubuntu Linux

 

 

Ok. GQRX was crashing on boot.

So was gnuradio when I tried playing with the osmocom source

GNU C++ version 5.4.0 20160609; Boost_105800; UHD_003.010.001.001-release

ImportError: /usr/lib/python2.7/dist-packages/gnuradio/uhd/_uhd_swig.x86_64-linux-gnu.so: undefined symbol: _ZN3uhd4usrp10multi_usrp7ALL_LOSB5cxx11E

so did python

from gnuradio import uhd

Eventually I apt get installed libuhd-dev which makes gqrx run now with an rtl-sdr

gqrx with line

soapy=0,driver=lime

should work but didn’t

 

Hmm another twist

Limesdr is power hungry

I may not have a usb3 port on my 2012 desktop insane as that sounds

so i need external power? I wonder if that is what the blinking led signifies

 

Trying to install in windows now. Maybe that will work better

Install PothosSDR

After running zadig can recognize an rtl-sdr in gqrx

https://wiki.myriadrf.org/Lime_Suite#USB_driver

Install the drivers as specified for limesdr.

I accidentally installed the x86 instead of the x64 drivers and needed to uninstall with deletion and then reinstall properly. Got error code 48

It appears to be working.

https://wiki.myriadrf.org/LimeSDR-USB_Quick_Test

GQRX opens.

 

 

It has been months since I tried in ubuntu 16.04. Maybe things have gotten better.

ok. At first gqrx wouldn’t load but after fiddling with the sampling and bandwidth it does. I don’t get any FM signals with nothing attached to the Lime. That is either good or bad. It does appear to be receiving data at least though.

 

So I have not gotten gqrx to actually receive signals with limesdr, but gnuradio appears to be working to some degree. This graph plays audio on 101.5 although very crappily. I hope it just needs filtering (I think I should be low passing those resamplers. Also I probably shouldn’t be receiving on the middle of the band where the DC spike is). I doubled the resampler because a single resampler through an error for too much decimation. Is this standard procedure?

simple_lime_fm-grc

Useful gnuradio tutorials

http://files.ettus.com/tutorials/labs/Lab_1-5.pdf

Possibly useful blog series

https://myriadrf.org/blog/limesdr-made-simple-part-4-pothos-beyond/

 

ok. Next step is simple transmit and receive