|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.knowceans.dirichlet.dmm.DmmGibbsSampler
public class DmmGibbsSampler
DmmGibbsSampler implements a simple Gibbs sampler that simulates the posterior of a Dirichlet mixture model. It uses a fixed point iteration to estimate the component parameters.
We sample the originating component / component of each observation and assign observation to the component, re-estimating the component statistics.
TODO: increase estimation accuracy, e.g., by using Newton-Raphson instead of fixed-point estimator for component precisions. TODO: fix for very small data sets.
TODO: fix NaN and Inf behaviour for small data sets.
| Field Summary | |
|---|---|
private int[] |
component
Component assignment of each data item. |
private int[] |
counts
|
(package private) double[][] |
data
|
private boolean |
fullPrecEst
use moment-based guess or full estimation (fixed point iteration). |
private int |
iterations
max iterations |
private int |
K
Dimensionality of the data |
private int |
L
Number of components. |
private double[][] |
means
Componentwise sum mean of all data samples. dim = components x data dimension. |
private double[][] |
meansq
Componentwise meansq of the sqares of all data samples. dim = components x data dimension. |
private double |
minComponent
minimum members of a component |
private int |
N
Length of the data |
private double[] |
precs
Component precisions |
private double[] |
probs
Component probabilities |
private double[][] |
suffstats
Componentwise sufficient statistics for alpha * N. dim = components x data dimension. |
| Constructor Summary | |
|---|---|
DmmGibbsSampler(double[][] data)
Initialise the Gibbs sampler with data. |
|
| Method Summary | |
|---|---|
(package private) void |
addObservation(double[] x,
int comp)
For updating mixture parameters |
void |
configure(int iterations,
int minComponent,
boolean fullPrecision)
Configure the Gibbs sampler. |
int[] |
getComponent()
Get the data-component associations. |
double[][] |
getMeans()
Calculates the means from the component sums and returns. |
double[] |
getPrecs()
Get the component precisions |
double[] |
getProbs()
Get the component weights. |
private void |
gibbs(int L)
Main method: Select initial state ? |
(package private) void |
initialState(int L)
Initialisation: random assignments with equal probabilities. |
static void |
main(java.lang.String[] args)
Driver with example data. |
(package private) void |
removeObservation(double[] x,
int comp)
For updating mixture parameters |
(package private) int |
sampleComponent(double[] x)
Sampling a component, P(z_j=i | x_j, theta) = pi_i * f(x_j | theta_j) / sum_m pi_m f(x_j | theta_m) Calculate the probability that the observation originated from each component. |
(package private) void |
updateParams()
Update the parameters. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
double[][] data
private int[] counts
private double[][] means
private double[][] meansq
private double[][] suffstats
private int[] component
private double[] probs
private double[] precs
private int L
private int N
private int K
private boolean fullPrecEst
private double minComponent
private int iterations
| Constructor Detail |
|---|
public DmmGibbsSampler(double[][] data)
data - | Method Detail |
|---|
public static void main(java.lang.String[] args)
args - void updateParams()
int sampleComponent(double[] x)
Calculate the probability that the observation originated from each component. Use random number(s) to assign component membership.
x - data itemL - number of componentsprobs - means - precs -
void addObservation(double[] x,
int comp)
x - comp -
void removeObservation(double[] x,
int comp)
x - comp - void initialState(int L)
L - private void gibbs(int L)
L - number of components
public void configure(int iterations,
int minComponent,
boolean fullPrecision)
iterations - minComponent - fullPrecision - public final int[] getComponent()
public final double[] getPrecs()
public final double[] getProbs()
public final double[][] getMeans()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||