-
Notifications
You must be signed in to change notification settings - Fork 0
/
causet_new_sprinkle.m
295 lines (294 loc) · 13.8 KB
/
causet_new_sprinkle.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
function [ coordinates, coordinateranges, volume, events, geoendevents ] = ...
causet_new_sprinkle( N, d, ...
shape, reducevolumeparams, rndstream, shapeparam, spacetime )
%CAUSET_NEW_SPRINKLE generates causet coordinates by sprinkling N events
% into a D dimensional SPACETIME volume with a given SHAPE.
%
% Arguments:
% N number of events to be sprinkled.
% D number of spacetime dimensions.
%
% Optional arguments:
% SHAPE specifies the shape of the compact volume for
% sprinkling.
% 'bicone' ball-shape in space-dimensions, scaled down into
% the future and into the past - forming a bicone.
% (Default)
% 'closedbicone' same as 'bicone', but the points at the 2 tips are
% added to the causet.
% 'cube' cube shape.
% 'cuboid' cuboid shape.
% 'cylinder' ball-shape in space-dimensions, stacked to a cylinder
% along the time-dimension.
% 'bicylinder' cylinder shape with 2 times default height.
% 'tricylinder' cylinder shape with 3 times default height.
% 'deccylinder' cylinder shape with 10 times default height.
% 'ball' spacetime ball.
% 'diamond' cube-shape in space-dimensions, scaled down into the
% future and into the past - forming a closed diamond.
% REDUCEVOLUMEPARAMS parameters to define selections of events for a
% reduced volume. Currently supported for the
% bicone sprinkling only. Default: [ 0, 1 ].
% The first parameter is the relative factor TO which
% the volume is reduced with every step from the
% future and/or from the past.
% The second parameter is the number of iterations
% (number of volume splits plus 1).
% As an optional third value, it can be specified if
% the volume is reduced from the future (-1, default),
% from the past (1) or both (0).
% RNDSTREAM stream for random number generation. Use 'global' to
% select the global stream (Default).
% SHAPEPARAM is a single number (radius and size) for
% 'bicone', 'ball' and 'diamond'. 'cylinder' and
% 'cube' also allow for a single number, which gives
% the size in positive and negative coordinate
% directions. (Default)
%
% A 'cuboid' asks for a [ 2, d ] matrix
% for the COORDINATERANGES.
% Passing a { [ 2, 1 ], 1 } cell array for 'cylinder',
% allows to specify the time coordinate range as
% [ 2, 1 ] matrix in the first cell, and the cylinder
% radius in the second cell.
% SPACETIME specifies the type of spacetime.
% 'Minkowski' flat spacetime. (Default)
%
% Returns:
% COORDINATES positions of the points in a [ N, d ] matrix.
% COORDINATERANGES [ 2, d ] matrix with minimal and maximal values,
% which are possible for each dimension.
% VOLUME of the spacetime shape.
% EVENTS logical [ N, n ] matrix as selections of n subvolumes
% for the N sprinkled events. The first column is the
% entire set.
% GEOENDEVENTS logical [ N, 2 ] matrix as selections of 2
% subvolumes, one in the far past and one in the far
% future to serve as random endpoints for geodesics.
%
% Copyright 2021, C. Minz. BSD 3-Clause License.
%% set start up parameter:
if nargin < 3
shape = 'bicone';
else
shape = lower( shape );
end
if nargin < 4 || isempty( reducevolumeparams )
reducevolumeparams = [ 0, 1 ];
elseif length( reducevolumeparams ) < 2
reducevolumeparams = [ reducevolumeparams, 2 ];
end
if nargin < 5 || strcmp( rndstream, 'global' )
rndstream = RandStream.getGlobalStream;
end
if nargin < 6
shapeparam = 1;
end
if length( shapeparam ) == 1
if strcmp( shape, 'cube' )
shapeparam = shapeparam * ones( 2, d );
shapeparam( 1, : ) = -shapeparam( 1, : );
shape = 'cuboid';
elseif strcmp( shape, 'cylinder' ) || strcmp( shape, 'bicylinder' ) || ...
strcmp( shape, 'tricylinder' ) || strcmp( shape, 'deccylinder' )
cylsize = shapeparam;
shapeparam = cell( 2, 1 );
shapeparam{ 1 } = cylsize * [ -1; 1 ];
if strcmp( shape, 'bicylinder' )
shapeparam{ 1 } = 2 * shapeparam{ 1 };
elseif strcmp( shape, 'tricylinder' )
shapeparam{ 1 } = 3 * shapeparam{ 1 };
elseif strcmp( shape, 'deccylinder' )
shapeparam{ 1 } = 10 * shapeparam{ 1 };
end
shapeparam{ 2 } = cylsize;
shape = 'cylinder';
end
end
if nargin < 7
spacetime = 'Minkowski';
end
%% allocate memory for coordinates:
isClosedBicone = strcmp( shape, 'closedbicone' );
isBicone = strcmp( shape, 'bicone' ) || isClosedBicone;
if isBicone
spaceradii = zeros( N + 2 * isClosedBicone, 1 );
end
coordinates = zeros( N + 2 * isClosedBicone, d );
coordinateranges = zeros( 2, d );
%% sprinkle:
if strcmp( spacetime, 'Minkowski' )
%% in d-dimensional Minkowski spacetime:
if strcmp( shape, 'ball' ) || strcmp( shape, 'cylinder' ) || isBicone
% set parameters for shapes based on a ball:
isCylinder = strcmp( shape, 'cylinder' );
if strcmp( shape, 'ball' )
balldstart = 1; % start dimenion for ball
ballrad = shapeparam; % ball radius
elseif isBicone
balldstart = 2;
ballrad = shapeparam;
coordinateranges( :, 1 ) = ballrad * [ -1; 1 ];
else
balldstart = 2;
coordinateranges( :, 1 ) = shapeparam{ 1 };
ballrad = shapeparam{ 2 };
end
% compute volume:
if strcmp( shape, 'ball' )
volume = ballrad^d * pi^( d / 2 ) / gamma( d / 2 + 1 );
else
volume = ballrad^( d - 1 ) * pi^( d / 2 - 0.5 ) / gamma( d / 2 + 0.5 );
volume = ( coordinateranges( 2, 1 ) - coordinateranges( 1, 1 ) ) * volume;
if isBicone
volume = volume / d;
end
end
balld = d - balldstart + 1; % number of ball dimenions
% set coordinate ranges for ball:
coordinateranges( 1, balldstart : d ) = -ballrad * ones( 1, balld );
coordinateranges( 2, balldstart : d ) = ballrad * ones( 1, balld );
% pick N random coordinate tuples uniformly:
for i = 1 : N
% get coordinates on sphere using normal distribution:
coordinates( i, balldstart : d ) = randn( rndstream, 1, balld );
r = sqrt( sum( coordinates( i, balldstart : d ).^2 ) );
rscaling = rand( rndstream )^( 1 / balld );
if isBicone
% get time coordinate in upper or lower cone:
hrand = rand( rndstream )^( 1 / d );
hsign = 2 * round( rand( rndstream ) ) - 1;
coordinates( i, 1 ) = hsign * ( 1 - hrand ) * ballrad;
rscaling = hrand * rscaling; % squeeze radius
spaceradii( i ) = rscaling * ballrad;
elseif isCylinder
% get time coordinate:
coordinates( i, 1 ) = ...
coordinateranges( 1, 1 ) + ...
( coordinateranges( 2, 1 ) - ...
coordinateranges( 1, 1 ) ) .* rand( rndstream );
end
% make coordinates uniform:
coordinates( i, balldstart : d ) = ...
( rscaling * ballrad / r ) .* ...
coordinates( i, balldstart : d );
end
if isClosedBicone
coordinates( N + 1, 1 ) = coordinateranges( 1, 1 );
coordinates( N + 2, 1 ) = coordinateranges( 2, 1 );
end
elseif strcmp( shape, 'cuboid' ) || strcmp( shape, 'diamond' )
% set parameters for shapes based on a cube/cuboid:
isDiamond = strcmp( shape, 'diamond' );
scaling = sqrt( d - 1 );
if isDiamond
cubedstart = 2; % start dimension for cube
coordinateranges( 1, : ) = -shapeparam * ones( 1, d );
coordinateranges( 2, : ) = shapeparam * ones( 1, d );
coordinateranges( :, 1 ) = scaling * coordinateranges( :, 1 );
else
cubedstart = 1;
coordinateranges = shapeparam;
end
% compute volume:
volume = 1;
for i = 1 : d
volume = ( coordinateranges( 2, i ) - coordinateranges( 1, i ) ) * volume;
end
if isDiamond
volume = volume / d;
end
cubed = d - cubedstart + 1; % number of cube dimenions
% pick N random coordinate tuples uniformly:
if isDiamond
for i = 1 : N
signs = ceil( 2^d * rand( rndstream ) );
% get time coordinate in upper or lower pyramid:
csign = 2 * mod( signs, 2 ) - 1;
signs = floor( signs / 2 );
hrand = 1 - rand( rndstream )^( 1 / d );
coordinates( i, 1 ) = csign * ( scaling * shapeparam ) * hrand;
% get space coordinates using uniform distribution:
for idim = cubedstart : d
csign = 2 * mod( signs, 2 ) - 1;
signs = floor( signs / 2 );
coordinates( i, idim ) = ...
csign * ( 1 - hrand ) * shapeparam * rand( rndstream );
end
end
else
for i = 1 : N
% get coordinates using uniform distribution:
coordinates( i, cubedstart : d ) = ...
coordinateranges( 1, cubedstart : d ) + ...
( coordinateranges( 2, cubedstart : d ) - ...
coordinateranges( 1, cubedstart : d ) ) .* ...
rand( rndstream, 1, cubed );
end
end
end
%% sort by time:
[ sortedtime, I ] = sort( coordinates( :, 1 ) );
coordinates = coordinates( I, : );
%% select events:
events = true( N + 2 * isClosedBicone, ...
abs( reducevolumeparams( 2 ) ) );
geoendevents = false( N + 2 * isClosedBicone, 2 );
if isBicone
spaceradii = spaceradii( I );
if ( reducevolumeparams( 2 ) < 0 ) % single volume
m_range = 1;
m_offset = 0;
tau = 2 * ballrad * reducevolumeparams( 1 )^( 1 / d );
else
volumesplits = reducevolumeparams( 2 ) - 1;
m_range = volumesplits : -1 : 1;
m_offset = 1;
tau = 2 * ballrad ...
* reducevolumeparams( 1 ).^( ( 1 : volumesplits ) / d );
end
reducefuture = ( length( reducevolumeparams ) == 2 ) ...
|| ( reducevolumeparams( 3 ) == -1 ); % also default
reducepast = ( length( reducevolumeparams ) > 2 ) ...
&& ( reducevolumeparams( 3 ) == 1 );
reduceboth = ( length( reducevolumeparams ) > 2 ) ...
&& ( reducevolumeparams( 3 ) == 0 );
if reduceboth
biconetip = tau / 2;
else
biconetip = tau - ballrad;
end
geotau = 0;
if ( length( reducevolumeparams ) > 3 )
geotau = 2 * ballrad * reducevolumeparams( 4 ) - ballrad;
end
for i = 1 : ( N + 2 * isClosedBicone )
for m = m_range
if ( reducefuture && ( spaceradii( i ) ...
< biconetip( m ) - sortedtime( i ) ) ) ...
|| ( reducepast && ( spaceradii( i ) ...
< biconetip( m ) + sortedtime( i ) ) ) ...
|| ( reduceboth && ( spaceradii( i ) ...
< biconetip( m ) - sortedtime( i ) ) ...
&& ( spaceradii( i ) ...
< biconetip( m ) + sortedtime( i ) ) )
% events is in this and further volumes:
break
else
% events is not in this volume:
events( i, m + m_offset ) = false;
% ... but perhaps in further volumes:
continue
end
end
if length( reducevolumeparams ) > 3
if ( spaceradii( i ) < geotau - sortedtime( i ) )
geoendevents( i, 1 ) = true;
elseif ( spaceradii( i ) < geotau + sortedtime( i ) )
geoendevents( i, 2 ) = true;
end
end
end
end
end
end