Calculate matrix constant in R

How to find the constant of a square matrix (for the general dimension nxn) in R? In particular, I am trying to find pdf statistics for independent but not equally distributed population groups, which includes the calculation of a constant matrix, the elements of which are pdf files and cdfs of the original population groups.

thank

+4
source share
2 answers

tl; dr , this is a nontrivial computational problem that does not seem to have been implemented in R, and is a fairly complex computational task, which may require a compiled solution. It would be best to write an R code wrapper for this open source implementation of C.

Based on the related Wikipedia article , “Ryser” looks like a good search term for finding implementations of this calculation. library("sos"); findFn("Ryser")finds only help Spearman's rank correlation , which says

n. n <= 22, , .

, . Googling "Permanent Ryser" , , MATLAB. Googling " Ryser" CodeProject, C, .

+4

matrix(1:9, 3) :

 install.packages("permute"); library(permute)
  A<-matrix(1:9, 3)

  # Error: sum( apply( allPerms(1:3), 1, function(r) prod( A[1:3, r]) )  )

allPerms, -, , , , cbind A:

sum( apply( rbind(1:3,allPerms(1:3)), 1,
                               function(r) prod( A[cbind(1:3, r)]) ) )

, , , "" .

 A <- matrix(1:16,4)    
 sum( apply( rbind(1:4,allPerms(1:4)), 1, 
                       function(r) prod( A[cbind(1:4, r)]) ) )
#[1] 55456
+2

Source: https://habr.com/ru/post/1544239/


All Articles