際際滷

際際滷Share a Scribd company logo
息 freiheit.com technologies gmbh
Clojure:
Programming self-optimizing webapps in Lisp
- Release 0.1 -
Developer Conference 2013
Hamburg, November 7th/8th 2013
息 freiheit.com technologies gmbh
Welcome, Earthlings!
 My name ist Stefan Richter
 I am a programmer, engineer and computer scientist
 I started programming in 1983 on an Apple ][ (UCSD Pascal)
 Worked in polar research, software development & consulting
 In 1999, I founded freiheit.com technologies gmbh
 We are building large-scale internet systems
 70 people. 90% programmers with a strong academic background
 We mostly use Java and JavaScript
 Today I want to show you how to have fun with Lisp (Clojure)
息 freiheit.com technologies gmbh
This is no Clojure
101 class.
息 freiheit.com technologies gmbh
There are some
really good books
about Clojure if you
want to learn the
language.
息 freiheit.com technologies gmbh
Today, I want to
show you how it
feels to work
with Lisp/Clojure.
息 freiheit.com technologies gmbh
I love...
息 freiheit.com technologies gmbh
Simple,
powerful
syntax
息 freiheit.com technologies gmbh
No state
(Almost)
息 freiheit.com technologies gmbh
Interactive
programming
息 freiheit.com technologies gmbh
Objectives of this talk
 We will learn what multi-armed bandit algorithms are
 We will write a Clojure library for the epsilon-greedy algorithm
Two approaches: Naive and idiomatic
 I will show you some nice features of the Clojure language
 We will make our library thread-safe by using agents
 And we will expose our Clojure library as a JAR-File to use it from
an ordinary Java program
So in the end youll get an idea of how you can write Lisp/Clojure
code and use it as a library from within your Java apps. ;)
息 freiheit.com technologies gmbh
Multi-armed bandit
algorithms
 Which arms on which
machines would you draw
based on the past outcome
(reward)?
 Exploration vs. exploitation
 What do you need?
 select-arm()
 update()
 algorithms: epsilon-
greedy, Softmax, UCB etc.
息 freiheit.com technologies gmbh
Epsilon: The explore frequency
息 freiheit.com technologies gmbh
First try: The naive solution
息 freiheit.com technologies gmbh
Demo-Time!
Interactive programming,
functions, sequences
(vectors), immutability or the
absence of state
息 freiheit.com technologies gmbh
Okay, whats wrong with this code?
息 freiheit.com technologies gmbh
Whats wrong with the naive implementation?
 Code must know what to expect at which vector index.
 Vector index access is diffcult to read/grasp.
 The functions have no cohesion. They are just named functions
that accidentally work together on the same datastructure, a
vector.
 How can we implement different algorithm versions that provide
the same interface functions (select-arm, update)?
 The code isnt self-explanatory. How do you should use the
functions?
息 freiheit.com technologies gmbh
Lets fix it in a
more idiomatic
way.
息 freiheit.com technologies gmbh
A protocol and a datastructure
息 freiheit.com technologies gmbh
Naive and idiomatic: Almost the same SLOCs
 Much better now. More readable and understandable.
 We are now accessing the different fields the algorithm needs by
name instead of by index.
 We defined a datastructure and implemented functions that are
working on this datastructure based on a protocol (interface).
 We can create many different implementations of the
BanditAlgorithm protocol.
 And along the way, a new Java class and interface are generated!
