def configure(self, time_series): """ Store the input shape to be later used to estimate memory usage. Also create the algorithm instance. """ self.input_shape = time_series.read_data_shape() log_debug_array(LOG, time_series, "time_series") ##-------------------- Fill Algorithm for Analysis -------------------## self.algorithm = PCA()
def configure(self, time_series): """ Store the input shape to be later used to estimate memory usage. Also create the algorithm instance. """ self.input_time_series_index = time_series self.input_shape = (self.input_time_series_index.data_length_1d, self.input_time_series_index.data_length_2d, self.input_time_series_index.data_length_3d, self.input_time_series_index.data_length_4d) LOG.debug("Time series shape is %s" % str(self.input_shape)) # -------------------- Fill Algorithm for Analysis -------------------## self.algorithm = PCA()
def configure(self, view_model): # type: (PCAAdapterModel) -> None """ Store the input shape to be later used to estimate memory usage. Also create the algorithm instance. """ self.input_time_series_index = self.load_entity_by_gid( view_model.time_series) self.input_shape = (self.input_time_series_index.data_length_1d, self.input_time_series_index.data_length_2d, self.input_time_series_index.data_length_3d, self.input_time_series_index.data_length_4d) self.log.debug("Time series shape is %s" % str(self.input_shape)) # -------------------- Fill Algorithm for Analysis -------------------## self.algorithm = PCA()
def get_input_tree(self): """ Return a list of lists describing the interface to the analyzer. This is used by the GUI to generate the menus and fields necessary for defining a simulation. """ algorithm = PCA() algorithm.trait.bound = self.INTERFACE_ATTRIBUTES_ONLY tree = algorithm.interface[self.INTERFACE_ATTRIBUTES] tree[0]['conditions'] = FilterChain( fields=[FilterChain.datatype + '._nr_dimensions'], operations=["=="], values=[4]) return tree
class PCAAdapter(ABCAdapter): """ TVB adapter for calling the PCA algorithm. """ _ui_name = "Principal Component Analysis" _ui_description = "PCA for a TimeSeries input DataType." _ui_subsection = "components" def get_form_class(self): return PCAAdapterForm def get_output(self): return [PrincipalComponentsIndex] def configure(self, view_model): # type: (PCAAdapterModel) -> None """ Store the input shape to be later used to estimate memory usage. Also create the algorithm instance. """ self.input_time_series_index = self.load_entity_by_gid( view_model.time_series) self.input_shape = (self.input_time_series_index.data_length_1d, self.input_time_series_index.data_length_2d, self.input_time_series_index.data_length_3d, self.input_time_series_index.data_length_4d) self.log.debug("Time series shape is %s" % str(self.input_shape)) # -------------------- Fill Algorithm for Analysis -------------------## self.algorithm = PCA() def get_required_memory_size(self, view_model): # type: (PCAAdapterModel) -> int """ Return the required memory to run this algorithm. """ used_shape = (self.input_shape[0], 1, self.input_shape[2], self.input_shape[3]) input_size = numpy.prod(used_shape) * 8.0 output_size = self.algorithm.result_size(used_shape) return input_size + output_size def get_required_disk_size(self, view_model): # type: (PCAAdapterModel) -> int """ Returns the required disk size to be able to run the adapter (in kB). """ used_shape = (self.input_shape[0], 1, self.input_shape[2], self.input_shape[3]) return self.array_size2kb(self.algorithm.result_size(used_shape)) def launch(self, view_model): # type: (PCAAdapterModel) -> [PrincipalComponentsIndex] """ Launch algorithm and build results. :returns: the `PrincipalComponents` object built with the given timeseries as source """ # --------- Prepare a PrincipalComponents object for result ----------## principal_components_index = PrincipalComponentsIndex() principal_components_index.fk_source_gid = view_model.time_series.hex time_series_h5 = h5.h5_file_for_index(self.input_time_series_index) dest_path = h5.path_for(self.storage_path, PrincipalComponentsH5, principal_components_index.gid) pca_h5 = PrincipalComponentsH5(path=dest_path) pca_h5.source.store(time_series_h5.gid.load()) pca_h5.gid.store(uuid.UUID(principal_components_index.gid)) # ------------- NOTE: Assumes 4D, Simulator timeSeries. --------------## input_shape = time_series_h5.data.shape node_slice = [ slice(input_shape[0]), None, slice(input_shape[2]), slice(input_shape[3]) ] # ---------- Iterate over slices and compose final result ------------## small_ts = TimeSeries() for var in range(input_shape[1]): node_slice[1] = slice(var, var + 1) small_ts.data = time_series_h5.read_data_slice(tuple(node_slice)) self.algorithm.time_series = small_ts partial_pca = self.algorithm.evaluate() pca_h5.write_data_slice(partial_pca) pca_h5.close() time_series_h5.close() return principal_components_index
def get_traited_datatype(self): return PCA()
class PCAAdapter(ABCAsynchronous): """ TVB adapter for calling the PCA algorithm. """ _ui_name = "Principal Component Analysis" _ui_description = "PCA for a TimeSeries input DataType." _ui_subsection = "components" def get_input_tree(self): """ Return a list of lists describing the interface to the analyzer. This is used by the GUI to generate the menus and fields necessary for defining a simulation. """ algorithm = PCA() algorithm.trait.bound = self.INTERFACE_ATTRIBUTES_ONLY tree = algorithm.interface[self.INTERFACE_ATTRIBUTES] tree[0]['conditions'] = FilterChain( fields=[FilterChain.datatype + '._nr_dimensions'], operations=["=="], values=[4]) return tree def get_output(self): return [PrincipalComponents] def configure(self, time_series): """ Store the input shape to be later used to estimate memory usage. Also create the algorithm instance. """ self.input_shape = time_series.read_data_shape() log_debug_array(LOG, time_series, "time_series") ##-------------------- Fill Algorithm for Analysis -------------------## self.algorithm = PCA() def get_required_memory_size(self, **kwargs): """ Return the required memory to run this algorithm. """ used_shape = (self.input_shape[0], 1, self.input_shape[2], self.input_shape[3]) input_size = numpy.prod(used_shape) * 8.0 output_size = self.algorithm.result_size(used_shape) return input_size + output_size def get_required_disk_size(self, **kwargs): """ Returns the required disk size to be able to run the adapter (in kB). """ used_shape = (self.input_shape[0], 1, self.input_shape[2], self.input_shape[3]) return self.array_size2kb(self.algorithm.result_size(used_shape)) def launch(self, time_series): """ Launch algorithm and build results. :returns: the `PrincipalComponents` object built with the given timeseries as source """ ##--------- Prepare a PrincipalComponents object for result ----------## pca_result = PrincipalComponents(source=time_series, storage_path=self.storage_path) ##------------- NOTE: Assumes 4D, Simulator timeSeries. --------------## node_slice = [ slice(self.input_shape[0]), None, slice(self.input_shape[2]), slice(self.input_shape[3]) ] ##---------- Iterate over slices and compose final result ------------## small_ts = TimeSeries(use_storage=False) for var in range(self.input_shape[1]): node_slice[1] = slice(var, var + 1) small_ts.data = time_series.read_data_slice(tuple(node_slice)) self.algorithm.time_series = small_ts partial_pca = self.algorithm.evaluate() pca_result.write_data_slice(partial_pca) pca_result.close_file() return pca_result
class PCAAdapter(ABCAsynchronous): """ TVB adapter for calling the PCA algorithm. """ _ui_name = "Principal Component Analysis" _ui_description = "PCA for a TimeSeries input DataType." _ui_subsection = "components" def get_input_tree(self): """ Return a list of lists describing the interface to the analyzer. This is used by the GUI to generate the menus and fields necessary for defining a simulation. """ algorithm = PCA() algorithm.trait.bound = self.INTERFACE_ATTRIBUTES_ONLY tree = algorithm.interface[self.INTERFACE_ATTRIBUTES] tree[0]['conditions'] = FilterChain(fields=[FilterChain.datatype + '._nr_dimensions'], operations=["=="], values=[4]) return tree def get_output(self): return [PrincipalComponents] def configure(self, time_series): """ Store the input shape to be later used to estimate memory usage. Also create the algorithm instance. """ self.input_shape = time_series.read_data_shape() log_debug_array(LOG, time_series, "time_series") ##-------------------- Fill Algorithm for Analysis -------------------## self.algorithm = PCA() def get_required_memory_size(self, **kwargs): """ Return the required memory to run this algorithm. """ used_shape = (self.input_shape[0], 1, self.input_shape[2], self.input_shape[3]) input_size = numpy.prod(used_shape) * 8.0 output_size = self.algorithm.result_size(used_shape) return input_size + output_size def get_required_disk_size(self, **kwargs): """ Returns the required disk size to be able to run the adapter (in kB). """ used_shape = (self.input_shape[0], 1, self.input_shape[2], self.input_shape[3]) return self.array_size2kb(self.algorithm.result_size(used_shape)) def launch(self, time_series): """ Launch algorithm and build results. :returns: the `PrincipalComponents` object built with the given timeseries as source """ ##--------- Prepare a PrincipalComponents object for result ----------## pca_result = PrincipalComponents(source=time_series, storage_path=self.storage_path) ##------------- NOTE: Assumes 4D, Simulator timeSeries. --------------## node_slice = [slice(self.input_shape[0]), None, slice(self.input_shape[2]), slice(self.input_shape[3])] ##---------- Iterate over slices and compose final result ------------## small_ts = TimeSeries(use_storage=False) for var in range(self.input_shape[1]): node_slice[1] = slice(var, var + 1) small_ts.data = time_series.read_data_slice(tuple(node_slice)) self.algorithm.time_series = small_ts partial_pca = self.algorithm.evaluate() pca_result.write_data_slice(partial_pca) pca_result.close_file() return pca_result