Polar Rose in Julia

Background

I’m doing exercise 4.9 of Think Julia, which asks for a function for a polar rose using Luxor’s turtle graphics.

Difficulties

  1. Work out the geometric structure of the family of polar roses. The key is to construct some auxiliary isoceles triangles and work out the angles between them. One sees that they are parametrized by two varaibles n and k.
    • n: number of petals
    • k: petal increment
    • constraint: k ≠ n ÷ 2
  2. Handle the case when gcd(n, k) > 1, i.e. more than one closed loop.
  3. The positive x direction goes to the right; the positive y direction goes down.

Attempt

  1. Use ThinkJulia.Reposition(t::Turtle, x, y) to reposition the turtle.
  2. Use turn(t::Turtle, θ) to turn t
  3. Use ThinkJulia.Orientation(t::Turtle, θ) to restore the turtle’s orientation after the move.

Code

I spend three days writing and testing this function.

[Read More]

Package Versioning for Julia Projects

Resolved GLM installation error

Update: Thanks to JuliaRegistries/General#647, the version cap of the package Distributions has now been removed, so that one can directly install the package GLM along with Distributions v0.19.2.

Background

I’m reading the book Statistics with Julia, which makes use of GLM.

Problem

I encountered the following error, which I posted in the issue GLM.jl#311.

(v1.1) pkg> add GLM
 Resolving package versions...
ERROR: Unsatisfiable requirements detected for package GLM [38e38edf]:
 GLM [38e38edf] log:
 ├─possible versions are: [0.2.0-0.2.5, 0.3.0-0.3.2, 0.4.0-0.4.8, 0.5.0-0.5.6, 0
.6.0-0.6.1, 0.7.0, 0.8.0-0.8.1, 0.9.0, 0.10.0-0.10.1, 0.11.0, 1.0.0-1.0.2, 1.1.0
-1.1.1] or uninstalled
 ├─restricted to versions * by an explicit requirement, leaving only versions [0
.2.0-0.2.5, 0.3.0-0.3.2, 0.4.0-0.4.8, 0.5.0-0.5.6, 0.6.0-0.6.1, 0.7.0, 0.8.0-0.8
.1, 0.9.0, 0.10.0-0.10.1, 0.11.0, 1.0.0-1.0.2, 1.1.0-1.1.1]
 ├─restricted by compatibility requirements with DataFrames [a93c6f00] to versio
ns: [0.4.0-0.4.8, 0.5.0-0.5.6, 0.6.0-0.6.1, 0.7.0, 0.8.0-0.8.1, 0.9.0, 0.10.0-0.
10.1, 0.11.0, 1.0.0-1.0.2, 1.1.0-1.1.1] or uninstalled, leaving only versions: [
0.4.0-0.4.8, 0.5.0-0.5.6, 0.6.0-0.6.1, 0.7.0, 0.8.0-0.8.1, 0.9.0, 0.10.0-0.10.1,
 0.11.0, 1.0.0-1.0.2, 1.1.0-1.1.1]
  └─DataFrames [a93c6f00] log:
    ├─possible versions are: [0.1.0, 0.2.0-0.2.5, 0.3.0-0.3.16, 0.4.0-0.4.3, 0.
5.0-0.5.12, 0.6.0-0.6.11, 0.7.0-0.7.8, 0.8.0-0.8.5, 0.9.0-0.9.1, 0.10.0-0.10.1, 
0.11.0-0.11.7, 0.12.0, 0.13.0-0.13.1, 0.14.0-0.14.1, 0.15.0-0.15.2, 0.16.0, 0.17
.0-0.17.1, 0.18.0-0.18.2] or uninstalled
    └─restricted to versions 0.18.2 by an explicit requirement, leaving only ve
rsions 0.18.2
 ├─restricted by compatibility requirements with StatsBase [2913bbd2] to version
s: [0.11.0, 1.0.0-1.0.2, 1.1.0-1.1.1] or uninstalled, leaving only versions: [0.
11.0, 1.0.0-1.0.2, 1.1.0-1.1.1]
  └─StatsBase [2913bbd2] log:
    ├─possible versions are: [0.1.0, 0.2.0-0.2.1, 0.2.3-0.2.10, 0.3.0-0.3.13, 0
.4.0-0.4.4, 0.5.0-0.5.3, 0.6.0-0.6.16, 0.7.0-0.7.4, 0.8.0-0.8.3, 0.9.0, 0.10.0, 
0.11.0-0.11.1, 0.12.0, 0.13.0-0.13.1, 0.14.0-0.14.1, 0.15.0, 0.16.0-0.16.1, 0.17
.0, 0.18.0, 0.19.0-0.19.5, 0.20.0-0.20.1, 0.22.0, 0.23.0-0.23.1, 0.24.0, 0.25.0,
 0.26.0, 0.27.0, 0.28.0-0.28.1, 0.29.0, 0.30.0] or uninstalled
    └─restricted to versions 0.30.0 by an explicit requirement, leaving only ve
