package blang.engines.internals.factories;

import org.eclipse.xtext.xbase.lib.Pair;

import bayonet.distributions.Random;
import blang.engines.internals.PosteriorInferenceEngine;
import blang.inits.Arg;
import blang.inits.DefaultValue;
import blang.inits.GlobalArg;
import blang.inits.experiments.ExperimentResults;
import blang.io.BlangTidySerializer;
import blang.runtime.Runner;
import blang.runtime.SampledModel;
import blang.runtime.internals.objectgraph.GraphAnalysis;

public class Forward implements PosteriorInferenceEngine
{
  @Arg               @DefaultValue("1")
  public Random random = new Random(1);
  
  @Arg   @DefaultValue("1")
  public int nSamples = 1;
  
  @GlobalArg ExperimentResults results;
  
  SampledModel model;

  @Override
  public void setSampledModel(SampledModel model) 
  {
    this.model = model;
  }

  @SuppressWarnings("unchecked")
  @Override
  public void performInference() 
  {
    BlangTidySerializer tidySerializer = new BlangTidySerializer(results.child(Runner.SAMPLES_FOLDER));
    for (int i = 0; i < nSamples; i++) 
    {
      model.forwardSample(random, false);
      model.getSampleWriter(tidySerializer).write(Pair.of(Runner.sampleColumn, i)); 
    }
  }

  @Override
  public void check(GraphAnalysis analysis) 
  {
  }
}

@@ -41,49 +41,8 @@
 s;%0A%0A
-import org.eclipse.xtext.xbase.lib.Pair;%0A
 %0Aimp
@@ -575,66 +575,8 @@
 %0A  %0A
-  @Arg   @DefaultValue(%221%22)%0A  public int nSamples = 1;%0A  %0A
   @G
@@ -924,56 +924,8 @@
 ));%0A
-    for (int i = 0; i %3C nSamples; i++) %0A    %7B%0A  
     
@@ -956,18 +956,15 @@
 om, 
-fals
+tru
 e);%0A
-  
     
@@ -1011,48 +1011,10 @@
 ite(
-Pair.of(Runner.sampleColumn, i)); %0A    %7D
+);
 %0A  %7D

Remove extra stringent check in Forward, remove multi-sample