Main Content

Automatic Feature Extraction Using GeneratedMATLABCode

诊断功能设计师, you explore features interactively, using tools for signal processing, feature generation, and ranking. Once you determine which features perform best, you can generate code that reproduces your interactive computations and allows you to automate feature extraction on similar input data. Select among your features, computed variables, and ranking tables to specify what the code includes.

With the generated code, you can:

  • 将代码直接应用于包含更多成员的较大测量数据集,因此增加了功能集中的成员数量。使用更多成员改进模型培训Classification Learner

  • Modify the function to suit your application. For example, you might add signal processing or features that are not available in诊断功能设计师

  • 在corporate portions of the function into another set of code that you are developing.

生成功能

这simplest way to generate code for automatic feature extraction is to use the出口button in the功能设计师tab and selectGenerate Function for Features

出口button in Diagnostic Feature Designer showing menu for feature and data export and for code generation

您的选择打开了一组选项,使您可以从选择的功能表中指定要包含的功能。一次仅一个功能表可以生成代码。

诊断功能设计器的选项,用于指定要包含在代码生成中的功能

You can generate code for all your features or, if you have performed ranking, you can choose the number of top-ranked features to include. If you have performed ranking, you can also generate the function using the出口button in theFeature Rankingtab. The generated code includes the calculations for any computed signals or spectra that the feature requires. The code includes a preamble that summarizes the computations that the code performs.

%DiagnosticFeatures重新创建诊断功能设计师的结果。%% 输入:% inputData: A table or a cell array of tables/matrices containing the% data as those imported into the app.%% 输出:%特征:包含所有功能和条件变量的表。% outputTable: A table containing the computation results.%% This function computes signals:%evibration_tsa/数据%%此功能计算功能:%evibration_stats/data_impulseFactor%evibration_stats/data_mean% Vibration_stats/Data_ShapeFactor% Vibration_stats/Data_Std% Vibration_tsa_rotmac/Data_RMS% Vibration_tsa_rotmac/Data_CrestFactor%% Organization of the function:%1.计算信号/光谱/功能%2.将计算出的功能提取到表中%% Modify the function to add or remove data processing, feature generation% or ranking operations.

Generate a Function for Specific Variables, Features, and Ranking Tables

If you want to customize your selections for code generation, use the导出>生成...option. With this option you can:

  • Select code generation for any outputs that the app computes, including computed signals and spectra, ensemble statistics, and ranking tables.

  • Filter your outputs so that you can choose among features with specific characteristics, such as input signal or variable-name text.

您可以一次从一个功能表中生成功能。如果您使用的是基于框架的处理,每个功能表都与一个框架政策, or combination of frame size and frame rate. Therefore, if you want to generate code for features computed with two different frame policies, or with both full-signal mode and a frame-based mode, you must generate a separate function for each feature table.

When you generate code for frame-based signals that depend on derived full signals, computations for the full signals appear also in the generated code.

Function generation option with selections for full signal mode and for a frame-based mode

When you select导出>生成...并选择一个功能源,一个包含候选选择输出的窗口打开。每个输出行都包含有关如何计算输出的其他信息。

Window in Diagnostic Feature Designer for selecting code generation outputs

在图中,选择了偏斜和RMS功能以及功率谱。这Details窗格显示最近选择的项目的输出和输入。这Code Will Be Generated For窗格包含您的选择。

Along with the selection window, selecting导出>生成...opens theCode Generation选项卡,其中包含过滤选项。

用于选择过滤选项的诊断功能设计器中的代码生成选项卡

For example, to select only features that are computed directly from the TSA signal, select输入>振动_tsa/数据, as the figure shows.

Selection for code generation input from TSA signal data only

过滤的选择窗口显示了直接基于TSA信号的三个功能以及功率谱,该功率谱也直接基于TSA信号。

特征和频谱的过滤选择窗口

When you specify a specific input signal, the在put过滤器仅返回直接使用该信号的项目。例如,在TSA输入信号上过滤的列表不包含从TSA信号频谱中得出的功能。如果要过滤计算链中任何地方发生的文本,请在过滤器中输入文本。例如,如果您输入tsa进入在putfilter, as the following figures show, the filtered list now includes the TSA spectral features. Text matching is case insensitive.

在put filter set for all signals containing the tsa string

Filtered list of all features and spectra that contain the tsa string

您还可以过滤输出,方法和分析类型。例如,如果要为排名表生成代码,请选择分析类型>排名

Code Generation tab in Diagnostic Feature Designer with Analysis Type filter set to the ranking option

选择列表包括t检验和bhattacharyya排名表。

Filtered list of ranking tables for code generation

要清除所有过滤器,请单击Reset Filters

重置过滤器按钮

每个过滤的视图显示可用输出的子集。要一起显示所有选择,请单击Sort by Selection

按选择按钮排序

这items that you selected in the filtered views appear in one group at the top of the selection list.

List of all possible outputs with selections grouped at the top

To generate code for these items, clickGenerate Function

保存并使用生成的代码

该应用分配了的默认名称DiagnosticFeaturesto the function. You can save the function as a file with this name, or rename the function and file name. To run the function, follow the syntax in the function line of the code. For example, suppose the function line is:

function[featureTable,outputTable] = diagnosticFeatures(inputData)
该函数的两个输出是一个功能表,其中包含特征和条件变量,以及一个包含集合中所有变量的输出表。第二个输出参数是可选的。您可以在具有与最初导入到应用程序的数据相同的输入变量的任何输入数据上使用此功能。例如,假设您的数据在fulldataitand you need only a feature tablefeatures。Use:
features = diagnosticFeatures(fullDataTable)

如果您最初使用的单个表Import Single-Member Datasets并希望根据原始数据验证代码,必须将表组合在一起。例如,如果您导入表格t1,t2, andt3, where each table represents a different ensemble member, first combine the tables into a single input table, and then run the generated function.

inputData = {t1,t2,t3}; features = diagnosticFeatures(inputData);

For an example of generating code and validating the code with the original data, seeGenerate a MATLAB Function in Diagnostic Feature Designer。有关将代码应用于新数据集的示例,请参见将生成的MATLAB功能应用于扩展的数据集。有关生成代码本身及其执行计算方式的描述,请参见应用程序生成的MATLAB代码的解剖结构

Change Computation Options for Generated Code

你的代码生成开掘ds in part on your selections inComputation Options。这figure below shows theComputation Options导入集合数据存储时的选择。

Computation options in Diagnostic Feature Designer with a green box around the options that you can change just before generating code.

在some cases, you may want the generated code to use a different option than the option you used to compute your features in the app. For instance, you might want to invoke parallel computing in the code when you did not use that option originally. If you originally imported data from an ensemble datastore into local memory, you might want your code to interact directly with the external files instead.

绿色盒子Computation Options图指示您可以在生成代码之前立即更改的选项。

  • 将所有结果存储在本地数据集中orWrite results to the same folder as the original data— You can switch between options for code generation. These options appear only when you import an ensemble datastore.

  • 使用并行计算— You can change this option for code generation. You can use parallel computing only if you have Parallel Computing Toolbox™ installed.

You cannot change the data handling mode and frame policy with which specific features were calculated when you generate code.

See Also

Related Topics