Create macros dynamically according to data

phivu
phivu New Altair Community Member
edited November 5 in Community Q&A

Hi RapidMiner,

 

I'm doing predictive maintenance, I have a data table containing a list of fault types and their corresponding percentages (as below). What I want is to create a macro for each fault type storing the percentage value. Because the size of the list may change overtime, I want a dynamic way to create the macros (# of macros= # of fault types). These macros will be reused many times later. Is there a way to do this? Thanks a lot for your help!

 

RESTART 0.31

MECH 0.26

PROD 0.13

ELEC 0.11

PLUMB 0.1

SOFT 0.06

SAFETY 0.02

UPG 0.01

Tagged:

Best Answers

  • MartinLiebig
    MartinLiebig
    Altair Employee
    Answer ✓

    Hey,

    Loop Examples + Extract macro should do the job :).

     

    ~Martin

  • JEdward
    JEdward New Altair Community Member
    Answer ✓

    Yes it is.  I often do it for cases where the number of fields might change. 

     

    One thing to think about in your process is how you will use those macros when they are generated... especially if they will be reused many times over. 

    You might find it more convenient to (rather than a macro) create a table which stores all the fault values and percentages and just recall that when required and extract the necessary value.  Here's an example process showing both methods. 

     

    <?xml version="1.0" encoding="UTF-8"?><process version="7.3.000">
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="7.3.000" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="retrieve" compatibility="7.3.000" expanded="true" height="68" name="Retrieve Iris" width="90" x="45" y="34">
    <parameter key="repository_entry" value="//Samples/data/Iris"/>
    </operator>
    <operator activated="true" class="loop_attributes" compatibility="7.3.000" expanded="true" height="82" name="Loop Attributes" width="90" x="179" y="34">
    <process expanded="true">
    <operator activated="true" class="extract_macro" compatibility="7.3.000" expanded="true" height="68" name="Extract Macro" width="90" x="112" y="34">
    <parameter key="macro" value="DynamicMacro_%{loop_attribute}_Average"/>
    <parameter key="macro_type" value="statistics"/>
    <parameter key="attribute_name" value="%{loop_attribute}"/>
    <list key="additional_macros"/>
    </operator>
    <connect from_port="example set" to_op="Extract Macro" to_port="example set"/>
    <connect from_op="Extract Macro" from_port="example set" to_port="example set"/>
    <portSpacing port="source_example set" spacing="0"/>
    <portSpacing port="sink_example set" spacing="0"/>
    <portSpacing port="sink_result 1" spacing="0"/>
    </process>
    </operator>
    <operator activated="true" class="generate_data_user_specification" compatibility="7.3.000" expanded="true" height="68" name="Extract Value of Macro" width="90" x="581" y="34">
    <list key="attribute_values">
    <parameter key="a1_average" value="%{DynamicMacro_a1_Average}"/>
    </list>
    <list key="set_additional_roles"/>
    <description align="center" color="transparent" colored="false" width="126">Select the macro you want dynamically when required.</description>
    </operator>
    <operator activated="true" class="retrieve" compatibility="7.3.000" expanded="true" height="68" name="Retrieve Iris (2)" width="90" x="45" y="391">
    <parameter key="repository_entry" value="//Samples/data/Iris"/>
    </operator>
    <operator activated="true" class="aggregate" compatibility="7.3.000" expanded="true" height="82" name="Aggregate" width="90" x="179" y="391">
    <parameter key="use_default_aggregation" value="true"/>
    <list key="aggregation_attributes"/>
    </operator>
    <operator activated="true" class="remember" compatibility="7.3.000" expanded="true" height="68" name="Remember" width="90" x="313" y="391">
    <parameter key="name" value="MyDataSet"/>
    </operator>
    <operator activated="true" class="recall" compatibility="7.3.000" expanded="true" height="68" name="Recall" width="90" x="581" y="391">
    <parameter key="name" value="MyDataSet"/>
    <parameter key="remove_from_store" value="false"/>
    <description align="center" color="transparent" colored="false" width="126">Select the value you want dynamically when required.</description>
    </operator>
    <connect from_op="Retrieve Iris" from_port="output" to_op="Loop Attributes" to_port="example set"/>
    <connect from_op="Extract Value of Macro" from_port="output" to_port="result 1"/>
    <connect from_op="Retrieve Iris (2)" from_port="output" to_op="Aggregate" to_port="example set input"/>
    <connect from_op="Aggregate" from_port="example set output" to_op="Remember" to_port="store"/>
    <connect from_op="Recall" from_port="result" to_port="result 2"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="sink_result 1" spacing="0"/>
    <portSpacing port="sink_result 2" spacing="336"/>
    <portSpacing port="sink_result 3" spacing="0"/>
    <description align="center" color="yellow" colored="false" height="69" resized="true" width="401" x="26" y="177">Method 1, Dynamically Create Macros</description>
    <description align="center" color="yellow" colored="false" height="69" resized="false" width="401" x="27" y="493">Method 2, Creating a table &amp;amp; storing in memory</description>
    </process>
    </operator>
    </process>

