-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
192 lines (164 loc) · 9.57 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html>
<html class="nojs" lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes">
<title>Infergo — Go programs that learn</title>
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://infergo.org/index.xml">
<meta name="created" content="2021-07-11T18:07:04+0300">
<meta name="modified" content="2021-07-11T18:07:04+0300">
<meta name="author" content="David Tolpin">
<meta name="description" content="">
<meta property="og:site_name" content="Infergo — Go programs that learn">
<meta property="og:title" content="Home">
<meta property="og:url" content="http://infergo.org/">
<meta name="generator" content="Hugo 0.85.0" />
<link rel="canonical" href="http://infergo.org/">
<link rel="icon" href="/favicon.png">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="stylesheet" href="/css/styles.css">
<link rel="stylesheet" href="/css/print.css" media="print">
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"url" : "http:\/\/infergo.org\/",
"name": "\"Home\"",
"author": {
"@type": "Person",
"name": "\"David Tolpin\""
},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "http:\/\/infergo.org\/"
},
"publisher": {
"@type": "Organization",
"name": "\"Infergo — Go programs that learn\"",
"url": "http:\/\/infergo.org\/",
}
</script>
</head>
<body>
<div class="page layout__page layout__sidebar-second">
<header class="header layout__header" role="banner">
<h1 class="header__site-name">
<a href="/" title="Home" rel="home" class="header__logo"><img src="/images/logo.png" alt="Home" class="header__logo-image"></a>
<a href="/" title="Home" class="header__site-link" rel="home"><span>Infergo — Go programs that learn</span></a>
</h1>
<div class="region header__region">
</div>
</header>
<nav class="main-menu layout__navigation" role="navigation">
<h2 class="visually-hidden">Main menu</h2>
<ul class="navbar">
<li><a class="active" href="/">Home</a></li>
<li><a class="" href="/start/">Getting started</a></li>
<li><a class="" href="/guide/">Guide</a></li>
<li><a class="" href="/examples/">Examples</a></li>
<li><a class="" href="/team/">Team</a></li>
<li><a class="" href="/peers/">Peers</a></li>
<li><a class="" href="/news/">News</a></li>
</ul>
</nav>
<main class="main layout__main" role="main">
<article class="single-view">
<div class="content">
<p><a href="http://bitbucket.org/dtolpin/infergo"><code>Infergo</code></a> is a probabilistic
programming facility for the <a href="http://golang.org/">Go language</a>.
<code>infergo</code> allows to write probabilistic models in almost
unrestricted Go and relies on <a href="https://en.wikipedia.org/wiki/Automatic_differentiation">automatic
differentiation</a>
for optimization and inference. Works anywhere where Go does.
Hosted on <a href="https://bitbucket.org/dtolpin/infergo">Bitbucket</a>.
Licensed under the <a href="https://opensource.org/licenses/MIT">MIT license</a>.</p>
<h2 id="example">Example</h2>
<p><a href="examples">more examples</a></p>
<p>Learning parameters of the Normal distribution from
observations:</p>
<h3 id="model">Model</h3>
<div class="highlight"><pre style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#007020;font-weight:bold">type</span> Model <span style="color:#007020;font-weight:bold">struct</span> {
Data []<span style="color:#902000">float64</span>
}
<span style="color:#60a0b0;font-style:italic">// x[0] is the mean, x[1] is the log stddev of the distribution
</span><span style="color:#60a0b0;font-style:italic"></span><span style="color:#007020;font-weight:bold">func</span> (m <span style="color:#666">*</span>Model) <span style="color:#06287e">Observe</span>(x []<span style="color:#902000">float64</span>) <span style="color:#902000">float64</span> {
<span style="color:#60a0b0;font-style:italic">// Our prior is a unit normal ...
</span><span style="color:#60a0b0;font-style:italic"></span> ll <span style="color:#666">:=</span> Normal.<span style="color:#06287e">Logps</span>(<span style="color:#40a070">0</span>, <span style="color:#40a070">1</span>, x<span style="color:#666">...</span>)
<span style="color:#60a0b0;font-style:italic">// ... but the posterior is based on data observations.
</span><span style="color:#60a0b0;font-style:italic"></span> ll <span style="color:#666">+=</span> Normal.<span style="color:#06287e">Logps</span>(x[<span style="color:#40a070">0</span>], math.<span style="color:#06287e">Exp</span>(x[<span style="color:#40a070">1</span>]), m.Data<span style="color:#666">...</span>)
<span style="color:#007020;font-weight:bold">return</span> ll
}</code></pre></div>
<h3 id="inference">Inference</h3>
<div class="highlight"><pre style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#60a0b0;font-style:italic">// Data
</span><span style="color:#60a0b0;font-style:italic"></span>m <span style="color:#666">:=</span> <span style="color:#666">&</span>Model{[]<span style="color:#902000">float64</span>{
<span style="color:#666">-</span><span style="color:#40a070">0.854</span>, <span style="color:#40a070">1.067</span>, <span style="color:#666">-</span><span style="color:#40a070">1.220</span>, <span style="color:#40a070">0.818</span>, <span style="color:#666">-</span><span style="color:#40a070">0.749</span>,
<span style="color:#40a070">0.805</span>, <span style="color:#40a070">1.443</span>, <span style="color:#40a070">1.069</span>, <span style="color:#40a070">1.426</span>, <span style="color:#40a070">0.308</span>}}
<span style="color:#60a0b0;font-style:italic">// Parameters
</span><span style="color:#60a0b0;font-style:italic"></span>mean, logs <span style="color:#666">:=</span> <span style="color:#40a070">0</span>, <span style="color:#40a070">0</span>
x <span style="color:#666">:=</span> []<span style="color:#902000">float64</span>{mean, logs}
<span style="color:#60a0b0;font-style:italic">// Optimization
</span><span style="color:#60a0b0;font-style:italic"></span>opt <span style="color:#666">:=</span> <span style="color:#666">&</span>infer.Momentum{
Rate: <span style="color:#40a070">0.01</span>,
Decay: <span style="color:#40a070">0.998</span>,
}
<span style="color:#007020;font-weight:bold">for</span> iter <span style="color:#666">:=</span> <span style="color:#40a070">0</span>; iter <span style="color:#666">!=</span> <span style="color:#40a070">1000</span>; iter<span style="color:#666">++</span> {
opt.<span style="color:#06287e">Step</span>(m, x)
}
mean, logs = x[<span style="color:#40a070">0</span>], x[<span style="color:#40a070">1</span>]
<span style="color:#60a0b0;font-style:italic">// Posterior
</span><span style="color:#60a0b0;font-style:italic"></span>hmc <span style="color:#666">:=</span> <span style="color:#666">&</span>infer.HMC{
Eps: <span style="color:#40a070">0.1</span>,
}
samples <span style="color:#666">:=</span> <span style="color:#007020">make</span>(<span style="color:#007020;font-weight:bold">chan</span> []<span style="color:#902000">float64</span>)
hmc.<span style="color:#06287e">Sample</span>(m, x, samples)
<span style="color:#007020;font-weight:bold">for</span> i <span style="color:#666">:=</span> <span style="color:#40a070">0</span>; i <span style="color:#666">!=</span> <span style="color:#40a070">1000</span>; i<span style="color:#666">++</span> {
x = <span style="color:#666"><-</span>samples
}
hmc.<span style="color:#06287e">Stop</span>()</code></pre></div>
<h2 id="acknowledgements">Acknowledgements</h2>
<p>I owe a debt of gratitude to <a href="https://www.cs.ubc.ca/~fwood/">Frank
Wood</a> who introduced me to
probabilistic programming and inspired me to pursue
probabilistic programming paradigms and applications. I also
want to thank <a href="http://www.ccs.neu.edu/home/jwvdm/">Jan-Willem van de
Meent</a>, with whom I had
fruitful discussions of motives, ideas, and implementation
choices behind <code>infergo</code>, and whose thoughts and recommendations
significantly influenced <code>infergo</code> design. Finally, I want to
thank <a href="http://pubplus.com/">PUB+</a>, the company I work for, for
supporting me in development of <code>infergo</code> and letting me
experiment with applying probabilistic programming to critical
decision-making in production environment.</p>
</div>
</article>
</main>
<aside class="sidebar layout__second-sidebar" role="complementary">
<section>
<h4 class="menu"><a class="" href="/peers/">Peers</a></h4>
<ul class="menu">
<li><a class="" href="/peers/gogp/">GoGP</a></li>
</ul>
</section>
<section>
<h4 class="menu"><a class="" href="/news/">News</a></h4>
<ul class="menu">
<li><a class="" href="/news/gogp-v1.0.1/">gogp v1.0.1</a></li>
<li><a class="" href="/news/v1.0.1/">infergo v1.0.1</a></li>
<li><a class="" href="/news/gogp/">gogp v0.1.0</a></li>
<li><a class="" href="/news/v0.7.0/">infergo v0.7.0</a></li>
<li><a class="" href="/news/v0.6.1/">infergo v0.6.1</a></li>
<li><a class="" href="/news/v0.5.0/">infergo v0.5.0</a></li>
<li><a class="" href="/news/tale-of-goids/">The Tale of GoIDs</a></li>
<li><a class="" href="/news/v0.3.0/">infergo v0.3.0</a></li>
<li><a class="" href="/news/v0.2.2/">infergo v0.2.2</a></li>
<li><a class="" href="/news/v0.2.1/">infergo v0.2.1</a></li>
<li><a class="" href="/news/why/">Why infergo</a></li>
</ul>
</section>
</aside>
<footer class="footer layout__footer" role="contentinfo">
<p><span>© Infergo — Go programs that learn</span></p>
</footer>
</div>
</body>
</html>