本文整理汇总了Python中pySPACE.resources.data_types.time_series.TimeSeries.reorder方法的典型用法代码示例。如果您正苦于以下问题:Python TimeSeries.reorder方法的具体用法?Python TimeSeries.reorder怎么用?Python TimeSeries.reorder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pySPACE.resources.data_types.time_series.TimeSeries
的用法示例。
在下文中一共展示了TimeSeries.reorder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _prepare_prediction
# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import reorder [as 别名]
def _prepare_prediction(self, data): #PredictionVector Data to work with.
""" Convert prediction vector to time series object for visualization
Using the function *get_previous_transformations* the node history is
searched for the respective transformation parametrizations and then
the transformations are combined tog et a complete picture of the
data processing chain.
A special case is, when the
:class:`~pySPACE.missions.nodes.meta.flow_node.BacktransformationNode`
**Parameters**
:data: This is a Prediction Vector, which might contain data in its
history component which is used for multiplication with
the transformation or which is used as sample for
calculating the derivative of the processing chain for the
backtransformation.
"""
if self.current_trafo_TS is None: #needed only once
transformation_list = self.get_previous_transformations(data)
classifier = transformation_list[-1]
if classifier[3] == "generic_backtransformation":
current_trafo = classifier[0]
if type(current_trafo) == FeatureVector:
current_trafo_TS = type_conversion.\
FeatureVector2TimeSeriesNode()._execute(current_trafo)
elif type(current_trafo) == TimeSeries:
current_trafo_TS = current_trafo
if self.covariancing:
shape = current_trafo_TS.shape
covariance = classifier[1][1]
new_TS_array = numpy.dot(
covariance, current_trafo_TS.flatten()).reshape(shape)
current_trafo_TS = TimeSeries.replace_data(
current_trafo_TS, new_TS_array)
elif classifier[3] == "linear classifier":
classifier_FV = FeatureVector(numpy.atleast_2d(classifier[0]),
feature_names=classifier[2])
current_trafo = classifier_FV
if self.use_FN:
try:
FN = transformation_list[-2]
assert(FN[3]=="feature normalization")
assert(classifier[2]==FN[2]),"VisualizationBase:: Feature names do not match!"
FN_FV = FeatureVector(numpy.atleast_2d(FN[0]),
feature_names = FN[2])
current_trafo = FeatureVector(current_trafo*FN_FV,
feature_names = FN_FV.feature_names)
except:
warnings.warn("VisualizationBase:: Did not get any feature normalization!")
pass #raise
current_trafo_TS = type_conversion.FeatureVector2TimeSeriesNode()._execute(current_trafo)
if self.use_SF:
try:
# TODO CHECK fitting of channel names
SF = transformation_list[-2]
if not SF[3] == "spatial filter":
SF = transformation_list[-3]
assert(SF[3] == "spatial filter")
new_channel_names = SF[2]
SF_trafo = SF[0]
current_trafo_TS = TimeSeries(numpy.dot(current_trafo_TS,SF_trafo.T),
channel_names = new_channel_names,
sampling_frequency = current_trafo_TS.sampling_frequency)
except:
warnings.warn("VisualizationBase:: Did not get any spatial filter!")
pass #raise
else:
warnings.warn("VisualizationBase:: "+
"Did not get any classifier transformation!")
raise RuntimeError
# the reordering should have been done in the type conversion
current_trafo_TS.reorder(sorted(current_trafo_TS.channel_names))
self.current_trafo_TS=current_trafo_TS
prepared_prediction = self.current_trafo_TS
if self.history_index:
found_in_history=False
if data.has_history():
try:
prepared_history = copy.deepcopy(data.history[self.history_index-1])
if type(prepared_history)==FeatureVector:
prepared_history=type_conversion.FeatureVector2TimeSeriesNode()._execute(prepared_history)
found_in_history=True
except:
pass
if found_in_history:
prepared_history.reorder(self.current_trafo_TS.channel_names)
prepared_prediction = copy.deepcopy(prepared_prediction)*prepared_history
else:
warnings.warn("VisualizationBase:: No FeatureVector or TimeSeries found in history. Parameter history_index ignored!")
return prepared_prediction
示例2: VisualizationBase
# 需要导入模块: from pySPACE.resources.data_types.time_series import TimeSeries [as 别名]
# 或者: from pySPACE.resources.data_types.time_series.TimeSeries import reorder [as 别名]
#.........这里部分代码省略.........
shape = current_trafo_TS.shape
covariance = classifier[1][1]
new_TS_array = numpy.dot(
covariance, current_trafo_TS.flatten()).reshape(shape)
current_trafo_TS = TimeSeries.replace_data(
current_trafo_TS, new_TS_array)
elif classifier[3] == "linear classifier":
classifier_FV = FeatureVector(numpy.atleast_2d(classifier[0]),
feature_names=classifier[2])
current_trafo = classifier_FV
if self.use_FN:
try:
FN = transformation_list[-2]
assert(FN[3]=="feature normalization")
assert(classifier[2]==FN[2]),"VisualizationBase:: Feature names do not match!"
FN_FV = FeatureVector(numpy.atleast_2d(FN[0]),
feature_names = FN[2])
current_trafo = FeatureVector(current_trafo*FN_FV,
feature_names = FN_FV.feature_names)
except:
warnings.warn("VisualizationBase:: Did not get any feature normalization!")
pass #raise
current_trafo_TS = type_conversion.FeatureVector2TimeSeriesNode()._execute(current_trafo)
if self.use_SF:
try:
# TODO CHECK fitting of channel names
SF = transformation_list[-2]
if not SF[3] == "spatial filter":
SF = transformation_list[-3]
assert(SF[3] == "spatial filter")
new_channel_names = SF[2]
SF_trafo = SF[0]
current_trafo_TS = TimeSeries(numpy.dot(current_trafo_TS,SF_trafo.T),
channel_names = new_channel_names,
sampling_frequency = current_trafo_TS.sampling_frequency)
except:
warnings.warn("VisualizationBase:: Did not get any spatial filter!")
pass #raise
else:
warnings.warn("VisualizationBase:: "+
"Did not get any classifier transformation!")
raise RuntimeError
# the reordering should have been done in the type conversion
current_trafo_TS.reorder(sorted(current_trafo_TS.channel_names))
self.current_trafo_TS=current_trafo_TS
prepared_prediction = self.current_trafo_TS
if self.history_index:
found_in_history=False
if data.has_history():
try:
prepared_history = copy.deepcopy(data.history[self.history_index-1])
if type(prepared_history)==FeatureVector:
prepared_history=type_conversion.FeatureVector2TimeSeriesNode()._execute(prepared_history)
found_in_history=True
except:
pass
if found_in_history:
prepared_history.reorder(self.current_trafo_TS.channel_names)
prepared_prediction = copy.deepcopy(prepared_prediction)*prepared_history
else:
warnings.warn("VisualizationBase:: No FeatureVector or TimeSeries found in history. Parameter history_index ignored!")
return prepared_prediction
def _prepare_FV(self, data):
""" Convert FeatureVector into TimeSeries and use it for plotting.
.. note:: This function is not yet working as it should be.
Work in progress.
Commit due to LRP-Demo (DLR Review)
"""
# visualization of transformation or history data times visualization
if self.current_trafo_TS is None:
transformation_list = self.get_previous_transformations(data)
transformation_list.reverse() #first element is previous node
for elem in transformation_list:
if self.use_FN and elem[3]=="feature normalization":
# visualize Feature normalization scaling as feature vector
FN_FV = FeatureVector(numpy.atleast_2d(elem[0]),
feature_names = elem[2])
self.current_trafo_TS = type_conversion.FeatureVector2TimeSeriesNode()._execute(FN_FV)
self.current_trafo_TS.reorder(sorted(self.current_trafo_TS.channel_names))
break
# visualize spatial filter as times series,
# where the time axis is the number of channel or virtual
# channel name
if self.use_SF and elem[3]=="spatial filter":
new_channel_names = elem[2]
SF_trafo = elem[0]
self.current_trafo_TS = TimeSeries(SF_trafo.T,
channel_names = new_channel_names,
sampling_frequency = 1)
self.current_trafo_TS.reorder(sorted(self.current_trafo_TS.channel_names))
break
return self.current_trafo_TS