annotate src/samer/models/#Model.java# @ 3:15b93db27c04

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