bmihaljevic / bnclassify

Learning Discrete Bayesian Network Classifiers from Data
18 stars 10 forks source link

Error in 'update_assess_fold' function #27

Open biotech25 opened 7 years ago

biotech25 commented 7 years ago

Hi,

I loaded all source codes from 'bnclassify' to use all functions that are necessary in the 'update_assess_fold' function. And, I ran

tn <- bnc('tan_cl', "class", car, smooth=0.01, dag_args=list(score = 'aic')) x=tn dataset=car k=5 dag=TRUE mean=TRUE

### The source code of 'cv' function below is working so I got 'train' and 'test'

xs <- ensure_multi_list(x, type = "bnc_bn") class <- get_common_class(xs) cnames <- colnames(dataset) stopifnot(!are_disjoint(class, cnames)) test_folds <- partition_dataset(dataset, class, k) train <- lapply(test_folds, function(x) dataset[-x, , drop = FALSE]) test <- lapply(test_folds, function(x) dataset[x, , drop = FALSE])

### Then, I tried to run 'update_assess_fold' function

update_assess_fold(train, test, x, TRUE, class) Error in x$.call_struct : $ operator not defined for this S4 class

### Even in the first line of 'update_assess_fold' function, I got the same error message

ux <- lapply(x, update, dataset = train, dag = TRUE) Error in x$.call_struct : $ operator not defined for this S4 class

It seems like one of the functions that are used in the 'update' function is making the error. I looked at all source codes of functions. There are two functions that use "x$.call_struct" in an important manner; 'bnc_get_update_args' and 'get_dag_update_args'. When I test the two functions, they are working fine and I didn't get any error. So, I can't find what is wrong and why I got the 'x$.call_struct' error message. Could you help me fix this problem? What should I do to fix it?

Thank you, Sanghoon

biotech25 commented 7 years ago

I think there is an error in a certain function when using 'lapply' function. Therefore, I didn't use 'lapply' function, and instead used for loop to update bayesian network modesl in each training dataset, and get predicted class label and probability in each test dataset.

Thanks, Sanghoon

ghost commented 7 years ago

Hi Sanghoon. Sorry I haven't been able to reply sooner. On a first you, it might be that you are passing a list to a function that expects a single bnc_dag object or similar. Could you paste a minimal example that reproduces your error? Have you looked at the unit tests related to the functions you are trying to modify? Maybe you can find something useful there.

Best, Bojan

biotech25 commented 7 years ago

Hi Bojan,

I am sorry for late response. I was busy since last week. I am sorry that I didn't understand you explanation well. I attach my code here. I just used 'car' data. Once you load all source code, and ran below, you will get the same error message at the last line.

I loaded all source code first.

I loaded car data

tn <- bnc('tan_cl', "class", car, smooth=0.01, dag_args=list(score = 'aic')) x=tn dataset=car k=5 dag=TRUE mean=TRUE

I ran 'cv' function. It is fine so far

xs <- ensure_multi_list(x, type = "bnc_bn") class <- get_common_class(xs) cnames <- colnames(dataset) stopifnot(!are_disjoint(class, cnames)) test_folds <- partition_dataset(dataset, class, k) train <- lapply(test_folds, function(x) dataset[-x, , drop = FALSE]) test <- lapply(test_folds, function(x) dataset[x, , drop = FALSE])

Then, I tried to run 'update_assess_fold' function

update_assess_fold(train, test, x, TRUE, class) Error in x$.call_struct : $ operator not defined for this S4 class