コード例 #1
0
 def extract_rtp_known_state(self, path_list):
     healthy_x = []
     healthy_y = []
     healthy_bs = []
     healthy_new_stroke = []
     disease_x = []
     disease_y = []
     disease_bs = []
     disease_new_stroke = []
     states = []
     for path in path_list:
         # Acuqisisco l'id del paziente
         id = HandManager.get_id_from_path(path)
         # Acquisisco lo stato del paziente
         state = HandManager.get_state_from_id(id)
         # Leggo i punti campionati nel file
         partial_x, partial_y, partial_bs = RTPExtraction.__read_samples_from_file(
             path)
         # Trasformo i punti in segmenti RHS.
         partial_x, partial_y, partial_bs = self.__transform_point_in_rtp(
             partial_x, partial_y, partial_bs)
         partial_new_stroke = RTPExtraction.__get_new_stroke(partial_bs)
         # Raddoppio il numero dei campioni RHS così da ampliare il dataset.
         partial_x, partial_y, partial_bs, partial_new_stroke = self.__extract_subs_from_samples(
             partial_x, partial_y, partial_bs, partial_new_stroke)
         # Suddivido i capioni in base allo stato di salute del paziente a cui appartengono, dopo di che genero degli
         # array mono dimensionali di lunghezza pari alla lunghezza dei campioni richiesta dal Modello.
         if state == HEALTHY_STATE:
             self.__create_sample_sequence(healthy_x, healthy_y, healthy_bs,
                                           healthy_new_stroke, partial_x,
                                           partial_y, partial_bs,
                                           partial_new_stroke)
         else:
             self.__create_sample_sequence(disease_x, disease_y, disease_bs,
                                           disease_new_stroke, partial_x,
                                           partial_y, partial_bs,
                                           partial_new_stroke)
     # Dopo aver ultimato l'estrazione genero due tensori tridimensionali, uno per i pazienti sani e uno per i pazienti malati
     healthy_tensor = np.reshape(
         np.array(healthy_x + healthy_y + healthy_bs + healthy_new_stroke),
         (len(healthy_x), self.__num_samples, FEATURES))
     disease_tensor = np.reshape(
         np.array(disease_x + disease_y + disease_bs + disease_new_stroke),
         (len(disease_x), self.__num_samples, FEATURES))
     # A questo punto per ottenere un dataset bilanciato in ogni situazione valuto quale dei due tensori possiede meno.
     healthy_tensor, disease_tensor = HandManager.balance_dataset(
         healthy_tensor, disease_tensor)
     # Il tensore con meno campioni verrà utilizzato per generare il tensore finale, il quale verrà composto inserendo
     # prima tutti gli utenti sani e poi tutti gli utenti sani, si è già provato un approccio alternato, ma ha dato
     # scarsi risultati.
     final_tensor = np.concatenate((healthy_tensor, disease_tensor))
     # Genero infine il vettore gli stati
     states += [HEALTHY_STATE for _ in range(len(healthy_tensor))
                ] + [DISEASE_STATE for _ in range(len(disease_tensor))]
     return np.array(final_tensor), np.array(states), len(final_tensor)
コード例 #2
0
 def extract_rhs_file(self, path):
     x_samples = []
     y_samples = []
     bs_samples = []
     id = HandManager.get_id_from_path(path)
     state = HandManager.get_state_from_id(id)
     partial_x, partial_y, partial_bs = RHSDistanceExtract.read_samples_from_file(path)
     partial_x, partial_y, partial_bs = self.__transform_point_in_rhs(partial_x, partial_y, partial_bs)
     partial_x, partial_y, partial_bs = self.__extract_subs_from_samples(partial_x, partial_y, partial_bs)
     self.__create_sample_sequence(x_samples, y_samples, bs_samples, partial_x, partial_y, partial_bs)
     tensor = np.reshape((x_samples + y_samples + bs_samples), (len(x_samples), self.__num_samples, FEATURES))
     states = [state for _ in range(len(x_samples))]
     return np.array(tensor), np.array(states)
コード例 #3
0
 def rtp(self, path):
     x_samples = []
     y_samples = []
     bs_samples = []
     new_stroke_samples = []
     id = HandManager.get_id_from_path(path)
     state = HandManager.get_state_from_id(id)
     partial_x, partial_y, partial_bs = RTPExtraction.__read_samples_from_file(
         path)
     partial_x, partial_y, partial_bs = self.__transform_point_in_rtp(
         partial_x, partial_y, partial_bs)
     partial_new_stroke = RTPExtraction.__get_new_stroke(partial_bs)
     partial_x, partial_y, partial_bs, partial_new_stroke = self.__extract_subs_from_samples(
         partial_x, partial_y, partial_bs, partial_new_stroke)
     self.__create_sample_sequence(x_samples, y_samples, bs_samples,
                                   new_stroke_samples, partial_x, partial_y,
                                   partial_bs, partial_new_stroke)
     tensor = np.reshape(
         (x_samples + y_samples + bs_samples + new_stroke_samples),
         (len(x_samples), self.__num_samples, FEATURES))
     states = [state for _ in range(len(x_samples))]
     return np.array(tensor), np.array(states)