Skip to content

Instantly share code, notes, and snippets.

@ryanrhymes
Last active August 28, 2017 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanrhymes/c18fdd78b99283a102a721a0fe4f214b to your computer and use it in GitHub Desktop.
Save ryanrhymes/c18fdd78b99283a102a721a0fe4f214b to your computer and use it in GitHub Desktop.
Owl's Tutorial at CUFP 2017

Owl's Tutorial at CUFP 2017

This zoo gist contains the material including dataset, code, and presentation slides for Owl's tutorial at CUFP in Oxford.

Please contact Liang Wang ryanrhymes@gmail.com if you have any questions.

Liang @ Cambridge, UK, 2017

c18fdd78b99283a102a721a0fe4f214b
#!/usr/bin/env owl
open Owl
let t1_load_data () =
let x = Mat.uniform 500 1 in
let p = Mat.uniform 1 1 in
let y = Mat.(x *@ p + gaussian ~sigma:0.05 500 1) in
x, y
let t1_sol () =
let x, y = t1_load_data () in
let h = Plot.create "plot_t1.png" in
let a, b = Linalg.D.linreg x y in
let y' = Mat.(x *$ b +$ a) in
Plot.scatter ~h x y;
Plot.plot ~h ~spec:[ RGB (0,255,0) ] x y';
Plot.output h
let t2_sol () =
let open Algodiff.D in
let x = Owl.Mat.linspace 0. 3. 100 in
let f x = Maths.(sin x) in
let y2 = (f |> diff |> diff) (Mat x) |> unpack_mat in
let y3 = (f |> diff |> diff |> diff) (Mat x) |> unpack_mat in
let open Algodiff.Numerical in
let g x = Pervasives.(sin x) in
let z2 = Owl.Mat.map (g |> diff |> diff) x in
let z3 = Owl.Mat.map (g |> diff |> diff |> diff) x in
let h = Plot.create "plot_t2.png" in
Plot.(plot ~h ~spec:[ LineStyle 2; RGB (255,0,0) ] x y2);
Plot.(plot ~h ~spec:[ LineStyle 1; RGB (255,0,0) ] x y3);
Plot.(plot ~h ~spec:[ LineStyle 2; RGB (0,255,0) ] x z2);
Plot.(plot ~h ~spec:[ LineStyle 1; RGB (0,255,0) ] x z3);
Plot.output h
let _ = print_endline "Welcome to Owl's Tutorial"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment