In Diagnostic Feature Designer, 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:
Apply the code directly to a larger set of measurement data that includes more members and, therefore, increase the number of members in your feature set. Using more members improves model training in Classification Learner.
Modify the function to suit your application. For example, you might add signal processing or features that are not available in Diagnostic Feature Designer.
Incorporate portions of the function into another set of code that you are developing.
The simplest way to generate code for automatic feature extraction is to use the Export button in the Feature Designer tab and select Generate Function for Features.
Your selection opens a set of options that allow you to specify the features to include from the feature table that you select. Code generation is possible for only one feature table at a time.
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 Export button in the Feature Ranking tab. 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 recreates results in Diagnostic Feature Designer. % % Input: % inputData: A table or a cell array of tables/matrices containing the % data as those imported into the app. % % Output: % featureTable: A table containing all features and condition variables. % outputTable: A table containing the computation results. % % This function computes signals: % Vibration_tsa/Data % % This function computes features: % Vibration_stats/Data_ImpulseFactor % Vibration_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. Compute signals/spectra/features % 2. Extract computed features into a table % % Modify the function to add or remove data processing, feature generation % or ranking operations.
If you want to customize your selections for code generation, use the Export > Generate Function for... 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.
You can generate a function for features from one feature table at a time. If you are using frame-based processing, each feature table is associated with one frame policy, 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.
When you select Export > Generate Function for... and choose a feature source, a window containing candidate selection outputs opens. Each output row includes additional information on how the output was computed.
In the figure, the skewness and RMS features and the power spectrum are selected. The Details pane displays the output and input for the most recently selected item. The Code Will Be Generated For pane contains your selections.
Along with the selection window, selecting Export > Generate Function for... opens the Code Generation tab, which contains filtering options.
For example, to select only features that are computed directly from the TSA signal, select Input > Vibration_tsa/Data, as the figure shows.
The filtered selection window displays the three features that are based directly on the TSA signal, along with the power spectrum, which is also based directly on the TSA signal.
When you specify a specific input signal, the Input filter returns
only the items which use that signal directly. For example, the list filtered on the TSA
input signal contains no features that are derived from the TSA signal spectrum. If you want
to filter for text that occurs anywhere in the computation chain, type the text into the
filter. For example, if you type tsa
into the Input
filter, as the following figures show, the filtered list now includes the TSA spectral
features. Text matching is case insensitive.
You can also filter on output, method, and analysis type. For example, if you want to generate code for a ranking table, select Analysis Type > ranking.
The selection list includes the T-Test and Bhattacharyya ranking tables.
To clear all the filters, click Reset Filters.
Each filtered view displays a subset of available outputs. To display all your selections together, click Sort by Selection.
The items that you selected in the filtered views appear in one group at the top of the selection list.
To generate code for these items, click Generate Function.
The app assigns the default name of diagnosticFeatures
to 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)
fullDataTable
and you need only a feature
table features
.
Use:features = diagnosticFeatures(fullDataTable)
If you originally imported individual tables using Import Single-Member
Datasets and want to validate the code against the original data, you must
combine the tables. For example, if you imported tables t1
,
t2
, and t3
, 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, see Generate a MATLAB Function in Diagnostic Feature Designer. For an example that applies code to a new dataset, see Apply Generated MATLAB Function to Expanded Data Set. For a description of generated code itself and how it performs its computations, see Anatomy of App-Generated MATLAB Code.
The code that you generate depends in part on your selections in Computation Options. The figure below shows the Computation Options choices when you import an ensemble datastore.
In 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.
The green box in the Computation Options figure indicates the options that you can change immediately before generating code.
Store all results in a local dataset or Write 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.
Use parallel computing — 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.