From 98dc0ab8b59f47cd2e2b3d62d2b882d40df438a1 Mon Sep 17 00:00:00 2001 From: smattis Date: Fri, 15 May 2015 15:07:12 -0500 Subject: [PATCH 1/2] updates setup.py --- bet/postProcess/plot_voronoi_probs.m | 187 --------------------------- setup.py | 9 +- 2 files changed, 6 insertions(+), 190 deletions(-) delete mode 100644 bet/postProcess/plot_voronoi_probs.m diff --git a/bet/postProcess/plot_voronoi_probs.m b/bet/postProcess/plot_voronoi_probs.m deleted file mode 100644 index cc557d62..00000000 --- a/bet/postProcess/plot_voronoi_probs.m +++ /dev/null @@ -1,187 +0,0 @@ -function plot_voronoi_probs(P_samples,samples,lam_dim,lam_domain,post_process, nbins) -% -% This makes plots of every pair of marginals (or joint in 2d case) of -% input probability measure defined by P_samples -% -% post_process - is an input that only applies to the 2d case if you want -% to see marginals on a regular grid instead of w.r.t. the Voronoi cells. -% -lam_domain = lam_domain'; -if nargin < 5 - post_process = 0; -end -if nargin == 5 - if isempty(post_process) - post_process = 0; - end -end -if nargin < 6 - nbins = 20; % number of bins in each direction -end -if nargin >= 5 - if isempty(nbins) - nbins = 20; % number of bins in each direction - end -end - -if lam_dim == 2 % Plot Voronoi tesselations, otherwise plot 2d projections/marginals of the joint inverse measure - [num_samples,~] = size(samples); - fig_num = 5; % Starting figure number - - fprintf('Plot Voronoi tesselations \n') - % Add fake samples outside of lam_domain to close Voronoi tesselations at - % infinity - midpt = mean(lam_domain); - for i=1:lam_dim - new_pt = midpt; - new_pt(i) = lam_domain(1,i)-10; - samples = [samples; new_pt]; - new_pt = midpt; - new_pt(i) = lam_domain(2,i)+10; - samples = [samples; new_pt]; - end - - indices = nchoosek(1:lam_dim,2); - - if ~post_process - % Get convex hulls for Voronoi cells in each plane of input domain - vv = []; - cc = []; - for i=1:nchoosek(lam_dim,2) - [Vor(i).vertices,Vor(i).cells]=voronoin(samples(:,indices(i,:))); - % fprintf('Length of cc = %6i \n', length(cc)) - if length(Vor(i).cells) ~= num_samples+2*lam_dim - fprintf('plot_voronoi: Houston, we have a problem \n') - return - end - end - for i=1:nchoosek(lam_dim,2) - figure(fig_num); - clf - fig_num = fig_num+1; - hold on - for l=1:length(Vor(i).cells) - if all (Vor(i).cells{l}-1 ~= 0) - patch(Vor(i).vertices(Vor(i).cells{l},1),Vor(i).vertices(Vor(i).cells{l},2),P_samples(l)); - end - end - axis([lam_domain(1,indices(i,1)) lam_domain(2,indices(i,1)) lam_domain(1,indices(i,2)) lam_domain(2,indices(i,2))]) - %title('Voronoi Tesselation colored by probability', 'FontSize', 15) - s = ['$\lambda_' int2str(indices(i,1)) '$']; - xlabel(s, 'interpreter', 'latex', 'FontSize', 15) - s = ['$\lambda_' int2str(indices(i,2)) '$']; - ylabel(s, 'interpreter', 'latex', 'FontSize', 15) - colorbar - hold off - end - else - [num_samples,~] = size(samples); - % Init the data struct holding info used for marginals - Lambda_Info = struct('bin_vals',zeros(lam_dim,nbins+1),'bin_ptr',zeros(num_samples,lam_dim)); - for k=1:lam_dim - % Compute bins in each direction - Lambda_Info.bin_vals(k,:) = linspace(lam_domain(1,k),lam_domain(2,k),nbins+1); - % Compute bin pointer for each sample - [~,Lambda_Info.bin_ptr(:,k)] = histc(samples(:,k),Lambda_Info.bin_vals(k,:)); - end - indices = nchoosek(1:lam_dim,2); - Lambda_pairs = struct('pair',struct()); - for i=1:nchoosek(lam_dim,2) % Compute marginals for each 2d pair of coordinates - Lambda_pairs.pair(i).terms = indices(i,:); - Lambda_pairs.pair(i).marginal = zeros(nbins+1,nbins+1); - end - - for i = 1:nchoosek(lam_dim,2) % Compute marginals - for j=1:num_samples - flag = 0; - k = 1; - while k Date: Fri, 15 May 2015 15:35:25 -0500 Subject: [PATCH 2/2] fixed filename issue in adaptiveSampling --- bet/sampling/adaptiveSampling.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bet/sampling/adaptiveSampling.py b/bet/sampling/adaptiveSampling.py index fe2bfeb5..90e4a554 100644 --- a/bet/sampling/adaptiveSampling.py +++ b/bet/sampling/adaptiveSampling.py @@ -277,7 +277,7 @@ def generalized_chains(self, param_min, param_max, t_set, kern, # hypercube/space-filling curve to fully explore parameter space - not # necessarily random). Call these Samples_old. (samples_old, data_old) = super(sampler, self).random_samples( - initial_sample_type, param_min, param_max, psavefile, + initial_sample_type, param_min, param_max, savefile, self.num_chains, criterion) self.num_samples = self.chain_length * self.num_chains comm.Barrier() @@ -326,8 +326,10 @@ def generalized_chains(self, param_min, param_max, t_set, kern, mdat['step_ratios'] = all_step_ratios mdat['samples'] = samples mdat['data'] = data - super(sampler, self).save(mdat, psavefile) - + if size > 1: + super(sampler, self).save(mdat, psavefile) + else: + super(sampler, self).save(mdat, savefile) MYsamples_old = samples_new # collect everything