55
55
InvariantEnsemble (basis,d:: Vector )= InvariantEnsemble (basis,Interval (d))
56
56
57
57
58
+ # # n, where the invariant ensemble is n x n
59
+ Base. size (ie:: InvariantEnsemble )= size (ie. basis,2 ),size (ie. basis,2 )
60
+ Base. size (ie:: InvariantEnsemble ,n)= size (ie. basis,2 )
61
+
62
+
63
+
58
64
# Takes in list of OPs, constructs phis
59
65
# can be unstable for large n
60
66
function InvariantEnsemble (p:: Array{IFun} ,V:: Function ,d,n:: Integer )
@@ -77,6 +83,11 @@ function InvariantEnsemble(p::Array{IFun},V::Function,d,n::Integer)
77
83
end
78
84
79
85
86
+
87
+
88
+
89
+
90
+ # #Construct invariant ensemble from weight, first moment and recurrence relationship
80
91
function adaptiveie (w,μ0,α,β,d)
81
92
for logn = 4 : 20
82
93
m= 2 ^ logn + 1
@@ -177,6 +188,20 @@ function RandomMatrices.eigvalrand(p::InvariantEnsemble,m::Integer)
177
188
hcat ([samplespectra (p. basis,p. domain,plan,pts) for i= 1 : m]. .. )'
178
189
end
179
190
191
+ RandomMatrices. eigvalrand (p:: InvariantEnsemble )= [eigvalrand (p,1 )[1 ,:]. .. ]
192
+
193
+ function Base. rand (p:: InvariantEnsemble )
194
+ Q= rand (Haar (2 ),size (p,1 ))
195
+ Q* diagm (eigvalrand (p))* Q'
196
+ end
197
+
198
+ function Base. rand (p:: InvariantEnsemble ,m:: Integer )
199
+ ei = eigvalrand (p,m)
200
+ [( Q= rand (Haar (2 ),size (p,1 ));
201
+ Q* diagm ([ei[k,:]. .. ])* Q' ) for k= 1 : size (ei,1 )]
202
+ end
203
+
204
+
180
205
samplespectra (q:: Array{Float64,2} ,d)= samplespectra (q,d,plan_chebyshevtransform (q[:,1 ]),chebyshevpoints (size (q,1 )))
181
206
182
207
function samplespectra (q:: Array{Float64,2} ,d,plan:: Function ,pts)
@@ -271,25 +296,25 @@ function spectradatabase(str,n::Integer,m::Integer)
271
296
272
297
ie = InvariantEnsemble (str,n)
273
298
274
- A= hcat ([ samplespectra (ie) for i = 1 : m+ 1 ] . .. ) ' ;
275
- writedlm (file,A,' ,' );
299
+ A= eigvalrand (ie, m+ 1 )
300
+ writedlm (file,A,' ,' )
276
301
else
277
- A = readdlm (file,' ,' );
302
+ A = readdlm (file,' ,' )
278
303
279
304
if ( m > size (A)[1 ])
280
305
warn (string (m) * " is greater than current samples " * string (size (A)[1 ]) * " . Generating more samples" );
281
306
282
307
ie = InvariantEnsemble (str,n)
283
308
284
- An= hcat ([ samplespectra (ie) for i = 1 : ( m- size (A)[1 ]+ 1 )] . .. ) ' ;
309
+ An= eigvalrand (ie, m- size (A)[1 ]+ 1 )
285
310
286
- A = vcat (A,An);
311
+ A = vcat (A,An)
287
312
288
- writedlm (file,A,' ,' );
313
+ writedlm (file,A,' ,' )
289
314
end
290
315
end
291
316
292
- return A[1 : m,:];
317
+ return A[1 : m,:]
293
318
end
294
319
295
320
0 commit comments