# Author: Isabel Darcy # Create a variety of artificial data sets # Date: Jan 15, 2018 # create data set with 7 flares. Noise1 <- cbind(runif(200, -30,30), runif(200, 5,6)) Noise2 <- cbind(runif(200, -6,30), runif(200, -6,-5)) Noise3 <- cbind(runif(200, -6,-5), runif(200, -20,20)) Noise4<- cbind(runif(200, 5,6), runif(200, -20,20)) Noise5<- cbind(runif(200, -6,6), runif(200, -6,6)) flares <- rbind(Noise1, Noise2, Noise3, Noise4, Noise5) plot(flares, asp=1) ## Apply a linear transformation to flares data # create 2x2 matrix A <- matrix(c(1, 2, 2, 0), nrow=2, ncol=2) C <- t(flares) # take the transpose of circle1 data M <- A %*% C # multiply A and C E <- eigen(A) # calculate eigenvalues and eigenvectors of A E # display E (note its data structure) plot(t(M), asp=1) # note M is the image of circle C under map A if (!require(package = "TDA")) { install.packages(pkgs = "TDA") } library("TDA") ## The TDA package has several commands for generating data sets ## with known topology: # choose 300 points randomly (with uniform distribution)from a circle of radius 1. Circle = circleUnif(300, r = 1) # choose 300 points randomly (with uniform distribution)from a 2-dimensional # sphere of radius 1. Note the 2nd parameter determines the dimension of the # sphere. # 2nd parameter = 1: 1-d sphere in R^2 = circle in R^2 # 2nd parameter = 2: 2-d sphere in R^3 # 2nd parameter = 3: 3-d sphere in R^4 Sphere = sphereUnif(300, 2, r = 1) # choose 300 points randomly (with uniform distribution)from a torus with tube # radius 1 where the center of the tube is a circle of radius 2 centered at the # origin. Note the center of the tube is not part of the torus. Torus = torusUnif(300, 1, 2) ############################################################################ ## To plot your points in a new window of size 4x5 windows(4,5);plot(torus) ## To save your data points to the csv file, circle.csv ## Note ncolumns = dimension of your data set (unless you also have a column ## containing the names of your rows). write(Circle, file = "circle.csv", ncolumns = 2, sep = ",") # To determine the directory where your file was saved getwd() # Recall you can specify where you would like to save your file, by giving the # path to the directory. For example, write(torus, file = "C:/users/YourUserName/Downloads/torus.csv", ncolumns = 3, sep = ",") ################################################ ## You can write for loops in R ## To get help for some special characters and words, one must use quotes help("for") # Create Noise data set containing 20 pts randomly chosen such that -2 < x,y < 2 Noise =cbind(runif(20, -2,2),runif(20, -2,2)) # Create a list where first element on the list is the Noise data set with 20pts. NoiseList <- list(Noise) # For each i = 2, 3, 4, 5, we create a new data set of noisy points by adding # 20 more points to the previously created noisy data set. for (i in 1:5) { MoreNoise <- cbind(runif(20, -2,2),runif(20, -2,2)) NoiseList[i] <- list(rbind(Noise, MoreNoise)) Noise <- NoiseList[[i]] windows(5,5); plot(Noise, sub = "20i points from noise.", asp = 1) filename <- "Noise.csv" write(Noise, file = filename, ncolumns = 2, sep = ",") } # Load trefoil knot data knotdata <- read.csv("../Data/trefoilknot.txt", sep = " ", header = FALSE) install.packages("scatterplot3d") library("scatterplot3d") scatterplot3d(knotdata, highlight.3d=TRUE, col.axis="blue", scttr3col.grid="lightblue", main="scatterplot3d - 1", pch=20) install.packages("rgl") library("rgl") plot3d(knotdata, col = rainbow(1000))