• 検索結果がありません。

Towards abductive functional programming

N/A
N/A
Protected

Academic year: 2022

シェア "Towards abductive functional programming"

Copied!
29
0
0

読み込み中.... (全文を見る)

全文

(1)

Muroya (U. B’ham.)

Towards abductive

functional programming

Koko Muroya

Steven Cheung & Dan R. Ghica (University of Birmingham)

ML Family workshop (Oxford), 7 Sep. 2017

(2)

Parameter tuning via targeted abduction

Koko Muroya

Steven Cheung & Dan R. Ghica

(University of Birmingham)

(3)

Muroya (U. B’ham.)

A programming idiom for optimisation & ML

3

model

output input

updated model data

use model

train

model

(4)

Example: parameter optimisation in TensorFlow

model

# Build inference graph.

# Create and initialise variables W and b.

W = tf.Variable(...) b = tf.Variable(...)

y = W * x_data + b #NOTE: Nothing actually computed here!

https://www.tensorflow.org/

https://github.com/sherrym/tf-tutorial

(5)

Muroya (U. B’ham.)

5

model

output input

use model

# Create a session.

sess = tf.Session() sess.run(init)

y_initial_values = sess.run(y)

# Compute some y values

W = tf.Variable(...) b = tf.Variable(...) y = W * x_data + b

Example: parameter optimisation in TensorFlow

(6)

data model

updated model train model

# Build training graph.

loss = tf.some_loss_function(y, y_data)

# Create an operation that calculates loss.

tf.train.some_optimiser.minimize(loss)

# Create an operation that minimizes loss.

init = tf.initialize_all_variables()

# Create an operation initializes variables.

sess = tf.Session() sess.run(init)

# Perform training:

for step in range(201):

sess.run(train)

W = tf.Variable(...) b = tf.Variable(...) y = W * x_data + b

Example: parameter optimisation in TensorFlow

(7)

Muroya (U. B’ham.)

7

● shallow embedded DSL

○ lack of integration with host language

○ cannot use libraries in graphs

○ difficult to debug / type graphs

● imperative “variable” update

TensorFlow

(8)

● shallow embedded DSL

○ lack of integration with host language

○ cannot use libraries in graphs

○ difficult to debug / type graphs

● imperative parameter (“variable”) update

TensorFlow

● simple & uniform programming language

○ full integration with base language

○ typed in ML-style

○ well-defined operational semantics

● funcional parameter update

Proper functional language?

(9)

Muroya (U. B’ham.)

Key idea:

Abductive reasoning

9

(10)

● logical inference

○ deduction (specialisation)

○ induction (generalisation)

○ abduction (explanation)

● previous applications

○ abductive logic programming