息 freiheit.com technologies gmbh
Demo-Time!
Interactive programming
(again), protocols and records,
sequences revisited (maps),
immutability or the absence
of state (again)
息 freiheit.com technologies gmbh
Now we need some
state and a way to
change it from
different threads.
息 freiheit.com technologies gmbh
We need
Agents!
息 freiheit.com technologies gmbh
Agents: async. shared access to mutable state
息 freiheit.com technologies gmbh
Next we wrap and
package our
Clojure code into a
Java class and JAR.
息 freiheit.com technologies gmbh
Agents: async. shared access to mutable state
息 freiheit.com technologies gmbh
Lets use it from a Java program...thread-safe.
息 freiheit.com technologies gmbh
Thank you!
Web:
http://www.freiheit.com
Twitter:
http://twitter.com/smartrevolution
GitHub:
https://github.com/smartrevolution
Google+:
https://plus.google.com/u/0/+StefanRichterSmartrevolution
息 freiheit.com technologies gmbh
息 freiheit.com technologies gmbh
Programming multi-armed bandit algorithms
in Go
- Release 0.1 -
Developer Conference 2013
Hamburg, November 7th/8th 2013
息 freiheit.com technologies gmbh
Welcome, Earthlings!
 My name ist Stefan Richter
 I am a programmer, engineer and computer scientist
 I started programming in 1983 on an Apple ][ (UCSD Pascal)
 Worked in polar research, software development & consulting
 In 1999, I founded freiheit.com technologies gmbh
 We are building large-scale internet systems
 70 people. 90% programmers with a strong academic background
 We mostly use Java and JavaScript
 Today I want to show you how to have fun with Go and in about
one hour I will show how to solve the same problem in Clojure.
息 freiheit.com technologies gmbh
Why should you
learn Golang?
息 freiheit.com technologies gmbh
Easy to learn,
highly
productiveMade by hackers, for hackers
息 freiheit.com technologies gmbh
Batteries
includedWorld-class libraries
息 freiheit.com technologies gmbh
Fast CompilerSaves time...
息 freiheit.com technologies gmbh
Testing is
part of the
platformTesting and Benchmarking
息 freiheit.com technologies gmbh
Easy to setupSuper-simple dependency-management
息 freiheit.com technologies gmbh
Easy to deployCompiles and links a single binary
息 freiheit.com technologies gmbh
Objectives of this talk
 We will learn what multi-armed bandit algorithms are
 We will write a Golang program for the epsilon-greedy algorithm
 I will show you some nice Golang features
 This prepares you for my next talk today at 1600 in Kinosaal 2
息 freiheit.com technologies gmbh
Multi-armed bandit
algorithms
 Which arms on which
machines would you draw
based on the past outcome
(reward)?
 Exploration vs. exploitation
 What do you need?
 selectArm()
 update()
 algorithms: epsilon-
greedy, Softmax, UCB etc.
息 freiheit.com technologies gmbh
Epsilon: The explore frequency
息 freiheit.com technologies gmbh
Not really trendy...
 Go is not object-oriented
 Good thing: You cant mess up your code with Enterprise
patterns... ;)
 Go doesnt support functional programming
 But you can define your own types
 And you have duck typing and interfaces
 It is like C without the bad parts
 (I think almost every language in the past 30 years was made to
fix the problems of C - and along the way new problems were
created)
息 freiheit.com technologies gmbh
An interface and a datastructure
息 freiheit.com technologies gmbh
Demo-Time!
Setup your Go-env, languages
basics, functions, structs,
visibility, build, run
息 freiheit.com technologies gmbh
Method definitions (implementing interface) I
息 freiheit.com technologies gmbh
Method definitions (implementing interface) II
息 freiheit.com technologies gmbh
Demo-Time!
Methods, for-loops,
go-routines
息 freiheit.com technologies gmbh
I hope you had
some fun!
息 freiheit.com technologies gmbh
Dont forget to visit
my Clojure talk
today at 1600/Saal5
息 freiheit.com technologies gmbh
Thank you!
Web:
http://www.freiheit.com
Twitter:
http://twitter.com/smartrevolution
GitHub:
https://github.com/smartrevolution
Google+:
https://plus.google.com/u/0/+StefanRichterSmartrevolution

More Related Content

