spectrum_functions.py
def export(coll,\
           ID,\
           sample_length=20,\
           test_size=5,\
           path_save="./dataset_spectrum/"):
    """
    
        Saves as a pickle file the training or testing sets.

    Parameters
    ----------
    coll : list
        List of participants that should be exported. If the
        length of the list is 1, the set is the out-of-sample
        set. Otherwise, it is the training set.
    ID : int
        A random ID that will be used to export the file.
    
    sample_length: Number of observations of each stream of data
    
    test_size: how many piece of sample_length sized data from one patient being tested
        Default: 5
    
    path_save: directory to save the dataset
        
    """

    try:
        os.mkdir(path_save)
        print("Directory " , path_save ,  " Created ") 
    except FileExistsError:
        continue
    
    

    if not os.path.exists(path_save+str(ID)):
            os.makedirs(path_save+str(ID))

            
    dataset=[]
    
        # For each participant and each bucket of appropriate size,
        # add the stream of data to dataset.
    l=copy.deepcopy(coll)
    
    
    if len(coll)==1:
            # We want to export a single participant for
            # testing.
        setType="test_set"
            
            
        for participant in l:
        
            min2=np.minimum(len(participant.data[0]),\
                            len(participant.data[1]))

            random_start=np.random.randint(min2-sample_length,\
                                           size=test_size)

            for i in range(test_size):
                p = Participant([participant.data[0][random_start[i]:random_start[i]+sample_length],\
                                participant.data[1][random_start[i]:random_start[i]+sample_length]],\
                                [participant.time[0][random_start[i]:random_start[i]+sample_length],\
                                participant.time[1][random_start[i]:random_start[i]+sample_length]],\
                                participant.idNumber,\
                                participant.diagnosis,\
                                None)
            
                dataset.append(p)

            
            
    else:
            # We want to export the rest of the cohort
            # for training.
        setType="train_set"


        for participant in l:
        
            min2=np.minimum(len(participant.data[0]),\
                            len(participant.data[1]))
            
            ########### changing class Participant if change database #############

            random_start=random.randint(0,min2-sample_length)

            p = Participant([participant.data[0][random_start:random_start+sample_length],\
                            participant.data[1][random_start:random_start+sample_length]],\
                            [participant.time[0][random_start:random_start+sample_length],\
                            participant.time[1][random_start:random_start+sample_length]],\
                            participant.idNumber,\
                            participant.diagnosis,\
                            None)
            
            dataset.append(p)



        
    # Export the dataset.
    filehandler = open(path_save+str(ID)+"/"+setType+".obj","wb")
    pickle.dump(dataset,filehandler)
    filehandler.close()

    
        Saves as a pickle file the training or testing sets.

    Parameters
    ----------
    coll : list
        List of participants that should be exported. If the
        length of the list is 1, the set is the out-of-sample
        set. Otherwise, it is the training set.
    ID : int
        A random ID that will be used to export the file.
    
    sample_length: Number of observations of each stream of data
    
    test_size: how many piece of sample_length sized data from one patient being tested
        Default: 5
    
    path_save: directory to save the dataset
        
    
Saves as a pickle file the training or testing sets.
Parameters

coll : list
List of participants that should be exported. If the
length of the list is 1, the set is the out-of-sample
set. Otherwise, it is the training set.
ID : int
A random ID that will be used to export the file.

Number of observations of each stream of data



