Never Funconal Programming Language Sawomir Maludziski, Ph.D. Jakub - - PowerPoint PPT Presentation

never
SMART_READER_LITE
LIVE PREVIEW

Never Funconal Programming Language Sawomir Maludziski, Ph.D. Jakub - - PowerPoint PPT Presentation

Never Funconal Programming Language Sawomir Maludziski, Ph.D. Jakub Podgrski Agenda Introducon Movaon Design Design Decisions | Under the Hood Features Demo Neural Network | Perceptron Supervised Learning | Results Mary


slide-1
SLIDE 1

Never

Funconal Programming Language

Sławomir Maludziński, Ph.D. Jakub Podgórski

slide-2
SLIDE 2

Agenda

Introducon Demo Design

Movaon Design Decisions | Under the Hood Features Neural Network | Perceptron Supervised Learning | Results

slide-3
SLIDE 3

Squirrel Euphoria Bertrand Mercury Esterel Crystal Charity Fjölnir Miranda Turing Falcon Pascal Orwell Kien Python Monkey Hermes Escher Euclid Cobra Janus Karel Swi Viper Zebra Mouse Panda Gödel Cybil Alice Clair Julia Euler Mirah Hugo Lynx Pony Pike Hope Agda Lily Reia Lisa Mary Tom D

  • g

Eve Ada A B C D E F G J K M P Q R S T Z

slide-4
SLIDE 4

About Never

Hobby project Creativity escape I wanted to learn more about programming languages Scripting languages are good for prototyping I chose matrices as they are frequently used in science and technology

slide-5
SLIDE 5

Design Decisions

Funconal Programming Language Stacally Typed Boxed Values Syntaccally Scoped Call By Value Reference Model C-Like Syntax

slide-6
SLIDE 6

Under the Hood

Excepon Handler Binary Search Linked Lists, Trees, Hash Maps Wrien in C with Bison/Flex

slide-7
SLIDE 7

Tick - Control - Funcons & Expressions

func calc() -> (float) -> float { func fah2cel(float f) -> float { (f - 32.0) / 1.8 } } func main() -> float { calc()(212.0) }

First class functions Everything is an expression Operators + - * / ?: Float

slide-8
SLIDE 8

Tock - Types - Integer

func gcd(x -> int, y -> int) -> int { (y == 0) ? x : gcd(y, x % y) } func main() -> int { gcd(56, 12) }

Integer Operator % Operators and or not

slide-9
SLIDE 9

Tick - Control - Built-in

func deg2rad(deg -> float) -> float { deg * 3.14159 / 180 } func get_func() -> (float) -> float { cos } func main() -> float { get_func()(deg2rad(60.0)) }

Built-in functions: sin, cos, tan, exp, log, sqrt, pow print, printf, assert

slide-10
SLIDE 10

Tock - Types - Matrices

func rotate_matrix(alpha -> float) -> [_,_] -> float { [ [ cos(alpha), -sin(alpha) ], [ sin(alpha), cos(alpha) ] ] -> float } func main() -> int { var vect = [[ 10.0, 0.0 ]] -> float; print_vect(vect * rotate_matrix(0.0)); }

First class matrices Conformat arrays Overloaded operators + - *

slide-11
SLIDE 11

Tick - Control Flow

var i = 0; var j = 0; for ({ i = 0; j = 0 }; i < 10; { i = i + 1; j = j + 2 }) { print(i + j) }

Bindings Control ow Side effects Operator =

slide-12
SLIDE 12

Tock - Types - String

func main() -> int { var s1 = "text equal"; var s2 = "text equal"; assert(if (s1 == s2) { 1 } else { 0 } == 1) }

Strings Operator == !=

slide-13
SLIDE 13

Tick - Control - Excepons

func one(d -> int) -> int { var f = let func (d -> int) -> int { 12 / d } catch (division_by_zero) { 12 }; f(0) }

Exceptions

slide-14
SLIDE 14

