comparison src/samer/models/#Model.java# @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 /*
2 * Copyright (c) 2002, Samer Abdallah, King's College London.
3 * All rights reserved.
4 *
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
6 * without even the implied warranty of MERCHANTABILITY or
7 * FITNESS FOR A PARTICULAR PURPOSE.
8 */
9
10 package samer.models;
11
12 import samer.core.*;
13 import samer.maths.*;
14 import samer.maths.opt.*;
15 import samer.tools.*;
16
17 public interface Model
18 {
19 /** return size of vector this model expects */
20 int getSize();
21
22 /** model should begin observing this vector */
23 void setInput(Vec x);
24
25 /** should infer values latent variables */
26 void infer();
27
28 /**
29 contract is that getEnergy and getGradient
30 must return correct values for current x after
31 infer and compute has been called, but not necessarily
32 before.
33
34 :q
35
36 This is to give model an opportunity to
37 cache values of energy and gradient to avoid repeated
38 computations.
39 */
40 void compute();
41
42 /** return E = -log p(x) */
43 double getEnergy();
44
45 /** return dE/dx */
46 double [] getGradient();
47
48 public void dispose();
49
50 /** This presents a more functional interface to the model
51 so that it can be driven by an optimiser. See classes
52 Functionx and MinimiserBase in package samer.maths.opt. */
53
54 public Functionx functionx();
55
56 /** This represents a training algorithm for a Model
57 Trainer is responsible for counting calls to accumulate()
58 between flushes
59 */
60
61 public interface Trainer {
62 /** collect statistics for parameter update */
63 public void accumulate();
64
65 /** weighted accumulate */
66 public void accumulate(double w);
67
68 /** use collected stats to update parameters and reset */
69 public void flush();
70
71 /** Must be equivalent to reset(); accumulate(); flush();
72 but can be optimised for non-batched training */
73 public void oneshot();
74
75 /** reset accumulators without updating parameters */
76 public void reset();
77
78 public void dispose();
79 }
80 }
81