-
-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix test-dot.product.game #1396
Comments
@schochastics for tomorrow |
aaah missed that in #1682 (Could do a catch all PR at the end with things I missed) |
just checked: These tests are actually wrong. g and g20 are not the same matrix! Sparse Matrix entries from the Matrix package are interpreted by A <- Matrix::sparseMatrix(
i = 1:5,
j = 1:5,
x = 1:5
)
A
#> 5 x 5 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 1 . . . .
#> [2,] . 2 . . .
#> [3,] . . 3 . .
#> [4,] . . . 4 .
#> [5,] . . . . 5
B <- Matrix::sparseMatrix(
i = 1:5,
j = 1:5,
x = 5:1
)
B
#> 5 x 5 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 5 . . . .
#> [2,] . 4 . . .
#> [3,] . . 3 . .
#> [4,] . . . 2 .
#> [5,] . . . . 1
all.equal(A,B,check.attributes=TRUE)
#> [1] "Attributes: < Component \"x\": Mean relative difference: 1 >"
all.equal(A,B,check.attributes=FALSE)
#> [1] TRUE
Matrix::all.equal(A,B)
#> [1] "Mean relative difference: 1"
as_unnamed_dense_matrix <- function(x) {
x <- as.matrix(x)
dimnames(x) <- NULL
x
}
testthat::expect_equal(as_unnamed_dense_matrix(A),as_unnamed_dense_matrix(B))
#> Error: as_unnamed_dense_matrix(A) not equal to as_unnamed_dense_matrix(B).
#> 4/25 mismatches (average diff: 3)
#> [1] 1 - 5 == -4
#> [7] 2 - 4 == -2
#> [19] 4 - 2 == 2
#> [25] 5 - 1 == 4 Created on 2025-02-19 with reprex v2.1.1 |
suggestion for a potentially more robust test withr::local_seed(42)
latent_features <- cbind(
c(0, 1, 1, 1, 0) / 3, c(0, 1, 1, 0, 1) / 3, c(1, 1, 1, 1, 0) / 4,
c(0, 1, 1, 1, 0)
)
expected_probs <- t(latent_features)%*%latent_features
diag(expected_probs) <- 0
num_graphs <- 1000
edge_counts <- matrix(0, nrow = 4, ncol = 4)
for (i in seq_len(num_graphs)) {
g <- sample_dot_product(latent_features)
adj_matrix <- as_adjacency_matrix(g, sparse = FALSE)
edge_counts <- edge_counts + adj_matrix
}
empirical_probs <- edge_counts / num_graphs
diag(empirical_probs) <- 0
tolerance <- 0.05
expect_true(all(abs(empirical_probs - expected_probs) < tolerance)) |
this is weird
The text was updated successfully, but these errors were encountered: