analysiscenter / cardio

CardIO is a library for data science research of heart signals
https://analysiscenter.github.io/cardio/
Apache License 2.0
248 stars 78 forks source link

how can i find "batch_size" function? #33

Closed koicu closed 4 years ago

koicu commented 5 years ago

I would like to know about "batch_size" in the following code. There are three things I want to know.

template_ppl_inits = ( bf.Pipeline() .init_variable("annsamps", init_on_each_run=list) .init_variable("anntypes", init_on_each_run=list) .init_variable("hmm_features", init_on_each_run=list) .load(fmt='wfdb', components=["signal", "annotation", "meta"], ann_ext='pu1') .cwt(src="signal", dst="hmm_features", scales=[4,8,16], wavelet="mexh") .standardize(axis=-1, src="hmm_features", dst="hmm_features") .update_variable("annsamps", bf.F(get_annsamples), mode='e') .update_variable("anntypes", bf.F(get_anntypes), mode='e') .update_variable("hmm_features", bf.B("hmm_features"), mode='e') .run(batch_size=20, shuffle=False, drop_last=False, n_epochs=1, lazy=True)

)

  1. I want to know if " batch_size " is the size to determine file index or the size to determine batch of siganl.

  2. If batch_size is to determine the batch_size of siganl, i would like to know whether it is a nested, batch-free, one-step process after the other.(I want to know the structure of playing batch.)

  3. I couldn't find a method where is batch_size. I would appreciate it if you could help me know the function associated with batch_size.

roman-kh commented 5 years ago

batch_size specifies how many items should be processed in one iteration.

When you run the pipeline, it takes batch_size items from your dataset index and execute each action in the pipeline:

See batchflow documentation and tutorials for details.

koicu commented 5 years ago

nice :) i solve it and.. i have one more problem when i run this code, this error come out

i use 'q1c' parameter not 'pu1' when i init HMM initialize parameter

thanx to your reply have a good day!

.load(fmt='wfdb', components=["signal", "annotation", "meta"], ann_ext='q1c')

Traceback (most recent call last):

File "", line 142, in expanded = np.concatenate([expand_annotation(samp, types, length) for samp, types, length in zip(annsamp, anntype, lengths)])

File "", line 142, in expanded = np.concatenate([expand_annotation(samp, types, length) for samp, types, length in zip(annsamp, anntype, lengths)])

File "", line 49, in expand_annotation annot_expand[begin:end] = states[s]

KeyError: 'u'

template_ppl_inits = ( bf.Pipeline() .init_variable("annsamps", init_on_each_run=list) .init_variable("anntypes", init_on_each_run=list) .init_variable("hmm_features", init_on_each_run=list) .load(fmt='wfdb', components=["signal", "annotation", "meta"], ann_ext='q1c') .cwt(src="signal", dst="hmm_features", scales=[4,8,16], wavelet="mexh") .standardize(axis=-1, src="hmm_features", dst="hmm_features") .update_variable("annsamps", bf.F(get_annsamples), mode='e') .update_variable("anntypes", bf.F(get_anntypes), mode='e') .update_variable("hmm_features", bf.B("hmm_features"), mode='e') .run(batch_size=20, shuffle=False, drop_last=False, n_epochs=1, lazy=True)

)

%%

index.drop_channels()

%%

from cardio.pipelines import hmm_preprocessing_pipeline, hmm_train_pipeline import warnings warnings.filterwarnings('ignore')

pipeline = hmm_preprocessing_pipeline() ppl_inits = (dtst >> pipeline).run()

ppl_inits = (dtst >> template_ppl_inits).run()

lengths = [hmm_features.shape[2] for hmm_features in ppl_inits.get_variable("hmm_features")]

lengths = [hmm_features.shape[2] for hmm_features in ppl_inits.get_variable("hmm_features")] hmm_features = np.concatenate([hmm_features[0,:,:].T for hmm_features in ppl_inits.get_variable("hmm_features")]) anntype = ppl_inits.get_variable("anntypes") annsamp = ppl_inits.get_variable("annsamps")

expanded = np.concatenate([expand_annotation(samp, types, length) for samp, types, length in zip(annsamp, anntype, lengths)])

means, covariances = prepare_means_covars(hmm_features, expanded, states = [3, 5, 11, 14, 17, 19], num_features = 3)

transition_matrix, start_probabilities = prepare_transmat_startprob()

Shlyankin commented 5 years ago

KeyError: 'u' I think, that is 'u' wave in annotations file. Standard function don't process 'u' wave. If you want to recognize 'u' waves you should rework code for this. Good luck.