Skip to content

Commit 853f4cc

Browse files
committed
Gaaah, fixed a bug. A minor one, but still a big.
For our test, we shouldn't have \psi(u,...), it should be \psi(1,...) because the u is not providing us random-ness. It's the minibatch variation that's providing randomness. I re-ran figures that were affected. Fortunately for that problem, results are similar.
1 parent 1595e69 commit 853f4cc

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

scripts/analyze_mhtest_logreg.ssc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
// Double-check these.
20-
val total = 5000
20+
val total = 3000
2121
val datadir = "mhtest_analysis/data_mhtest/"
2222

2323
// On stout OR bitter:

scripts/test_mh.ssc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* random-ness!!
2525
*/
2626

27-
val seed = 4
27+
val seed = 69
2828
println("Our seed: " +seed)
2929
setseed(seed)
3030

@@ -94,7 +94,7 @@ mopts.verboseMH = false
9494
mopts.collectData = true // CAUTION! May save a lot!
9595
mopts.collectDataDir = "mhtest_analysis/data_mhtest/" // Clear this directory
9696
mopts.exitTheta = true // breaks out of program ...
97-
mopts.exitThetaAmount = 5000 // means we collect this many thetas
97+
mopts.exitThetaAmount = 3000 // means we collect this many thetas
9898
mopts.initThetaHere = true // break symmetry at the start
9999
mopts.burnIn = -1 // change stuff after this sample (set to -1 to ignore)
100100
mopts.tempAfterBurnin = 1 // after burn-in, change temp to this

src/main/scala/BIDMach/updaters/MHTest.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import edu.berkeley.bid.CUMACH
2121
*
2222
* - In particular, we need \Delta* and Var(\Delta*). Since \Delta* is of the form:
2323
*
24-
* \Delta* = - log(u) + (1/b)\sum_{i=1}^b Y_i
24+
* \Delta* = -\psi + (1/b)\sum_{i=1}^b Y_i
2525
*
2626
* for IID random variables Y_i, which represent a log of a probability ratio,
2727
* it suffices to compute the statistics as follows:
@@ -61,7 +61,7 @@ class MHTest(override val opts:MHTest.Opts = new MHTest.Options) extends Updater
6161
var b:Long = 0 // Current minibatch size (also `b` in the paper).
6262
var N:Long = 0 // Maximum minibatch size (i.e. all training data).
6363
var n:Float = 0f // The *number* of minibatches we are using.
64-
var logu:Float = 0f // log u, since we assume a symmetric proposer.
64+
var psi:Float = 0f // \psi = log (1 * prop_ratio * prior_ratio)
6565
var T:Int = 1 // The temperature of the distribution.
6666
var t:Int = 0 // Current number of samples of theta.
6767
var sumOfValues:Float = 0f // \sum_{i=1}^b (N/T)*log(p(x_i|theta')/p(x_i|theta)).
@@ -148,7 +148,7 @@ class MHTest(override val opts:MHTest.Opts = new MHTest.Options) extends Updater
148148
// (Part 2) Update our \Delta* and sample variance of \Delta*.
149149
sumOfSquares += sum((diff)*@(diff)).v
150150
sumOfValues += sum(diff).v
151-
val deltaStar = sumOfValues/b.v - logu
151+
val deltaStar = sumOfValues/b.v - psi
152152
val sampleVariance = (sumOfSquares/b.v - ((sumOfValues/b.v)*(sumOfValues/b.v))) / b.v
153153
val numStd = deltaStar / math.sqrt(sampleVariance)
154154
var accept = false
@@ -221,7 +221,7 @@ class MHTest(override val opts:MHTest.Opts = new MHTest.Options) extends Updater
221221
def beforeEachMinibatch() {
222222
if (opts.verboseMH) println("\n\tNew minibatch!")
223223
randomWalkProposer()
224-
logu = ln(rand(1,1)).v
224+
psi = ln(1).v // WARNING, symmetric proposals ONLY, since \psi(1,\theta,theta')=0.
225225
newMinibatch = false
226226
b = 0
227227
n = 0
@@ -313,7 +313,7 @@ class MHTest(override val opts:MHTest.Opts = new MHTest.Options) extends Updater
313313

314314
/** This is for debugging. */
315315
def debugPrints(sampleVariance:Float, deltaStar:Float) {
316-
println("b="+b+", n="+n+", logu="+logu+ ", b-mbSize="+(b - model.datasource.opts.batchSize).toInt)
316+
println("b="+b+", n="+n+", psi="+psi+ ", b-mbSize="+(b - model.datasource.opts.batchSize).toInt)
317317
println("mean(scores0) = "+mean(scores0,2).dv+", mean(scores1) = "+mean(scores1,2).dv)
318318
println("sampleVar = " +sampleVariance)
319319
println("delta* = " + deltaStar)

0 commit comments

Comments
 (0)