Neural Network in Never

x1

1

x2

2

x3

3

s( s(Σ

Σx

xi

i*w

*wi

i)

) y w1 w2 w3

slide-15
SLIDE 15

Sigmoid

func sigmoid(x -> float) -> float { 1.0 / (1.0 + exp(-x)) }

Function Statically typed Float type Returns expression

1+e−x 1

slide-16
SLIDE 16

Linear Congruenal Generator

func randomize(seed -> int) -> () -> int { var v = seed; func rand() -> int { v = (v * 1103515245 + 12345) % 2147483648 } rand }

First class functions - rand Syntax scope - nested to any level

v - closed within randomize

slide-17
SLIDE 17

Matrix Algebra

func Hadamard_matrix(W1[D1, D2] -> float, W2[D3, D4] -> float) -> [_,_] -> float { var r = 0; var c = 0; var H = {[ D1, D2 ]} -> float; for (r = 0; r < D1; r = r + 1) { for (c = 0; c < D2; c = c + 1) { H[r, c] = W1[r, c] * W2[r, c] } }; H }

Hadamard multiplication Conformant matrices (arrays)

slide-18
SLIDE 18

Forward Propagaon - Input & Output

var x = [ [0, 1, 0], [1, 0, 0], [1, 1, 1], [0, 0, 1] ] -> float; var y = [ [1, 0, 1, 0] ] -> float; var yT = T_matrix(y);

Input matrix x Output transposed matrix

y = [ [1], [0], [1], [0] ]

Middle value as output

slide-19
SLIDE 19

Forward Propagaon - Inializaon

var W = {[ 3, 1 ]} -> float; var rand = randomize(165); rand_matrix(W, rand);

W initialized to random values

slide-20
SLIDE 20

Forward Propagaon - Output Calculaon

var s = {[ 4, 1 ]} -> float; s = sigmoid_matrix(x * W);

Operators +, -, * are overloaded for matrices Output calculated to all inputs Sigmoid function used to get 0/1 results

slide-21
SLIDE 21

Backpropagaon - Error Reducon

  • 1
  • 0.5

0.5 1 1.5

  • 8
  • 6
  • 4
  • 2

2 4 6 8 s(x)

  • ds(x)
slide-22
SLIDE 22

Backpropagaon - Error Calculaon

var err = {[ 4, 1 ]} -> float; err = yT - s;

Calculate error for each input sample

err used to correct W weights

slide-23
SLIDE 23

Backpropagaon - Gradient Descent

var sD = {[ 4, 1 ]} -> float; var one = {[ 4, 1 ]} -> float; sD = Hadamard_matrix(s, one - s); W = W + xT * Hadamard_matrix(err, sD)

sD = s * (1 - s) W = W + xT * err * sD

First derivative (or gradient) multiplied by error lets to move towards function minimum Calculations for all input values x at once

slide-24
SLIDE 24

Forward and Backpropagaon Learning Cycles

func main() -> int { var i = 0; for (i = 0; i < 1000; i = i + 1) { ... } }

Forward and backpropagation need to be repeated until error is low Function main as program entry point

slide-25
SLIDE 25

Results

X s(X * W) y [[ 1, 1, 1 ]] 0.96 1.00 [[ 1, 1, 0 ]] 1.00 1.00 [[ 1, 0, 1 ]] 0.00 0.00 [[ 1, 0, 0 ]] 0.05 0.00 [[ 0, 1, 1 ]] 1.00 1.00 [[ 0, 1, 0 ]] 1.00 1.00 [[ 0, 0, 1 ]] 0.05 0.00 [[ 0, 0, 0 ]] 0.50 0.00 7 correct results, 1 undecided

slide-26
SLIDE 26

Future

slide-27
SLIDE 27

Summary

Creating programming languages... is fun can teach you a lot is satisfactory

slide-28
SLIDE 28

Thank You!

slide-29
SLIDE 29

never-lang.github.io/never

Star me!

73