cost <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), nrow = 3, byrow = TRUE)
# Soft assignment with default parameters
result <- sinkhorn(cost)
print(round(result$transport_plan, 3))
# Sharper assignment (higher lambda)
result_sharp <- sinkhorn(cost, lambda = 50)
print(round(result_sharp$transport_plan, 3))
# With custom marginals (more mass from row 1)
result_weighted <- sinkhorn(cost, r_weights = c(0.5, 0.25, 0.25))
print(round(result_weighted$transport_plan, 3))
# Round to hard assignment
hard_match <- sinkhorn_to_assignment(result)
print(hard_match)
Run the code above in your browser using DataLab