rsions 0.30.0
 └─restricted by compatibility requirements with Distributions [31c24e10] to ver
sions: uninstalled  no versions left
   └─Distributions [31c24e10] log:
     ├─possible versions are: [0.1.0-0.1.4, 0.2.0-0.2.13, 0.3.0, 0.6.4-0.6.7, 0.
7.0-0.7.6, 0.8.0-0.8.10, 0.9.0, 0.10.0-0.10.2, 0.11.0-0.11.1, 0.12.0-0.12.5, 0.1
3.0, 0.14.0-0.14.2, 0.15.0, 0.16.0-0.16.4, 0.17.0, 0.18.0, 0.19.1-0.19.2] or uni
nstalled
     └─restricted to versions 0.19.2 by an explicit requirement, leaving only ve
rsions 0.19.2

Discussion

Although the packages StatsBase and DataFrames appear in the above error message, the cause of this problem was actually the package Distributions.

[Read More]
Julia  GLM 

Juno Installation 2019

Log of system-wide config

Goal

To install Juno for convenient development in Julia.

Problem

After Juno installation, I received the following error.

Juno error

Analysis

From the error message, the system had tried to find an executable file julia, which would then be executed by the shell /bin/sh. Nonetheless, it’s absent from the system’s environment $PATH, so Juno couldn’t find it.

I’ve only changed my $PATH in ZSHRC, which is user-specific.

Solution

This Stack Overflow question about $PATH setting on *nix has provided various solution. As I was in a hurry to get Julia run on Juno, I’ve taken the advice from the best answer. I prefer creating a separate shortcut under /usr/bin, rather than editing system-wide config files.

[Read More]
Juno  Atom  Julia 

Julia Rcall Installation

Rcall.jl build failure due to missing dependencies

Problem

During the installation of RCall.jl, the package wasn’t successfully built due to a missing variable $R_HOME.

$ julia -q
julia> Pkg.add("RCall")
 Resolving package versions...
 Installed WinReg ─ v0.3.1
 Installed RCall ── v0.13.2
  Updating `~/.julia/environments/v1.0/Project.toml`
  [6f49c342] + RCall v0.13.2
  Updating `~/.julia/environments/v1.0/Manifest.toml`
  [6f49c342] + RCall v0.13.2
  [1b915085] + WinReg v0.3.1
  Building RCall → `~/.julia/packages/RCall/ffM0W/deps/build.log`
┌ Error: Error building `RCall`:
│ ERROR: LoadError: R_HOME is not a directory.
│ Stacktrace:
│  [1] error(::String) at ./error.jl:33
│  [2] top-level scope at logging.jl:322
│  [3] top-level scope at /home/vin100/.julia/packages/RCall/ffM0W/deps/build.jl
:19
│  [4] include at ./boot.jl:317 [inlined]
│  [5] include_relative(::Module, ::String) at ./loading.jl:1041
│  [6] include(::Module, ::String) at ./sysimg.jl:29
│  [7] include(::String) at ./client.jl:388
│  [8] top-level scope at none:0
│ in expression starting at /home/vin100/.julia/packages/RCall/ffM0W/deps/build.
jl:10
└ @ Pkg.Operations /buildworkjr/worker/package_linux64/build/usr/share/julia/std
lib/v1.0/pkg/src/operations.jl:1069

Discussion

It took me a few minutes to realise that the cause of this error is the absence of R. I referred to CRAN’s installation instructions for Ubuntu and added

[Read More]
Julia  RCall  R 

Install Julia From Source

Custom built Julia from GitHub

Goal

To get Julia installed as a normal user on RHEL 6.

Motivation

Julia talks like Python but walks like C.”

To do statistics more efficiently.

The compiled binaries often contain install scripts which put files to shared folders under /usr. Consequently, they have to be run as sudo privileges. That drove me to start this lengthy Julia compilation.

Installation

Without sudo privileges, I’ve chosen to compile Julia from source. I was too lazy to get the dependencies fixed. I just compiled it without GFortran and pkg-config under the ~/src folder.

[Read More]
Linux  Julia