11library(Rfast )
22
3-
3+ # run time of the method
44measure_runtime <- function (func , ... ) {
55 start_time = Sys.time()
66 result = do.call(func , list (... ))
@@ -20,6 +20,16 @@ MatrixMultiplication <- function(p) {
2020 return (b )
2121}
2222
23+ DistributedRandom <- function (n , p , m ) {
24+ mean_vec = rep(0 , p )
25+ cov_mat = 0.5 ^ abs(outer(1 : p , 1 : p , " -" ))
26+ x = vector(" list" , length = m )
27+ for (i in 1 : m ) {
28+ x [[i ]] = Rfast :: rmvnorm(n , mean_vec , cov_mat )
29+ }
30+ return (x )
31+ }
32+
2333Data_result = measure_runtime(RandomData , n = 200 , p = 2000 )
2434cat(" 随机数生成结果: " , dim(Data_result $ result ), " \n " )
2535sprintf(" 随机数生成时间为 %.2f 秒" , Data_result $ runtime )
@@ -28,12 +38,16 @@ Matrix_result = measure_runtime(MatrixMultiplication, p=2000)
2838cat(" 矩阵乘法结果: " , dim(Matrix_result $ result ), " \n " )
2939cat(" 矩阵乘法时间: " , Matrix_result $ runtime , " seconds\n " )
3040
41+ Distributed_result = measure_runtime(DistributedRandom , n = 6000 , p = 600 , m = 60 )
42+ sprintf(" 分布式随机数生成时间为 %.2f 秒" , Distributed_result $ runtime )
43+
3144# win original: 4 seconds, 6.8 seconds
3245# win OpenBLAS: 0.8 seconds, 0.5 seconds
3346# mac mini M4: 1.2 seconds, 2 seconds
3447# mac mini M4 Accelerating R: 0.1 seconds, 0.12 seconds
3548
3649
50+ # metrics for method results
3751method_metrics <- function (method_result , beta_true ) {
3852 beta_index1 = which(beta_true != 0 )
3953 beta_index2 = which(method_result $ beta != 0 )
@@ -52,3 +66,4 @@ method_metrics <- function(method_result, beta_true) {
5266
5367
5468
69+
0 commit comments