Created
May 16, 2020 12:45
-
-
Save caseykneale/bb69f11df170fa2ee72078f0f378ef24 to your computer and use it in GitHub Desktop.
Helping Kasemiir Alice with Tensors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kasemiir <- as.data.frame(read.csv2("/mydata2.csv")) | |
#i batches(BatchID), j variables and k time(Time) | |
batch_part <- split(kasemiir, f=kasemiir$BatchID) | |
#now we have a list of dataframes split over batchid | |
#z[[2]] #is batch2 etc... | |
#make sure each subdf is ordered by time and convert to matrix | |
for( subdf in batch_part){ | |
subdf <- data.matrix( subdf[order("Time")] ) | |
} | |
dimens = dim(batch_part[[2]]) | |
batches = length( batch_part ) | |
print(dimens)#dimens of 895(time) x 46(vars) | |
print(batches)#12 batches | |
ThreeTensor <- array( batch_part , dim = c( dimens[1] , dimens[2] , batches ) ) | |
dim(ThreeTensor) | |
library(rTensor)# https://rdrr.io/cran/rTensor/man/unfold-methods.html | |
UnfoldedTensor <- unfold(as.tensor(ThreeTensor), 1, c(2,3)) | |
UnfoldedMatrix <- as.matrix(UnfoldedTensor@data) | |
dim(UnfoldedMatrix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment