Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmalleson committed Oct 18, 2018
2 parents ff566f7 + ab33885 commit 7e702de
Show file tree
Hide file tree
Showing 4 changed files with 2,069 additions and 10,037 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,12 @@ public class SimpleModel {
private ArrayList<Integer> history = new ArrayList<Integer>();
private static int modelCount = 0 ; // Count the number of models that are created (just for info)

private ArrayList<Double> randomNumbers ; // TEMPORARY (while we can't get the random numbers from keanu)


/* Constructors */

public SimpleModel(double threshold, RandomGenerator random ) {
SimpleModel.modelCount++;
this.threshold = threshold;
this.random = random;
this.randomNumbers = new ArrayList<Double>();
for (int i=0; i<SimpleWrapper.NUM_RAND_DOUBLES; i++) {
this.randomNumbers.add(this.random.nextDouble());
}
//System.out.println("SimpleModel contstuctor: "+SimpleModel.modelCount++ + ". Threshold: "+threshold
// +". Random numbers: "+this.randomNumbers.toString());
}
Expand All @@ -44,7 +37,7 @@ public SimpleModel(double threshold, RandomGenerator random ) {
*/
public void step() {
//this.counter = this.random.nextDouble() > this.threshold ? this.counter+1 : this.counter-1;
if (this.random.nextDouble() > this.threshold) {
if (this.random.nextGaussian() > this.threshold) {
this.counter = this.counter+1;
}
else {
Expand All @@ -71,10 +64,6 @@ public void printHistory() {
System.out.println();
}

public List<Double> getRandomNumbers() {
return this.randomNumbers;
}

public static int getNumModelsCreated() {
return SimpleModel.modelCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
public class SimpleWrapper {

/* Model parameters */
private static final double threshold = 0.5;
public static final int NUM_RAND_DOUBLES = 10;
private static final int NUM_ITER = 100;
private static final double threshold = 0.0;
public static final int NUM_RAND_DOUBLES = 50;
private static final int NUM_ITER = 10000;

/* Hyperparameters */
private static final double SIGMA_NOISE = 0.1;
Expand Down Expand Up @@ -80,7 +80,7 @@ public static void run() {

// Store the random numbers used (for comparison later)
List<Double> truthRandomNumbers = new ArrayList<>(NUM_RAND_DOUBLES);
for (int i=0; i<NUM_RAND_DOUBLES; i++) truthRandomNumbers.add(truthRandom.nextDouble());
for (int i=0; i<NUM_RAND_DOUBLES; i++) truthRandomNumbers.add(truthRandom.nextGaussian());

// Run the model
Integer[] truth = SimpleWrapper.runModel(truthRandom);
Expand All @@ -89,8 +89,7 @@ public static void run() {
System.out.println("Truth data: "+Arrays.asList(truth).toString() + "\n\n");
System.out.println("Truth random numbers:");
System.out.println(truthRandomNumbers.toString());

(new ArrayList<String>(NUM_RAND_DOUBLES)).forEach(i -> System.out.print(truthRandom.nextDouble()+", "));
(new ArrayList<String>(NUM_RAND_DOUBLES)).forEach(i -> System.out.print(truthRandom.nextGaussian()+", "));
System.out.println();


Expand Down Expand Up @@ -164,6 +163,23 @@ public static void run() {
parameters, // The vertices to include in the returned samples
NUM_SAMPLES); // The number of samples

// Sample using a stream.
/*
NetworkSamples sampler = MetropolisHastings.generatePosteriorSamples(
net, // The bayes net with latent variables (the random numbers?)
parameters // The vertices to include in the returned samples
)
.dropCount(DROP_SAMPLES)
.downSampleInterval(DOWN_SAMPLE)
.stream()
.limit(NUM_SAMPLES)
.map(networkState -> {
for()
networkState.get(x)
})
.average().getAsDouble();
*/

System.out.println("Finished running MCMC.");

// Downsample etc
Expand Down
21 changes: 18 additions & 3 deletions results/simple/ResultsSummary-Simple.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if (length(samples.files) != length(rands.files)) {
This is weird so I'm not continuing.")
}
if (length(samples.files) != 1) {
if (length(samples.files) != 1) {ç
message("Found multiple samples files. Using the most recent one.")
samples.files <- samples.files[-1]
rand.files <- rand.files[-1]
Expand Down Expand Up @@ -130,9 +130,24 @@ density_plot(samples, truth.results)

# Plot random numbers

XXXX Look at how the random numbers changed
Look at how the random numbers changed.

_(For now just make a table)_
Start with a histogram.

```{r randPosterior, fig.width=15, fig.height=15}
par(mfrow=c(ncol(rands)/3, 3))
i <- 1
for (column in names(rands)) {
#print(column)
hist(rands[,column][[1]], xlim=c(-3,3))
abline(v=truth.rands[i[[1]]], col="red")
abline(v=0.0, col="blue", lty="dashed")
i <- i + 1
}
# XXXX Add vertical lines showing where the true values rae
```

## 'True' random numbers

Expand Down
12,044 changes: 2,028 additions & 10,016 deletions results/simple/ResultsSummary-Simple.html

Large diffs are not rendered by default.

0 comments on commit 7e702de

Please sign in to comment.