-
Notifications
You must be signed in to change notification settings - Fork 0
Add rev11: pre-generate MC RNG, preserve azimuth chunking, and add validator/benchmark #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nicklasorte
wants to merge
1
commit into
main
Choose a base branch
from
codex/create-subchunk_agg_check_maxazi_rev11-implementation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| function results=benchmark_subchunk_agg_check_maxazi_rev11_chunk_sweep(app,cell_aas_dist_data,array_bs_azi_data,radar_beamwidth,min_azimuth,max_azimuth,base_protection_pts,point_idx,on_list_bs,cell_sim_chunk_idx,rand_seed1,agg_check_reliability,on_full_Pr_dBm,clutter_loss,custom_antenna_pattern,sub_point_idx,varargin) | ||
| %BENCHMARK_SUBCHUNK_AGG_CHECK_MAXAZI_REV11_CHUNK_SWEEP | ||
| % Runtime sweep for rev11 AZI_CHUNK tuning. | ||
| % | ||
| % Optional name/value: | ||
| % 'ChunkValues' (default [64 128 256 512]) | ||
| % 'NumTrials' (default 3) | ||
|
|
||
| opts=parse_inputs(varargin{:}); | ||
|
|
||
| if exist('subchunk_agg_check_maxazi_rev11','file')~=2 | ||
| error('benchmark_subchunk_agg_check_maxazi_rev11_chunk_sweep:MissingRev11', ... | ||
| 'subchunk_agg_check_maxazi_rev11.m was not found on MATLAB path.'); | ||
| end | ||
|
|
||
| chunk_values=opts.ChunkValues(:).'; | ||
| num_chunks=numel(chunk_values); | ||
| runtime_trials=NaN(num_chunks,opts.NumTrials); | ||
|
|
||
| fprintf('\n=== rev11 AZI_CHUNK sweep benchmark ===\n'); | ||
| fprintf('Chunk values: %s\n',mat2str(chunk_values)); | ||
| fprintf('Trials per chunk: %d\n',opts.NumTrials); | ||
|
|
||
| for c=1:1:num_chunks | ||
| azi_chunk=chunk_values(c); | ||
| for t=1:1:opts.NumTrials | ||
| run_tic=tic; | ||
| subchunk_agg_check_maxazi_rev11(app,cell_aas_dist_data,array_bs_azi_data, ... | ||
| radar_beamwidth,min_azimuth,max_azimuth,base_protection_pts,point_idx,on_list_bs, ... | ||
| cell_sim_chunk_idx,rand_seed1,agg_check_reliability,on_full_Pr_dBm,clutter_loss, ... | ||
| custom_antenna_pattern,sub_point_idx,azi_chunk); | ||
| runtime_trials(c,t)=toc(run_tic); | ||
| end | ||
| end | ||
|
|
||
| runtime_median=median(runtime_trials,2,'omitnan'); | ||
| runtime_mean=mean(runtime_trials,2,'omitnan'); | ||
| runtime_min=min(runtime_trials,[],2,'omitnan'); | ||
|
|
||
| [best_runtime,best_idx]=min(runtime_median); | ||
| best_chunk=chunk_values(best_idx); | ||
|
|
||
| fprintf('\nSummary table (seconds):\n'); | ||
| fprintf(' AZI_CHUNK | median | mean | min\n'); | ||
| for c=1:1:num_chunks | ||
| fprintf(' %9d | %8.4f | %8.4f | %8.4f\n',chunk_values(c),runtime_median(c),runtime_mean(c),runtime_min(c)); | ||
| end | ||
| fprintf('\nRecommended AZI_CHUNK: %d (median runtime %.4f s)\n',best_chunk,best_runtime); | ||
|
|
||
| results=struct(); | ||
| results.chunk_values=chunk_values; | ||
| results.runtime_trials_s=runtime_trials; | ||
| results.runtime_median_s=runtime_median; | ||
| results.runtime_mean_s=runtime_mean; | ||
| results.runtime_min_s=runtime_min; | ||
| results.best_chunk=best_chunk; | ||
| results.best_runtime_median_s=best_runtime; | ||
|
|
||
| end | ||
|
|
||
| function opts=parse_inputs(varargin) | ||
| opts=struct(); | ||
| opts.ChunkValues=[64 128 256 512]; | ||
| opts.NumTrials=3; | ||
|
|
||
| if mod(numel(varargin),2)~=0 | ||
| error('Optional arguments must be name/value pairs.'); | ||
| end | ||
|
|
||
| for i=1:2:numel(varargin) | ||
| name=varargin{i}; | ||
| value=varargin{i+1}; | ||
| switch lower(string(name)) | ||
| case "chunkvalues" | ||
| opts.ChunkValues=unique(max(1,round(value(:).')),'stable'); | ||
| case "numtrials" | ||
| opts.NumTrials=max(1,round(value)); | ||
| otherwise | ||
| error('Unknown option: %s',name); | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| function [sub_array_agg_check_mc_dBm]=subchunk_agg_check_maxazi_rev11(app,cell_aas_dist_data,array_bs_azi_data,radar_beamwidth,min_azimuth,max_azimuth,base_protection_pts,point_idx,on_list_bs,cell_sim_chunk_idx,rand_seed1,agg_check_reliability,on_full_Pr_dBm,clutter_loss,custom_antenna_pattern,sub_point_idx,varargin) | ||
| %SUBCHUNK_AGG_CHECK_MAXAZI_REV11 Monte Carlo aggregate check with tunable azimuth chunking. | ||
| % rev11 goals: | ||
| % 1) remove per-iteration RNG reseeding overhead; | ||
| % 2) keep azimuth chunking as a memory/performance tuning knob; | ||
| % 3) preserve rev9/rev10 output contract (max aggregate dBm over sim azimuth). | ||
|
|
||
| % Tuning knob: larger chunks can improve compute throughput but may increase peak memory. | ||
| AZI_CHUNK_DEFAULT=128; | ||
| DEBUG_CHECKS=false; | ||
| azi_chunk=AZI_CHUNK_DEFAULT; | ||
| if ~isempty(varargin) | ||
| azi_chunk=varargin{1}; | ||
| end | ||
| azi_chunk=max(1,round(azi_chunk)); | ||
|
|
||
| array_aas_dist_data=cell_aas_dist_data{2}; | ||
| aas_dist_azimuth=cell_aas_dist_data{1}; | ||
| mod_azi_diff_bs=array_bs_azi_data(:,4); | ||
|
|
||
| % Off-axis EIRP lookup at BS-relative azimuth. | ||
| nn_azi_idx=nearestpoint_app(app,mod_azi_diff_bs,aas_dist_azimuth); | ||
| super_array_bs_eirp_dist=array_aas_dist_data(nn_azi_idx,:); | ||
|
|
||
| % Simulation azimuth grid. | ||
| [array_sim_azimuth,num_sim_azi]=calc_sim_azimuths_rev3_360_azimuths_app(app,radar_beamwidth,min_azimuth,max_azimuth); | ||
|
|
||
| % BS->point azimuths. | ||
| sim_pt=base_protection_pts(point_idx,:); | ||
| bs_azimuth=azimuth(sim_pt(1),sim_pt(2),on_list_bs(:,1),on_list_bs(:,2)); | ||
|
|
||
| % MC iteration indices for this sub-point. | ||
| sub_mc_idx=cell_sim_chunk_idx{sub_point_idx}; %#ok<NASGU> | ||
| num_mc_idx=length(sub_mc_idx); | ||
| num_bs=length(bs_azimuth); | ||
| sub_array_agg_check_mc_dBm=NaN(num_mc_idx,1); | ||
|
|
||
| % ------------------------------------------------------------------------- | ||
| % STEP 1: MC random pre-generation using a single RNG seeding call. | ||
| % Draw in [rel_min, rel_max] for PR, EIRP, clutter random reliabilities. | ||
| % ------------------------------------------------------------------------- | ||
| rel_min=min(agg_check_reliability); | ||
| rel_max=max(agg_check_reliability); | ||
|
|
||
| if rel_min==rel_max | ||
| rand_pr_all=repmat(rel_min,num_bs,num_mc_idx); | ||
| rand_eirp_all=rand_pr_all; | ||
| rand_clutter_all=rand_pr_all; | ||
| else | ||
| rng(rand_seed1); | ||
| rel_span=(rel_max-rel_min); | ||
| rand_pr_all=rel_min+rel_span.*rand(num_bs,num_mc_idx); | ||
| rand_eirp_all=rel_min+rel_span.*rand(num_bs,num_mc_idx); | ||
| rand_clutter_all=rel_min+rel_span.*rand(num_bs,num_mc_idx); | ||
| end | ||
|
|
||
| % ------------------------------------------------------------------------- | ||
| % STEP 2: Precompute off-axis gain matrix once for all (bs,sim_azimuth). | ||
| % Keep nearestpoint semantics stable. | ||
| % ------------------------------------------------------------------------- | ||
| pat_az=mod(custom_antenna_pattern(:,1),360); | ||
| pat_gain=custom_antenna_pattern(:,2); | ||
| [pat_az_unique,ia_unique]=unique(pat_az,'stable'); | ||
| pat_gain_unique=pat_gain(ia_unique); | ||
|
|
||
| off_axis_gain_matrix=NaN(num_bs,num_sim_azi); | ||
| for azimuth_idx=1:1:num_sim_azi | ||
| sim_azimuth=array_sim_azimuth(azimuth_idx); | ||
| rel_az=mod(bs_azimuth-sim_azimuth,360); | ||
| ant_deg_idx=nearestpoint_app(app,rel_az,pat_az_unique); | ||
| off_axis_gain_matrix(:,azimuth_idx)=pat_gain_unique(ant_deg_idx); | ||
| end | ||
|
|
||
| % ------------------------------------------------------------------------- | ||
| % STEP 3: RNG-free MC pathloss terms for each MC realization. | ||
| % ------------------------------------------------------------------------- | ||
| sort_monte_carlo_pr_dBm_all=NaN(num_bs,num_mc_idx); | ||
| for loop_idx=1:1:num_mc_idx | ||
| pre_sort_monte_carlo_pr_dBm=monte_carlo_Pr_dBm_rev2_app(app,agg_check_reliability,on_full_Pr_dBm,rand_pr_all(:,loop_idx)); | ||
| rand_norm_eirp=monte_carlo_super_bs_eirp_dist_rev5(app,super_array_bs_eirp_dist,agg_check_reliability,rand_eirp_all(:,loop_idx)); | ||
| monte_carlo_clutter_loss=monte_carlo_clutter_rev3_app(app,agg_check_reliability,clutter_loss,rand_clutter_all(:,loop_idx)); | ||
|
|
||
| sort_monte_carlo_pr_dBm_all(:,loop_idx)=pre_sort_monte_carlo_pr_dBm+rand_norm_eirp-monte_carlo_clutter_loss; | ||
| end | ||
|
|
||
| % ------------------------------------------------------------------------- | ||
| % STEP 4: Aggregate over BS in watts, convert back to dBm, then max over az. | ||
| % ------------------------------------------------------------------------- | ||
| for loop_idx=1:1:num_mc_idx | ||
| base_mc=sort_monte_carlo_pr_dBm_all(:,loop_idx); | ||
| max_azi_agg=-Inf; | ||
|
|
||
| for azi_start=1:azi_chunk:num_sim_azi | ||
| azi_end=min(azi_start+azi_chunk-1,num_sim_azi); | ||
| chunk_gain=off_axis_gain_matrix(:,azi_start:azi_end); | ||
| sort_temp_mc_dBm=base_mc+chunk_gain; | ||
|
|
||
| if DEBUG_CHECKS | ||
| if any(isnan(sort_temp_mc_dBm),'all') | ||
| error('subchunk_agg_check_maxazi_rev11:NaNTempDbm','NaN detected in sort_temp_mc_dBm'); | ||
| end | ||
| end | ||
|
|
||
| binary_sort_mc_watts=db2pow(sort_temp_mc_dBm)/1000; | ||
| if DEBUG_CHECKS | ||
| if any(isnan(binary_sort_mc_watts),'all') | ||
| error('subchunk_agg_check_maxazi_rev11:NaNWatt','NaN detected in binary_sort_mc_watts'); | ||
| end | ||
| end | ||
|
|
||
| azimuth_agg_dBm_chunk=pow2db(sum(binary_sort_mc_watts,1,'omitnan')*1000); | ||
| chunk_max=max(azimuth_agg_dBm_chunk,[],'omitnan'); | ||
| if chunk_max>max_azi_agg | ||
| max_azi_agg=chunk_max; | ||
| end | ||
| end | ||
|
|
||
| sub_array_agg_check_mc_dBm(loop_idx,1)=max_azi_agg; | ||
| end | ||
|
|
||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reseeds the generator with only
rand_seed1on every function call, so differentsub_point_idxchunks regenerate the same random matrices whenevernum_mc_idxis the same. In the chunked workflow (cell_sim_chunk_idx), that duplicates Monte Carlo realizations across chunks instead of producing unique draws permc_iter, which can materially skew aggregate percentiles and reduce effective sample size. The pre-generation should incorporatesub_mc_idx/mc_iteridentity (as prior revs did) or otherwise skip ahead in a deterministic way per chunk.Useful? React with 👍 / 👎.