Category Archives: Julia

Making dotted graph paper in Julia with Luxor.jl

By: Tamás K. Papp

Re-posted from: https://tamaspapp.eu/post/dotted-paper-luxor/

I needed some graph paper with subdivisions at centimeters and millimetres. There are some generators online, but I found their output too heavy, visually cluttered, or simply not ideal (yes, I am very picky about these things).

The obvious solution was to generate a PDF or SVG using a program. Before learning Julia, I would have just started in pgf/tikz, and spent hours searching online to do the thing I want. pgf/tikz are fine tools, but I generally try to avoid programming anything nontrivial in LaTeX, so I always have to spend a lot of time debugging my code.

However, being a Julia user, this was a great opportunity to try Luxor.jl, the “Cairo for tourists!”. This means that I don’t have to immerse myself in the intricacies of its syntax and concepts; I can just dip my toes and get the results.

I was not disappointed: within 15 minutes of Pkg.add("Luxor"), I had arrived at a solution I like. I am very satisfied with Luxor.jl and will probably use it in the future when I need graphics built up from primitives.

download as dotted_paper.jl

using Luxor

#######################
# customize script here
#######################
paper = "A4"                       # paper size
major_unit = 1cm                   # gridlines at each
subdivisions = 10                  # dots on gridlines in between
radius = 0.1mm                     # radius for the tiny dots
margins = (5mm, 5mm)               # minimum margins (may be more, centered)
color = "black"                    # color for the tiny dots
filename = "dotted_paper.pdf"      # output goes here, OVERWRITTEN

#######################################################
# runtime code - you probably don't need to change this
#######################################################
pagesize = paper_sizes[paper]
nx, ny = @. floor(Int, (pagesize - (2 * margins)) / major_unit)
offsetx, offsety = @. margins + (pagesize % major_unit) / 2

major_grid_x = offsetx .+ major_unit * (0:nx)
major_grid_y = offsety .+ major_unit * (0:ny)
minor_grid_x = offsetx .+ (major_unit / subdivisions) * (0:(nx*subdivisions))
minor_grid_y = offsety .+ (major_unit / subdivisions) * (0:(ny*subdivisions))

Drawing(paper, filename)
background("white")
sethue(color)
@. circle(Point(major_grid_x, minor_grid_y'), radius, :fill);
@. circle(Point(minor_grid_x, major_grid_y'), radius, :fill);
finish()
preview()

The final PDF is here.

GSoC’18: From Go to AlphaGo

By: Tejan Karmali

Re-posted from: https://tejank10.github.io/jekyll/update/2018/06/09/GSoC-week3-4.html

Hello, world!

In the last post, I had talked about the game of Go and its dynamics. In last two weeks, I worked on the set objectives which were Monte-Carlo Tree Search and putting things together to make AlphaGo Zero.

In the week 3, it was mostly about MCTS. The MCTS is organized into two parts. One is a struct for a node of tree. The other is a struct for Player which uses MCTS to perform move. MCTSPlayer is the struct with which the user will interact. A node of Monte-Carlo tree is defined by a board position, and the different positions it can go to upon playing any of the moves from that board position in the action space. MCTSPlayer provides an API to perform Tree Search. It then selects a move based on tree search, and perform it. While performing tree search virtual loss was used. It means that when selecting a node, it is pretended that evaluation has already taken place. This introduces some stochasticity in selection of node.

MCTSPlayer consists of a neural network. This neural network is used to generate a prediction of policy and value for a given input of board position. This prediction is used to update the values related to the nodes (which we had earlier used as virtual loss). MCTSPlayer’s neural network is of type NeuralNet, which is broken down into 3 parts: Base network, value head and policy head. The input passes through the base network first. The output of it is fed into value head to obtain value of state and into policy head to obtain the policy for it. NeuralNet can also perform the evaluation of two MCTSPlayers, where two players compete in a series of games to decide who is the winner.

I have put up an example of AlphaGo Zero algorithm here. By setting the flags, you can run it. By default it runs the default AGZ algorithms from the paper.