RapidMiner

RapidMiner

Nested macros

Regular Contributor

Nested macros

Hi!

I have an example set with different attributes and a class. For all regular attributes I want to calculate the average of examples labled false. Then I want to use this averages and calculate for every example the difference to this average.

I planned to use a feature iterator (over all false examples) to calculate all averages and store them in macros. Then i wanted to use another feature iterator (over all examples) to calculate the difference in an AttributeConstruction:

<operator name="Calculate Averages" class="OperatorChain" expanded="no">
    <operator name="Work on copy" class="IOMultiplier">
        <parameter key="io_object" value="ExampleSet"/>
    </operator>
         
    <operator name="Only non-pain" class="ExampleFilter">
      <parameter key="condition_class" value="attribute_value_filter"/>
      <parameter key="parameter_string" value="pain=no"/>
    </operator>

    <operator name="For All Distances and Angles" class="FeatureIterator" expanded="no">
        <parameter key="filter" value="dist.*|angle.*"/>
       
        <operator name="Calculate Average" class="DataMacroDefinition">
            <parameter key="macro" value="avg_%{loop_feature}"/>
            <parameter key="macro_type" value="statistics"/>
            <parameter key="attribute_name" value="%{loop_feature}"/>
        </operator>
               
    </operator>
           
    <operator name="Delete Copy" class="IOConsumer">
          <parameter key="io_object" value="ExampleSet"/>
                <parameter key="deletion_type" value="delete_one"/>
      </operator>
</operator>
       
<operator name="Calculate Relations" class="OperatorChain" expanded="yes">
     
    <operator name="For All Distances and Angles (2)" class="FeatureIterator" expanded="yes">
        <parameter key="filter" value="whatever.*"/>
        <parameter key="work_on_input" value="false"/>
               
            <operator name="AttributeConstruction" class="AttributeConstruction">
                <list key="function_descriptions">
                      <parameter key="%{loop_feature}_Quotient" value="%{avg_%{loop_feature}}"/>
                </list>
              </operator>
      </operator>
</operator>


The problem is this line:
<parameter key="%{loop_feature}_Quotient"	value="%{avg_%{loop_feature}}"/>
I get an UserError: SyntaxError. By now I know that is is obviously not possible to have an macro in a macro name. How can I come over this problem?

I would also be happy about a totally different solution. (Please consider that I'm dealing with about 4000 attributes which are not known jet. So assigning individual names is not possible).
1 REPLY
Elite

Re: Nested macros

Hi,
here's a total different solution Smiley Happy This way it should work, if you adapt the following process onto your needs.

<operator name="Root" class="Process" expanded="yes">
  <operator name="ExampleSetGenerator" class="ExampleSetGenerator">
      <parameter key="target_function"    value="sum"/>
  </operator>
  <operator name="FeatureIterator" class="FeatureIterator" expanded="yes">
      <parameter key="work_on_input"    value="false"/>
      <operator name="Aggregation" class="Aggregation">
          <list key="aggregation_attributes">
            <parameter key="%{loop_feature}"    value="average"/>
          </list>
      </operator>
      <operator name="DataMacroDefinition" class="DataMacroDefinition">
          <parameter key="macro"    value="current_average"/>
          <parameter key="macro_type"    value="data_value"/>
          <parameter key="attribute_name"    value="average(%{loop_feature})"/>
          <parameter key="example_index"    value="1"/>
      </operator>
      <operator name="IOConsumer" class="IOConsumer">
          <parameter key="io_object"    value="ExampleSet"/>
          <parameter key="deletion_type"    value="delete_one"/>
      </operator>
      <operator name="AttributeConstruction" class="AttributeConstruction">
          <list key="function_descriptions">
            <parameter key="norm_%{loop_feature}"    value="%{loop_feature} - %{current_average}"/>
          </list>
      </operator>
  </operator>
</operator>


Greetings,
  Sebastian
Old World Computing - Establishing the Future

Check out the Jackhammer Extension for RapidMiner! Crunch more data easier and with up to 700% speed up! Available only here