Answers

  • MartinLiebig
    MartinLiebig
    Altair Employee
    Answer ✓

    Hey,

    Loop Examples + Extract macro should do the job :).

     

    ~Martin

  • JEdward
    JEdward New Altair Community Member
    Answer ✓

    Yes it is.  I often do it for cases where the number of fields might change. 

     

    One thing to think about in your process is how you will use those macros when they are generated... especially if they will be reused many times over. 

    You might find it more convenient to (rather than a macro) create a table which stores all the fault values and percentages and just recall that when required and extract the necessary value.  Here's an example process showing both methods. 

     

    <?xml version="1.0" encoding="UTF-8"?><process version="7.3.000">
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="7.3.000" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="retrieve" compatibility="7.3.000" expanded="true" height="68" name="Retrieve Iris" width="90" x="45" y="34">
    <parameter key="repository_entry" value="//Samples/data/Iris"/>
    </operator>
    <operator activated="true" class="loop_attributes" compatibility="7.3.000" expanded="true" height="82" name="Loop Attributes" width="90" x="179" y="34">
    <process expanded="true">
    <operator activated="true" class="extract_macro" compatibility="7.3.000" expanded="true" height="68" name="Extract Macro" width="90" x="112" y="34">
    <parameter key="macro" value="DynamicMacro_%{loop_attribute}_Average"/>
    <parameter key="macro_type" value="statistics"/>
    <parameter key="attribute_name" value="%{loop_attribute}"/>
    <list key="additional_macros"/>
    </operator>
    <connect from_port="example set" to_op="Extract Macro" to_port="example set"/>
    <connect from_op="Extract Macro" from_port="example set" to_port="example set"/>
    <portSpacing port="source_example set" spacing="0"/>
    <portSpacing port="sink_example set" spacing="0"/>
    <portSpacing port="sink_result 1" spacing="0"/>
    </process>
    </operator>
    <operator activated="true" class="generate_data_user_specification" compatibility="7.3.000" expanded="true" height="68" name="Extract Value of Macro" width="90" x="581" y="34">
    <list key="attribute_values">
    <parameter key="a1_average" value="%{DynamicMacro_a1_Average}"/>
    </list>
    <list key="set_additional_roles"/>
    <description align="center" color="transparent" colored="false" width="126">Select the macro you want dynamically when required.</description>
    </operator>
    <operator activated="true" class="retrieve" compatibility="7.3.000" expanded="true" height="68" name="Retrieve Iris (2)" width="90" x="45" y="391">
    <parameter key="repository_entry" value="//Samples/data/Iris"/>
    </operator>
    <operator activated="true" class="aggregate" compatibility="7.3.000" expanded="true" height="82" name="Aggregate" width="90" x="179" y="391">
    <parameter key="use_default_aggregation" value="true"/>
    <list key="aggregation_attributes"/>
    </operator>
    <operator activated="true" class="remember" compatibility="7.3.000" expanded="true" height="68" name="Remember" width="90" x="313" y="391">
    <parameter key="name" value="MyDataSet"/>
    </operator>
    <operator activated="true" class="recall" compatibility="7.3.000" expanded="true" height="68" name="Recall" width="90" x="581" y="391">
    <parameter key="name" value="MyDataSet"/>
    <parameter key="remove_from_store" value="false"/>
    <description align="center" color="transparent" colored="false" width="126">Select the value you want dynamically when required.</description>
    </operator>
    <connect from_op="Retrieve Iris" from_port="output" to_op="Loop Attributes" to_port="example set"/>
    <connect from_op="Extract Value of Macro" from_port="output" to_port="result 1"/>
    <connect from_op="Retrieve Iris (2)" from_port="output" to_op="Aggregate" to_port="example set input"/>
    <connect from_op="Aggregate" from_port="example set output" to_op="Remember" to_port="store"/>
    <connect from_op="Recall" from_port="result" to_port="result 2"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="sink_result 1" spacing="0"/>
    <portSpacing port="sink_result 2" spacing="336"/>
    <portSpacing port="sink_result 3" spacing="0"/>
    <description align="center" color="yellow" colored="false" height="69" resized="true" width="401" x="26" y="177">Method 1, Dynamically Create Macros</description>
    <description align="center" color="yellow" colored="false" height="69" resized="false" width="401" x="27" y="493">Method 2, Creating a table &amp;amp; storing in memory</description>
    </process>
    </operator>
    </process>