From 1017a2614c1708bac638fec5108b5dc83729f760 Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 2 Apr 2019 20:36:52 +0200 Subject: some new stuff --- .../00010_Links-and-Literature/index.md | 3 +- 00_blog/00040_Haskell/00020_GHC-Notes/index.md | 30 ++--- .../00040_Convex-and-Concave-Hulls/alpha.png | Bin 0 -> 555961 bytes .../00040_Convex-and-Concave-Hulls/index.md | 20 ++++ 00_blog/00040_Haskell/00040_Graham-Scan/index.md | 128 --------------------- .../00040_Haskell/00220_Neural-Networks/index.md | 7 ++ .../00240_FFI-Foreign-Function-Interface/index.md | 19 +++ 7 files changed, 64 insertions(+), 143 deletions(-) create mode 100644 00_blog/00040_Haskell/00040_Convex-and-Concave-Hulls/alpha.png create mode 100644 00_blog/00040_Haskell/00040_Convex-and-Concave-Hulls/index.md delete mode 100644 00_blog/00040_Haskell/00040_Graham-Scan/index.md create mode 100644 00_blog/00040_Haskell/00240_FFI-Foreign-Function-Interface/index.md (limited to '00_blog/00040_Haskell') diff --git a/00_blog/00040_Haskell/00010_Links-and-Literature/index.md b/00_blog/00040_Haskell/00010_Links-and-Literature/index.md index b09733d..4ede8c0 100644 --- a/00_blog/00040_Haskell/00010_Links-and-Literature/index.md +++ b/00_blog/00040_Haskell/00010_Links-and-Literature/index.md @@ -1,10 +1,11 @@ # Haskell - Books, Links and Papers -A growing collection of external links and books concerning Haskell. +A growing collection of external links and books concerning (or tangent to) Haskell. * **Learn You a Haskell** for Great Good by Marian Lipovaca * **Real World Haskell** by Bryan O'Sullivan, Don Stewart, and John Goerzen * **Parallel and Concurrent Programming in Haskell** by Simon Marlow +* **Category Theory for Programmers** by Bartosz Milewski * **Haskell Wiki** * **UPENN CIS 194** * **What I Wish I Knew When Learning Haskell** by Stephen Diehl diff --git a/00_blog/00040_Haskell/00020_GHC-Notes/index.md b/00_blog/00040_Haskell/00020_GHC-Notes/index.md index c945319..acee63f 100644 --- a/00_blog/00040_Haskell/00020_GHC-Notes/index.md +++ b/00_blog/00040_Haskell/00020_GHC-Notes/index.md @@ -2,33 +2,35 @@ ## Some GHC Flags - -v verbose mode - -O2 level 2 optimizations - -rtsopts allow +RTS flags - -prof enable basic time and allocation profiling - -auto-all cost centers on all top level functions - (you can also add them via the SCC pragma) - -caf-all generate data for CAFs (constant applicative forms) - -fforce-recomp force recompilation + -v verbose mode + -O2 level 2 optimizations + -rtsopts allow +RTS flags + -prof enable basic time and allocation profiling + -auto-all cost centers on all top level functions + (you can also add them via the SCC pragma) + -fprof-auto replaced -auto-all + -caf-all generate data for CAFs (constant applicative forms) + -fprof-cafs replaced -caf-all + -fforce-recomp force recompilation -threaded Use threaed runtime -eventlog enables +RTS -l flag -Wall -Werror + -no-hs-main supress linking main module + Notes: you will obtain the profiling versions of dependancies via: stack install --profile [libraryname] - -fprof-auto replaced -auto-all - -fprof-cafs replaced -caf-all ## Some +RTS flags - -K set stack limit + -K set stack limit -s statistic reporting - -p profiling - -hc extract heap profile - -hy allocation by type + -p profiling + -hc extract heap profile + -hy allocation by type -hd allocation by constructor -ix x is sampling frequency in seconds. e.g. 0.01) -Nx x is number of cores to utilize diff --git a/00_blog/00040_Haskell/00040_Convex-and-Concave-Hulls/alpha.png b/00_blog/00040_Haskell/00040_Convex-and-Concave-Hulls/alpha.png new file mode 100644 index 0000000..a8cbe34 Binary files /dev/null and b/00_blog/00040_Haskell/00040_Convex-and-Concave-Hulls/alpha.png differ diff --git a/00_blog/00040_Haskell/00040_Convex-and-Concave-Hulls/index.md b/00_blog/00040_Haskell/00040_Convex-and-Concave-Hulls/index.md new file mode 100644 index 0000000..d68abcd --- /dev/null +++ b/00_blog/00040_Haskell/00040_Convex-and-Concave-Hulls/index.md @@ -0,0 +1,20 @@ + December 2017 +# Calculating Convex and Concave Hulls + +Experimenting with Convex and Concave Hulls with Haskell + +## Concave + + +SVG generated via Graham Scan + +## Convex +![](alpha.png){}\ +Alpha Shapes and Concave Hulls obtained from the delaunay triangulation + +## Ref + +* STOC '83 Proceedings of the fifteenth annual ACM symposium on Theory of computing / Primitives for the manipulation of general subdivisions and the computation of Voronoi diagrams + +## Git +* diff --git a/00_blog/00040_Haskell/00040_Graham-Scan/index.md b/00_blog/00040_Haskell/00040_Graham-Scan/index.md deleted file mode 100644 index 195dbe1..0000000 --- a/00_blog/00040_Haskell/00040_Graham-Scan/index.md +++ /dev/null @@ -1,128 +0,0 @@ -Haskell – Convex Hull – Graham Scan -=================================== - -December 16, 2017 - -Playing with Convex Hulls (via Graham Scan) and SVG Export in Haskell: - -This is an embedded SVG generated by the Haskell programm below: - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.haskell .numberLines} ---------------------------------------------------------------------------------------------- --- --- GRAHAM SCAN IMPLEMENTATION --- --- This little haskell programm calulates the Convex Hull for a set of 2D points. --- It ships wit a main function that feeds the Graham Scan algorithm with some --- random points and generates a simple SVG of the input points and resulting envelope. --- A simple SVG encoder is included. --- --- Alogrithm used: https://en.wikipedia.org/wiki/Graham_scan --- --- CREDITS -- --- --- Michal Idziorek --- 16 December 2017 --- ---------------------------------------------------------------------------------------------- - -import Data.List -import System.Random - ---------------------------------------------------------------------------------------------- - --- GRAHAM SCAN -- - --- Three points are clockwise if ccw < 0. -ccw (p1x,p1y) (p2x,p2y) (p3x,p3y) = (p2x - p1x)*(p3y - p1y) - (p2y - p1y)*(p3x - p1x) - --- Calculate the slope defined by 2 points. (return Infinity, if points are identical). -slope (ax,ay) (bx,by) | (ax,ay ) == (bx,by) = 1/0 -- Infinity - | otherwise = (bx-ax)/(by-ay) - --- Comparison function to sort points counterclockwise (given a reference point). -slope_cmp a b c = compare (slope a c) (slope a b) - --- Comparison function using the y and x coordinates for ordering. -graham_cmp (ax,ay) (bx,by) | ay /= by = compare ay by - | otherwise = compare ax bx - --- Graham scan on prepared data. this will calculate the convex hull. -graham_calc [] hs = hs -graham_calc (x1:xs) hh | length(hh) < 2 = graham_calc xs (x1:hh) -graham_calc xx@(x1:xs) hh@(h1:h2:hs) | ccw x1 h1 h2 < 0 = graham_calc xs (x1:hh) - | otherwise = graham_calc xx (h2:hs) - --- Find the starting point, sort all points counterclockwise and perform the graham scan. -graham xs = graham_calc sortedPoints [] - where minPoint = minimumBy graham_cmp xs - sortedPoints = sortBy (slope_cmp minPoint) xs - ---------------------------------------------------------------------------------------------- - --- XML ENCODING-- - -xml_attr (x:xs) = x++"=\""++(head xs)++"\" " -xml_enc tag attrs body = "<"++tag++" "++xml_attrs++">"++body++"" - where xml_attrs = unlines $ map xml_attr attrs - --- SVG ENCODING -- - --- hardcoded scaling and panning function -svg_transf x = x*30+5 - -line_to_svg ((x1,y1),(x2,y2)) = xml_enc "line" [["x1",show lx1],["y1",show ly1], - ["x2",show lx2],["y2",show ly2], - ["style", "stroke:rgb(255,0,0);stroke-width:2"]] "" - where lx1=svg_transf x1 - lx2=svg_transf x2 - ly1=svg_transf y1 - ly2=svg_transf y2 - -point_to_svg (x,y) = xml_enc "circle" [["cx",show cx],["cy",show cy],["r","5"], - ["fill","rgb(30,150,"++(show (floor dist))++")"]] "" - where cx=svg_transf x - cy=svg_transf y - dist= (sqrt ((x-5)*(x-5) + (y-5)*(y-5)))*255/8 - - - --- draws SVG points and lines (in hardcoded sizes and colors) -svg_draw p l = xml_enc "svg" [style,["width","330"],["height","330"]] body - where style = ["style", - "background-color:black;border:3px solid green;margin:2px;"] - body = (unlines (map point_to_svg p )) ++ - (unlines (map line_to_svg l )) - --- calculate convex hull and generate svg -svg_graham xs = svg_draw xs (zip hull hull_open) - where hull_open = graham xs - hull = (last hull_open) : hull_open - --- RANDOMIZING -- - -randomPoints g cnt = take cnt (zip r10a r10b) - where r5 = randomRs (0,5) g :: [Double] - r10a =zipWith (+) r5 (drop cnt r5) - r10b =zipWith (+) (drop (2*cnt) r5) (drop (3*cnt) r5) - ---------------------------------------------------------------------------------------------- - --- MAIN -- - --- Note that this is the only place of impurity in this source-file. --- Is is subject to side effects due to I/O (we are writng to stdout) --- and the random number generator. -main = do - g <- newStdGen - putStr (svg_graham (randomPoints g 25)) - putStr (svg_graham (randomPoints g 50)) - putStr (svg_graham (randomPoints g 100)) - putStr (svg_graham (randomPoints g 250)) - putStr (svg_graham (randomPoints g 500)) - putStr (svg_graham (randomPoints g 1500)) - ---------------------------------------------------------------------------------------------- -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/00_blog/00040_Haskell/00220_Neural-Networks/index.md b/00_blog/00040_Haskell/00220_Neural-Networks/index.md index 16b39d0..e298046 100644 --- a/00_blog/00040_Haskell/00220_Neural-Networks/index.md +++ b/00_blog/00040_Haskell/00220_Neural-Networks/index.md @@ -64,6 +64,12 @@ yourself familiar with, when learning about neural networks. * backpropagation (based on 4 fudnamental equations / check proofs) * weighted input * saturated neuron +* softmax +* log-likehood +* overfitting +* hyper-parameters +* validation data +* regularization (l1,l2,dropout) ## Git Repo @@ -75,3 +81,4 @@ yourself familiar with, when learning about neural networks. * [2] * [3] * [4] +* [5] diff --git a/00_blog/00040_Haskell/00240_FFI-Foreign-Function-Interface/index.md b/00_blog/00040_Haskell/00240_FFI-Foreign-Function-Interface/index.md new file mode 100644 index 0000000..892f4cd --- /dev/null +++ b/00_blog/00040_Haskell/00240_FFI-Foreign-Function-Interface/index.md @@ -0,0 +1,19 @@ + March 2019 +# Haskell - Foreign Function Interface + +Haskell's FFI allows easily to cooperate with other languages. Foreign functions can call Haskell code and vice versa. +Simple examples can be found in my git repository [1]. For now, the provided Makefile exposes two interesting targets: + +* **c\_from\_hask** - simple program with a C function called from Haskell. +* **hask\_from\_c** - simple programm with a Haskell function called from C. + +The next step is to pass more complicated structures via _ForeignPtr_'s. + +## Notes + +* since version 8.4 GHC guarantees that garbage collection will never occur during an unsafe call. + +## Ref +* [1] +* [2] +* [3] -- cgit v1.2.3