From 296c7cc2082557db4a82b4a1208986c6e93ad935 Mon Sep 17 00:00:00 2001 From: "trevor.cohn" Date: Fri, 9 Jul 2010 22:29:02 +0000 Subject: Added initial VB implementation for symetric Dirichlet prior. git-svn-id: https://ws10smt.googlecode.com/svn/trunk@215 ec762483-ff6d-05da-a07a-a48fb63a330f --- gi/posterior-regularisation/prjava/src/arr/F.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'gi/posterior-regularisation/prjava/src/arr/F.java') diff --git a/gi/posterior-regularisation/prjava/src/arr/F.java b/gi/posterior-regularisation/prjava/src/arr/F.java index 7f2b140a..54dadeac 100644 --- a/gi/posterior-regularisation/prjava/src/arr/F.java +++ b/gi/posterior-regularisation/prjava/src/arr/F.java @@ -4,18 +4,25 @@ import java.util.Random; public class F { public static Random rng = new Random(); - + public static void randomise(double probs[]) + { + randomise(probs, true); + } + + public static void randomise(double probs[], boolean normalise) { double z = 0; for (int i = 0; i < probs.length; ++i) { probs[i] = 3 + rng.nextDouble(); - z += probs[i]; + if (normalise) + z += probs[i]; } - for (int i = 0; i < probs.length; ++i) - probs[i] /= z; + if (normalise) + for (int i = 0; i < probs.length; ++i) + probs[i] /= z; } public static void l1normalize(double [] a){ -- cgit v1.2.3