ggobi / tourr

A implementation of tour algorithms in R
http://ggobi.github.io/tourr/
Other
65 stars 21 forks source link

Unexpected behaviour in frozen_tour() #104

Open nspyrison opened 3 years ago

nspyrison commented 3 years ago

1) works for some but not all variables 2) Only seems to check the column norm, not the row (variable norm) 3) see other comments in the example section, not run

require(tourr)
#> Loading required package: tourr
#> Warning: package 'tourr' was built under R version 4.0.5
?frozen_tour ## Also not the Not run: code and comments in the examples section.

#### Works for some variables but not others. ------
## Example case; expected success
frozen <- matrix(NA, nrow = 4, ncol = 2)
frozen[3, ] <- .5
if(interactive())
  animate_xy(flea[, 1:4], frozen_tour(2, frozen)) 

## Trivial variable change; unexpected error
frozen <- matrix(NA, nrow = 4, ncol = 2)
frozen[1, ] <- .5
animate_xy(flea[, 1:4], frozen_tour(2, frozen))
#> Converting input data to the required matrix format.
#> target_dist - cur_dist: 0 
#> generation:  dist =   1.815423
#> Error in svd(t(Fa) %*% Fz): infinite or missing values in 'x'

#### Check is column norm >1, also need to check row norm? ------
## Norm > 1; expected error
frozen <- matrix(NA, nrow = 4, ncol = 2)
frozen[3, ] <- 1.1 
animate_xy(flea[, 1:4], frozen_tour(2, frozen))
#> Converting input data to the required matrix format.
#> Error: Columns of frozen matrix must have squared norm < 1

## Norm > 1, variable contribution larger than 1; unexpected success
frozen <- matrix(NA, nrow = 4, ncol = 2)
frozen[3, ] <- .9
if(interactive())
  animate_xy(flea[, 1:4], frozen_tour(2, frozen))

## Norm > 1, each row < 1, but col norm > 1; expected error
frozen <- matrix(NA, nrow = 4, ncol = 2)
frozen[c(3, 4), ] <- .9
animate_xy(flea[, 1:4], frozen_tour(2, frozen))
#> Converting input data to the required matrix format.
#> Error: Columns of frozen matrix must have squared norm < 1

Created on 2021-04-12 by the reprex package (v1.0.0)

dicook commented 3 years ago

@nspyrison try out the code again. I fixed one problem that the initialisation wasn't happening correctly if one of the first variables was frozen.

nspyrison commented 3 years ago

@dicook, that fixed the first issue! To list the remaining issue and re-hash 2 cases from the example section of ?frozen_tour:

require(tourr) ## SHA1 (272a2f88) from 30/05/2021
#> Loading required package: tourr
#install.packages("ellipsis") ## required newer ver
#install.packages("vctrs") ## required newer ver

print("Case 4 remains unexpected success.")
#> [1] "Case 4 remains unexpected success."
## Norm > 1, variable contribution larger than 1; unexpected success
frozen <- matrix(NA, nrow = 4, ncol = 2)
frozen[3, ] <- .9
if(interactive())
  animate_xy(flea[, 1:4], frozen_tour(2, frozen))

print("Now working, but sometimes has discrete jumps, step size seem much larger than ussual for 2 consecutive frames, seems undesirable.")
#> [1] "Now working, but sometimes has discrete jumps, step size seem much larger than ussual for 2 consecutive frames, seems undesirable."
# Doesn't work - a bug?
frozen <- matrix(NA, nrow = 4, ncol = 2)
frozen[1:2, 1] <- 1 / 4
if(interactive())
  animate_xy(flea[, 1:4], frozen_tour(2, frozen))

print("Less importantly, when norm = 1, error code should suggest use of dependence_tour() to set 1 variable to 1 axis. As pointed out in this example code:")
#> [1] "Less importantly, when norm = 1, error code should suggest use of dependence_tour() to set 1 variable to 1 axis. As pointed out in this example code:"
## Not run: 
# This freezes one entire direction which causes a problem,
# and is caught by error handling.
# If you want to do this it would be best with a dependence
# tour, with one variable set one axis, eg 3rd variable to
# x axis would be indicated from the code below
frozen <- matrix(NA, nrow = 4, ncol = 2)
frozen[3, ] <- c(0, 1)
animate_xy(flea[, 1:4], frozen_tour(2, frozen))
#> Converting input data to the required matrix format.
#> Error: Columns of frozen matrix must have squared norm < 1

Created on 2021-05-30 by the reprex package (v2.0.0)