directory to save the dataset
Saves as a pickle file the training or testing sets . Parameters coll : list List of participants that should be exported . If the length of the list is 1 the set is the out - of - sample set . Otherwise it is the training set . ID : int A random ID that will be used to export the file . Number of observations of each stream of data directory to save the dataset
def export(coll,\
           ID,\
           sample_length=20,\
           test_size=5,\
           path_save="./dataset_spectrum/"):
    try:
        os.mkdir(path_save)
        print("Directory " , path_save ,  " Created ") 
    except FileExistsError:
        continue
    if not os.path.exists(path_save+str(ID)):
            os.makedirs(path_save+str(ID))
    dataset=[]
    l=copy.deepcopy(coll)
    if len(coll)==1:
        setType="test_set"
        for participant in l:
            min2=np.minimum(len(participant.data[0]),\
                            len(participant.data[1]))
            random_start=np.random.randint(min2-sample_length,\
                                           size=test_size)
            for i in range(test_size):
                p = Participant([participant.data[0][random_start[i]:random_start[i]+sample_length],\
                                participant.data[1][random_start[i]:random_start[i]+sample_length]],\
                                [participant.time[0][random_start[i]:random_start[i]+sample_length],\
                                participant.time[1][random_start[i]:random_start[i]+sample_length]],\
                                participant.idNumber,\
                                participant.diagnosis,\
                                None)
                dataset.append(p)
    else:
        setType="train_set"
        for participant in l:
            min2=np.minimum(len(participant.data[0]),\
                            len(participant.data[1]))
            random_start=random.randint(0,min2-sample_length)
            p = Participant([participant.data[0][random_start:random_start+sample_length],\
                            participant.data[1][random_start:random_start+sample_length]],\
                            [participant.time[0][random_start:random_start+sample_length],\
                            participant.time[1][random_start:random_start+sample_length]],\
                            participant.idNumber,\
                            participant.diagnosis,\
                            None)
            dataset.append(p)
    filehandler = open(path_save+str(ID)+"/"+setType+".obj","wb")
    pickle.dump(dataset,filehandler)
    filehandler.close()
def export ( coll , ID , sample_length = 20 , test_size = 5 , path_save = "./dataset_spectrum/" ) : try : os . mkdir ( path_save ) print ( "Directory " , path_save , " Created " ) except FileExistsError : continue if not os . path . exists ( path_save + str ( ID ) ) : os . makedirs ( path_save + str ( ID ) ) dataset = [ ] l = copy . deepcopy ( coll ) if len ( coll ) == 1 : setType = "test_set" for participant in l : min2 = np . minimum ( len ( participant . data [ 0 ] ) , len ( participant . data [ 1 ] ) ) random_start = np . random . randint ( min2 - sample_length , size = test_size ) for i in range ( test_size ) : p = Participant ( [ participant . data [ 0 ] [ random_start [ i ] : random_start [ i ] + sample_length ] , participant . data [ 1 ] [ random_start [ i ] : random_start [ i ] + sample_length ] ] , [ participant . time [ 0 ] [ random_start [ i ] : random_start [ i ] + sample_length ] , participant . time [ 1 ] [ random_start [ i ] : random_start [ i ] + sample_length ] ] , participant . idNumber , participant . diagnosis , None ) dataset . append ( p ) else : setType = "train_set" for participant in l : min2 = np . minimum ( len ( participant . data [ 0 ] ) , len ( participant . data [ 1 ] ) ) random_start = random . randint ( 0 , min2 - sample_length ) p = Participant ( [ participant . data [ 0 ] [ random_start : random_start + sample_length ] , participant . data [ 1 ] [ random_start : random_start + sample_length ] ] , [ participant . time [ 0 ] [ random_start : random_start + sample_length ] , participant . time [ 1 ] [ random_start : random_start + sample_length ] ] , participant . idNumber , participant . diagnosis , None ) dataset . append ( p ) filehandler = open ( path_save + str ( ID ) + "/" + setType + ".obj" , "wb" ) pickle . dump ( dataset , filehandler ) filehandler . close ( )
Saves as a pickle file the training or testing sets.
Saves as a pickle file the training or testing sets .
"""
    
        Saves as a pickle file the training or testing sets.

    Parameters
    ----------
    coll : list
        List of participants that should be exported. If the
        length of the list is 1, the set is the out-of-sample
        set. Otherwise, it is the training set.
    ID : int
        A random ID that will be used to export the file.
    
    sample_length: Number of observations of each stream of data
    
    test_size: how many piece of sample_length sized data from one patient being tested
        Default: 5
    
    path_save: directory to save the dataset
        
    """ # For each participant and each bucket of appropriate size, # add the stream of data to dataset. # We want to export a single participant for # testing. # We want to export the rest of the cohort # for training. ########### changing class Participant if change database ############# # Export the dataset.
coll
ID
sample_length
test_size
path_save