○ program verification (http://fbinfer.com/)

Abductive inference: background

A

B

A ⇒ B

(11)

Muroya (U. B’ham.)

● logical inference

○ deduction (specialisation)

○ induction (generalisation)

○ abduction (explanation)

● previous applications

○ abductive logic programming

○ program verification (http://fbinfer.com/)

Abductive inference: background

11

A

B

A ⇒ B

(12)

● logical inference

○ deduction (specialisation)

○ induction (generalisation)

○ abduction (explanation)

● previous applications

○ abductive logic programming

○ program verification (http://fbinfer.com/)

Abductive inference: background

A

B

A ⇒ B

(13)

Muroya (U. B’ham.)

Abductive inference: our use

● possible deductive rule for abduction

13

“abduct” explanation P of A

in “targeted”

way

(14)

“Parameter tuning via targeted abduction”

model

output updated model

train use

let m x = {2} * x + {3};;

m 0;; let f @ p = m in

let q = optimise p in f q;;

(15)

Muroya (U. B’ham.)

“Parameter tuning via targeted abduction”

15

model

let m x = {2} * x + {3};;

provisional constants (“targets”)

cf. definitive constants

0,1,2,...

(16)

Parameter tuning via targeted abduction

model

output

use

let m x = {2} * x + {3};;

m 0;;

(* simply function application *)

provisional

constants

(17)

Muroya (U. B’ham.)

“Parameter tuning via targeted abduction”

17

model

updated model train

let m x = {2} * x + {3};;

let f @ p = m in (* “decouple” model f and parameters p *) let q = optimise p in (* compute “better” parameter values *) Let m’ = f q in (* “improve” model using new parameters *) ...

provisional constants abductive

decoupling

(18)

Abductive decoupling: informal semantics

val m = fun x -> {2} * x + {3}

model with

provisional constants

--- val f = fun (p1,p2) -> fun x -> p1 * x + p2

parameterised model

val p = (2,3)

parameter vector

let m x = {2} * x + {3};;

let f @ p = m in

let q = optimise p in f q;;

(19)

Muroya (U. B’ham.)

Abductive decoupling: informal semantics

19

val m = fun x -> {2} * x + {3}

model with

provisional constants

--- val f = fun (p1,p2) -> fun x -> p1 * x + p2

parameterised model

val p = (2,3)

parameter vector

let m x = {2} * x + {3};;

let f @ p = m in

let q = optimise p in f q;;

abduction rule

(20)

Promoting provisional to definitive constants

val m = fun x -> {2} * x + {3}

model with

provisional constants

--- val f = fun (p1,p2) -> fun x -> p1 * x + p2

parameterised model

val p = (2,3)

parameter vector

--- val q = (2,3)

(trivially updated)

parameter vector

- = fun x -> 2 * x + 3

result: model with

definitive constants

let m x = {2} * x + {3};;

let f @ p = m in let q = p in

f q;;

(21)

Muroya (U. B’ham.)

Parameter tuning via targeted abduction

21

model

output updated model

train use

let m x = {2} * x + {3};;

m 0;; let f @ p = m in

let q = optimise p in f q;;

provisional constants

abductive

decoupling

(22)

Targeted abduction: syntax & types

provisional

constant abduction

opaque vector space, representing

(fixed) field

let f@x = u in t

(abd f@x -> t) u

(23)

Muroya (U. B’ham.)

Targeted abduction: syntax & types

23

provisional

constant abduction

(fixed) field

(* abduction of open terms *) let m x = {2} * x + n in

let f @ p = m in ...

opaque vector space,

representing

(24)

● size determined dynamically

● order of coordinates unknown

○ … yet we want deterministic programs

○ always point-free (no access to bases/coordinates)

○ only symmetric operations (invariant over permutation of bases/coordinates)

Targeted abduction: opaque vectors

● possible in theory

○ symmetric tensors

● reasonable in practice

○ not all, but most, optimisation algorithms

are symmetric

(25)

Muroya (U. B’ham.)

standard vector operations

Targeted abduction: symmetric vector operations

25

iterated vector operations

(26)

Targeted abduction: example use

numerical gradient descent

let m x = {2} * x + {3};;

let f @ p = m in

let q = grad_desc f p loss 0.001 in f q;;

(* least square on some reference data *) let loss f p = ...;;

(* numerical gradient descent *) let grad_desc f p loss rate = let d = 0.001 in

let g e =

let old = loss f p in

let new = loss f (p ⊞ (d ⊠ e)) in (((old - new) / d) * rate) ⊠ e in g |⊞ p;;

folding over standard basis

(27)

Muroya (U. B’ham.)

Targeted abduction: syntax & types

27

provisional

constant abduction

opaque vector space, representing

(fixed) field

let f@x = u in t

(abd f@x -> t) u

only symmetric operations

on vectors

(28)

Targeted abduction: operational semantics

● provisional constants are linear!

● graph rewriting semantics

○ … based on Geometry of Interaction

○ http://www.cs.bham.ac.uk/~drg/goa/visualiser/

○ determinism

○ soundness of execution

○ safety of garbage-collection

○ call-by-value evaluation

let m x = {0} * x + {0};; let p = {0} in

let m x = p * x + p;;

vs

(29)

Muroya (U. B’ham.)

● a fully-integrated language for parameter tuning

○ abductive decoupling “abd”

○ simply-typed + abduction rule

○ formal operational semantics

■ call-by-value

■ determinism

■ sound execution & safe garbage-collection

● open problems

○ actual ML compiler extension

■ abduction is dynamic & complex

■ … but not computationally dominant

○ stochastical machinary

Conclusions

29

http://www.cs.bham.ac.uk/~drg/goa/visualiser/

参照

関連したドキュメント

This is the rst (or \conical") type of polar decomposition of x , and it generalizes the polar decomposition of matrices. This representation is the second type of

Theorem 1. Tarnanen uses the conjugacy scheme of the group S n in order to obtain new upper bounds for the size of a permutation code. A distance that is both left- and right-

Abstract We show that the transition matrices between the standard and the canon- ical bases of infinitely many weight subspaces of the higher-level q -deformed Fock spaces are

§ 10. Top corner of the triangle: regular systems of weights We start anew by introducing the concept of a regular system of weights. in the next section. This view point

In my earlier paper [H07] and in my talk at the workshop on “Arithmetic Algebraic Geometry” at RIMS in September 2006, we made explicit a conjec- tural formula of the L -invariant

We shall finally point out two examples of functions V and F which lead to the convergence of any sequence of symmetric self-stabilizing invariant measures towards a limit measure

Hence similar calculations of the prepolarization as in Section 5 will give a proof of the existence of crystal bases for KR modules of other quantum affine algebras..

The question posed after Theorem 2.1, whether there are 2 ℵ 0 closed permutation classes with counting functions mutually incomparable by the eventual dominance, has a positive