Clojure: Programming self-optimizing webapps in Lisp

  • 1. 息 freiheit.com technologies gmbh Clojure: Programming self-optimizing webapps in Lisp - Release 0.1 - Developer Conference 2013 Hamburg, November 7th/8th 2013
  • 2. 息 freiheit.com technologies gmbh Welcome, Earthlings! My name ist Stefan Richter I am a programmer, engineer and computer scientist I started programming in 1983 on an Apple ][ (UCSD Pascal) Worked in polar research, software development & consulting In 1999, I founded freiheit.com technologies gmbh We are building large-scale internet systems 70 people. 90% programmers with a strong academic background We mostly use Java and JavaScript Today I want to show you how to have fun with Lisp (Clojure)
  • 3. 息 freiheit.com technologies gmbh This is no Clojure 101 class.
  • 4. 息 freiheit.com technologies gmbh There are some really good books about Clojure if you want to learn the language.
  • 5. 息 freiheit.com technologies gmbh Today, I want to show you how it feels to work with Lisp/Clojure.
  • 7. 息 freiheit.com technologies gmbh Simple, powerful syntax
  • 8. 息 freiheit.com technologies gmbh No state (Almost)
  • 9. 息 freiheit.com technologies gmbh Interactive programming
  • 10. 息 freiheit.com technologies gmbh Objectives of this talk We will learn what multi-armed bandit algorithms are We will write a Clojure library for the epsilon-greedy algorithm Two approaches: Naive and idiomatic I will show you some nice features of the Clojure language We will make our library thread-safe by using agents And we will expose our Clojure library as a JAR-File to use it from an ordinary Java program So in the end youll get an idea of how you can write Lisp/Clojure code and use it as a library from within your Java apps. ;)
  • 11. 息 freiheit.com technologies gmbh Multi-armed bandit algorithms Which arms on which machines would you draw based on the past outcome (reward)? Exploration vs. exploitation What do you need? select-arm() update() algorithms: epsilon- greedy, Softmax, UCB etc.
  • 12. 息 freiheit.com technologies gmbh Epsilon: The explore frequency
  • 13. 息 freiheit.com technologies gmbh First try: The naive solution
  • 14. 息 freiheit.com technologies gmbh Demo-Time! Interactive programming, functions, sequences (vectors), immutability or the absence of state
  • 15. 息 freiheit.com technologies gmbh Okay, whats wrong with this code?
  • 16. 息 freiheit.com technologies gmbh Whats wrong with the naive implementation? Code must know what to expect at which vector index. Vector index access is diffcult to read/grasp. The functions have no cohesion. They are just named functions that accidentally work together on the same datastructure, a vector. How can we implement different algorithm versions that provide the same interface functions (select-arm, update)? The code isnt self-explanatory. How do you should use the functions?
  • 17. 息 freiheit.com technologies gmbh Lets fix it in a more idiomatic way.
  • 18. 息 freiheit.com technologies gmbh A protocol and a datastructure
  • 19. 息 freiheit.com technologies gmbh Naive and idiomatic: Almost the same SLOCs Much better now. More readable and understandable. We are now accessing the different fields the algorithm needs by name instead of by index. We defined a datastructure and implemented functions that are working on this datastructure based on a protocol (interface). We can create many different implementations of the BanditAlgorithm protocol. And along the way, a new Java class and interface are generated!
  • 20. 息 freiheit.com technologies gmbh Demo-Time! Interactive programming (again), protocols and records, sequences revisited (maps), immutability or the absence of state (again)
  • 21. 息 freiheit.com technologies gmbh Now we need some state and a way to change it from different threads.
  • 22. 息 freiheit.com technologies gmbh We need Agents!
  • 23. 息 freiheit.com technologies gmbh Agents: async. shared access to mutable state
  • 24. 息 freiheit.com technologies gmbh Next we wrap and package our Clojure code into a Java class and JAR.
  • 25. 息 freiheit.com technologies gmbh Agents: async. shared access to mutable state
  • 26. 息 freiheit.com technologies gmbh Lets use it from a Java program...thread-safe.
  • 27. 息 freiheit.com technologies gmbh Thank you! Web: http://www.freiheit.com Twitter: http://twitter.com/smartrevolution GitHub: https://github.com/smartrevolution Google+: https://plus.google.com/u/0/+StefanRichterSmartrevolution
  • 29. 息 freiheit.com technologies gmbh Programming multi-armed bandit algorithms in Go - Release 0.1 - Developer Conference 2013 Hamburg, November 7th/8th 2013
  • 30. 息 freiheit.com technologies gmbh Welcome, Earthlings! My name ist Stefan Richter I am a programmer, engineer and computer scientist I started programming in 1983 on an Apple ][ (UCSD Pascal) Worked in polar research, software development & consulting In 1999, I founded freiheit.com technologies gmbh We are building large-scale internet systems 70 people. 90% programmers with a strong academic background We mostly use Java and JavaScript Today I want to show you how to have fun with Go and in about one hour I will show how to solve the same problem in Clojure.
  • 31. 息 freiheit.com technologies gmbh Why should you learn Golang?
  • 32. 息 freiheit.com technologies gmbh Easy to learn, highly productiveMade by hackers, for hackers
  • 33. 息 freiheit.com technologies gmbh Batteries includedWorld-class libraries
  • 34. 息 freiheit.com technologies gmbh Fast CompilerSaves time...
  • 35. 息 freiheit.com technologies gmbh Testing is part of the platformTesting and Benchmarking
  • 36. 息 freiheit.com technologies gmbh Easy to setupSuper-simple dependency-management
  • 37. 息 freiheit.com technologies gmbh Easy to deployCompiles and links a single binary
  • 38. 息 freiheit.com technologies gmbh Objectives of this talk We will learn what multi-armed bandit algorithms are We will write a Golang program for the epsilon-greedy algorithm I will show you some nice Golang features This prepares you for my next talk today at 1600 in Kinosaal 2
  • 39. 息 freiheit.com technologies gmbh Multi-armed bandit algorithms Which arms on which machines would you draw based on the past outcome (reward)? Exploration vs. exploitation What do you need? selectArm() update() algorithms: epsilon- greedy, Softmax, UCB etc.
  • 40. 息 freiheit.com technologies gmbh Epsilon: The explore frequency
  • 41. 息 freiheit.com technologies gmbh Not really trendy... Go is not object-oriented Good thing: You cant mess up your code with Enterprise patterns... ;) Go doesnt support functional programming But you can define your own types And you have duck typing and interfaces It is like C without the bad parts (I think almost every language in the past 30 years was made to fix the problems of C - and along the way new problems were created)
  • 42. 息 freiheit.com technologies gmbh An interface and a datastructure
  • 43. 息 freiheit.com technologies gmbh Demo-Time! Setup your Go-env, languages basics, functions, structs, visibility, build, run
  • 44. 息 freiheit.com technologies gmbh Method definitions (implementing interface) I
  • 45. 息 freiheit.com technologies gmbh Method definitions (implementing interface) II
  • 46. 息 freiheit.com technologies gmbh Demo-Time! Methods, for-loops, go-routines
  • 47. 息 freiheit.com technologies gmbh I hope you had some fun!
  • 48. 息 freiheit.com technologies gmbh Dont forget to visit my Clojure talk today at 1600/Saal5
  • 49. 息 freiheit.com technologies gmbh Thank you! Web: http://www.freiheit.com Twitter: http://twitter.com/smartrevolution GitHub: https://github.com/smartrevolution Google+: https://plus.google.com/u/0/+StefanRichterSmartrevolution