public SimpleSimultaneousGaussianProposal(double[] sigma) { this.sigma = sigma; gen = new Troschuetz.Random.Generators.MT19937Generator(); gDist = new Troschuetz.Random.Distributions.Continuous.NormalDistribution(gen, 0, 1); dim = sigma.Length; }
public SimpleSequentialGaussianProposal(double[] sigma) { this.sigma = sigma; gen = new Troschuetz.Random.Generators.MT19937Generator(); gDist = new Troschuetz.Random.Distributions.Continuous.NormalDistribution(gen, 0, 1); dim = sigma.Length; duDist = new Troschuetz.Random.Distributions.Discrete.DiscreteUniformDistribution(gen, 0, dim - 1); }
public FTildeDriver() { rnorm = new Troschuetz.Random.Distributions.Continuous.NormalDistribution(gen); }
public Annealer() { mt = new Troschuetz.Random.Generators.MT19937Generator(); uRand = new Troschuetz.Random.Distributions.Continuous.ContinuousUniformDistribution(mt); zRand = new Troschuetz.Random.Distributions.Continuous.NormalDistribution(mt); }
//private void mcmcButton_Click(object sender, RoutedEventArgs e) //{ // // initialize rng // Troschuetz.Random.Generators.MT19937Generator mt = new Troschuetz.Random.Generators.MT19937Generator(); // Troschuetz.Random.Distributions.Continuous.NormalDistribution z = new Troschuetz.Random.Distributions.Continuous.NormalDistribution(mt, 0, 1); // // make data // double alpha = 0; // double beta = 0.333; // int n = 10; // double tau = 0.1; // double[] x = new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // double[] y = new double[n]; // for (int i = 0; i < n; i++) // { // y[i] = alpha + beta * x[i] + Math.Sqrt(tau) * z.NextDouble(); // } // List<double> estimates = linearRegression(x, y); // TestStatistics ts = new TestStatistics(); // ts.LoadData(x, y); // MCMC mcmc = new MCMC(); // //SimpleSequentialGaussianProposal ssgp = new SimpleSequentialGaussianProposal(new double[] { 0.1, 0.1, 0.1 }); // //SimpleSimultaneousGaussianProposal sgp = new SimpleSimultaneousGaussianProposal(new double[] { 0.01, 0.01, 0.01 }); // SimpleSimultaneousGaussianProposal sgp = new SimpleSimultaneousGaussianProposal(new double[] { 0.01, 0.01, 0.01 }); // int burnin = 0; // int total = 1000; // mcmc.Initialize(ts.LogLikelihoodLR, ts.LogPriorLR, sgp.Proposal, 3, total, burnin); // double tauInit = Math.Log(estimates[2]); // double[] pars = new double[]{estimates[0],estimates[1],tauInit}; // mcmc.MCMCRun(pars); //} private void mcmcButton_Click(object sender, RoutedEventArgs e) { // initialize rng Troschuetz.Random.Generators.MT19937Generator mt = new Troschuetz.Random.Generators.MT19937Generator(); Troschuetz.Random.Distributions.Continuous.NormalDistribution z = new Troschuetz.Random.Distributions.Continuous.NormalDistribution(mt, 0, 1); // make data double alpha = 0; double beta = 0.333; int n = 10; double tau = 0.1; double[] x = new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; double[] y = new double[n]; for (int i = 0; i < n; i++) { y[i] = alpha + beta * x[i] + Math.Sqrt(tau) * z.NextDouble(); } List <double> estimates = linearRegression(x, y); TestStatistics ts = new TestStatistics(); ts.LoadData(x, y); double tauInit = Math.Log(estimates[2]); double[] pars = new double[] { estimates[0], estimates[1], tauInit }; int burnin = 50000; int total = 50000; // 1 parameter per auxiliary chain int numSubModels = 3; AuxiliaryChain[] submodel = new AuxiliaryChain[] { new AuxiliaryChain(), new AuxiliaryChain(), new AuxiliaryChain() }; SimpleSimultaneousGaussianProposal[] gp = new SimpleSimultaneousGaussianProposal[] { new SimpleSimultaneousGaussianProposal(new double[] { 0.01 }), new SimpleSimultaneousGaussianProposal(new double[] { 0.01 }), new SimpleSimultaneousGaussianProposal(new double[] { 0.01 }) }; ParallelHierarchicalSampler mother = new ParallelHierarchicalSampler(total, burnin, numSubModels, 3); mother.Initialize(ts.LogLikelihoodLR, ts.LogPriorLR, pars); for (int i = 0; i < numSubModels; i++) { mother.mcmc[i].Initialize(ts.LogLikelihoodLR, ts.LogPriorLR, gp[i].Proposal, new int[] { i }, mother.Mother); } ////// all 3 parameters in the auxiliary chains //int numSubModels = 3; //AuxiliaryChain[] submodel = new AuxiliaryChain[] { new AuxiliaryChain(), new AuxiliaryChain(), new AuxiliaryChain() }; //SimpleSimultaneousGaussianProposal[] gp = new SimpleSimultaneousGaussianProposal[] // { new SimpleSimultaneousGaussianProposal(new double[] { 0.01, 0.01, 0.01 }), // new SimpleSimultaneousGaussianProposal(new double[] { 0.01, 0.01, 0.01 }), // new SimpleSimultaneousGaussianProposal(new double[] { 0.01, 0.01, 0.01 }) }; //ParallelHierarchicalSampler mother = new ParallelHierarchicalSampler(total, burnin, numSubModels, 3); //mother.Initialize(ts.LogLikelihoodLR, ts.LogPriorLR, pars); //for (int i = 0; i < numSubModels; i++) //{ // mother.mcmc[i].Initialize(ts.LogLikelihoodLR, ts.LogPriorLR, gp[i].Proposal, new int[] { 0, 1, 2 }, mother.state); //} //// single chain //int numSubModels = 1; //AuxiliaryChain[] submodel = new AuxiliaryChain[] { new AuxiliaryChain() }; //SimpleSimultaneousGaussianProposal[] gp = new SimpleSimultaneousGaussianProposal[] { new SimpleSimultaneousGaussianProposal(new double[] { 0.01 }) }; //ParallelHierarchicalSampler mother = new ParallelHierarchicalSampler(total, burnin, numSubModels, 3); //mother.Initialize(ts.LogLikelihoodLR, ts.LogPriorLR, pars); //mother.mcmc[0].Initialize(ts.LogLikelihoodLR, ts.LogPriorLR, gp[0].Proposal, new int[] { 0, 1, 2 }, mother.state); mother.Run(); }