Categories

Versions

You are viewing the RapidMiner Studio documentation for version 10.0 - Check here for latest version

Generate Macro (RapidMiner Studio Core)

Synopsis

This operator can be used to calculate new macros from existing macros. A macro can be used by writing %{macro_name} in parameter values of succeeding operators of the current process. A Macro can be considered as a value that can be used by all operators of the current process that come after the macro has been defined. This operator can also be used to re-define existing macros.

Description

This operator can be used to define macros which can be used in parameter values of succeeding operators of the current process. Once the macro has been defined, the value of that macro can be used as parameter value in coming operators by writing the macro name in %{macro_name} format in the parameter value where 'macro_name' is the name of the macro specified when it was defined. In Generate Macro operator macro names and function descriptions are specified in the function descriptions parameters. The macro will be replaced in the value strings of parameters by the macro's value. This operator can also be used to re-define existing macros by specifying the name of that macro as name in the function descriptions parameter.

A large number of operations and functions is supported, which allows you to write rich expressions. For a list of operations and functions and their descriptions open the Edit Expression dialog. Complicated expressions can be created by using multiple operations and functions. Parenthesis can be used to nest operations. Since RapidMiner 6.0.3 the operator will fail if an expression is not valid so that you can correct it. The description of all operations follows this format:

This operator also supports various constants (for example 'INFINITY', 'PI' and 'e'). Again you can find a complete list in the Edit Expression dialog. You can also use strings in operations but the string values should be enclosed in double quotes (").

The functions available in the Generate Macro operator behave analogously to the functions of the Generate Attributes operator. Please study the Example Process of the Generate Attributes operator to understand the use of these functions.

Macros

Macro can be considered as a value that can be used by all operators of the current process that come after the macro has been defined. Whenever using macros, make sure that the operators are in the correct sequence. It is compulsory that the macro should be defined before it can be used in parameter values. Macro is one of the advanced topics of RapidMiner, please study the attached Example Processes to develop a better understanding of macros.

There are also some predefined macros:

  • %{process_name}: will be replaced by the name of the process (without path and extension)
  • %{process_file}: will be replaced by the file name of the process (with extension)
  • %{process_path}: will be replaced by the complete absolute path of the process file
  • %{execution_count}: will be replaced by the number of times the current operator was applied.
  • %{operator_name}: will be replaced by the name of the current operator.

Please note that other operators like many of the loop operators (e.g. Loop Values , Loop Attributes) also add specific macros.

Input

  • through (Data Table)

    It is not compulsory to connect any object with this port. Any object connected at this port is delivered without any modifications to the output port. This operator can have multiple inputs. When one input is connected, another through input port becomes available which is ready to accept another input (if any). The order of inputs remains the same. The object supplied at first through input port of the Generate Macro operator is available at the first through output port.

Output

  • through (Data Table)

    The objects that were given as input are passed without changing to the output through this port. It is not compulsory to attach this port to any other port, the macro value is calculated even if this port is left without connections. The Generate Macro operator can have multiple outputs. When one output is connected, another through output port becomes available which is ready to deliver another output (if any). The order of outputs remains the same. The object delivered at the first through input port of the Generate Macro operator is delivered at the first through output port

Parameters

  • function_descriptionsThe list of macro names together with the expressions which define the new macros are specified through this parameter. Range:

Tutorial Processes

Generating a new macro from an already existing macro

This Example Process discusses an imaginary scenario to explain how the Generate macro operator can be used to define a new macro from an existing macro. Suppose we want to apply the K-NN operator on an ExampleSet such that the value of the k parameter of the K-NN operator is set dynamically to some ratio of number of examples in the input ExampleSet. Let us assume that the required ratio is k = n * 0.025 where n is the number of examples in the input ExampleSet.

The Polynomial data set is loaded using the Retrieve operator. The Extract Macro operator is applied on it to create a new macro. The macro parameter is set to 'example_count' and the macro type parameter is set to 'number of examples'. Thus a macro is created with the name 'example_count'. The value of this macro is equal to the number of examples in the Polynomial data set. Then the Generate Macro operator is applied. Only one macro is defined in the function descriptions parameter. The macro is named 'value_k' and it is defined by this expression: ceil(eval(%{example_count}) * 0.025). Note the use of the 'example_count' macro here. When this process is executed '%{example_count}' is replaced by the value of the 'example_count' macro which is equal to the number of examples in the input ExampleSet which is 200. Since all macros are strings we need to use the eval function to obtain 200 as number. Thus at run-time the expression that defines 'value_k' macro will be evaluated as ceil( 200 * 0.025 ). The result of this expression is 5. The K-NN operator is applied on the Polynomial data set with the parameter k set to '%{value_k}'. At run-time '%{value_k}' will be replaced by the actual value of the 'value_k' macro which is 5. Thus K-NN operator will be applied on the Polynomial data set with the parameter k set to 5. This can be verified by running the process and viewing the results in the Results Workspace.