Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • c5f4ada
  • /
  • samplingFromCovMatrix.m
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:180fe1935d433cf1463d0bf26eef9a9db2f3c874
directory badge
swh:1:dir:c5f4adac1b72ecacc88b2619ce55482731c2b451

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
samplingFromCovMatrix.m
%% Build cov matrix, and have generate samples from it

% Build the target area
boxTargetArea = boxArea( ...
    1 ,       ... wavelength
    0.5,      ... MFP
    [0,1],    ... z
    [-10,10], ... x
    [-10,10]  ... y
);

% define HG scatter
scatter = isotropicScatter;

% make lights in far field, and views in near field
lightDirections = [0, 4];
lights = farFieldSource(deg2rad(lightDirections), 0);
views  = nearFieldSource([-5;0;-10],[5;0;-10],101);
viewsPositions = views.positions(1,:);

% render both the cov matrix, and one direct sample of the field
tic;
mulres = scmc(boxTargetArea, views, lights, scatter,1e3, ...
    'renderField', true, 'parforIters', 12);
toc

maxVal = max(abs(mulres.C(:)));

% show correlation matrix
f = figure;
f.Position = [0,0,870,420];
subplot(1,2,1)
imagesc(viewsPositions,viewsPositions,abs(mulres.C(:,:,1,1)),[0,maxVal])
title(['(',num2str(lightDirections(1)),',', ...
    num2str(lightDirections(1)),')']);

subplot(1,2,2)
imagesc(viewsPositions,viewsPositions,abs(mulres.C(:,:,1,2)),[0,maxVal])
title(['(',num2str(lightDirections(1)),',', ...
    num2str(lightDirections(2)),')']);

%% Sample from correlation matrix
% Sample from complex multinormal distribution

% first build united C matirx
C = [mulres.C(:,:,1,1),mulres.C(:,:,1,2) ; ...
     mulres.C(:,:,2,1),mulres.C(:,:,2,2)];

figure
imagesc(abs(C));
xticks([]);
yticks([]);
title('United correlation matrix');

% seperate the real and complex part of the matrix
Sigma = 0.5 * [real(C), -imag(C); imag(C), real(C)];
Miu = zeros(1,size(Sigma,1));

% take two samples
sample1 = mvnrnd(Miu,Sigma);
sample2 = mvnrnd(Miu,Sigma);

% reshape to complex number
halfSample = numel(sample1)/2;
z1 = sample1(1:halfSample) + 1i * sample1(halfSample+1:end);
z2 = sample2(1:halfSample) + 1i * sample2(halfSample+1:end);

% reshape to two lighting directions
u1 = reshape(z1,[],2);
u2 = reshape(z2,[],2);

%% Plot all samples
% In full lines - lighting direction of $0^\circ$
% 
% In dashed line - lighting direction of $4^\circ$
figure;
f = gca;
plotColors = f.ColorOrder;
hold on

l1 = plot(viewsPositions,abs(mulres.field(:,1)), ...
    'lineWidth',2,'Color',plotColors(1,:),'LineStyle','-');

plot(viewsPositions,abs(mulres.field(:,2)), ...
    'lineWidth',2,'Color',plotColors(1,:),'LineStyle','--');

l2 = plot(viewsPositions,abs(u1(:,1)), ...
    'lineWidth',2,'Color',plotColors(2,:),'LineStyle','-');

plot(viewsPositions,abs(u1(:,2)), ...
    'lineWidth',2,'Color',plotColors(2,:),'LineStyle','--');

l3 = plot(viewsPositions,abs(u2(:,1)), ...
    'lineWidth',2,'Color',plotColors(3,:),'LineStyle','-');

plot(viewsPositions,abs(u2(:,2)), ...
    'lineWidth',2,'Color',plotColors(3,:),'LineStyle','--');

legend([l1, l2, l3], 'Measured Field', 'Sampled Field 1', 'Sampled Field 2');
xlabel('View position');
ylabel('Abs field');
title('Direct rendered field vs sampled field');

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API