Reuse the result from loop

Teja_Varanasi
Teja_Varanasi New Altair Community Member
edited November 5 in Community Q&A
Hi i am trying this 

<?xml version="1.0" encoding="UTF-8"?><process version="9.9.002">
  <context>
    <input/>
    <output/>
    <macros/>
  </context>
  <operator activated="true" class="process" compatibility="9.9.002" expanded="true" name="Process">
    <parameter key="logverbosity" value="init"/>
    <parameter key="random_seed" value="2001"/>
    <parameter key="send_mail" value="never"/>
    <parameter key="notification_email" value=""/>
    <parameter key="process_duration_for_mail" value="30"/>
    <parameter key="encoding" value="SYSTEM"/>
    <process expanded="true">
      <operator activated="true" class="set_macro" compatibility="9.9.002" expanded="true" height="68" name="Set Macro (2)" width="90" x="380" y="187">
        <parameter key="macro" value="Result"/>
        <parameter key="value" value="NA"/>
      </operator>
      <operator activated="true" class="set_macro" compatibility="9.9.002" expanded="true" height="68" name="Set Macro" width="90" x="179" y="187">
        <parameter key="macro" value="inp"/>
        <parameter key="value" value="2"/>
      </operator>
      <operator activated="true" class="read_csv" compatibility="9.9.002" expanded="true" height="68" name="Read CSV" width="90" x="112" y="85">
        <parameter key="csv_file" value="C:\Users\30763290\Desktop\SabicProject\Vendor_recomendation\try_1_vr.csv"/>
        <parameter key="column_separators" value=","/>
        <parameter key="trim_lines" value="false"/>
        <parameter key="use_quotes" value="true"/>
        <parameter key="quotes_character" value="&quot;"/>
        <parameter key="escape_character" value="\"/>
        <parameter key="skip_comments" value="true"/>
        <parameter key="comment_characters" value="#"/>
        <parameter key="starting_row" value="1"/>
        <parameter key="parse_numbers" value="true"/>
        <parameter key="decimal_character" value="."/>
        <parameter key="grouped_digits" value="false"/>
        <parameter key="grouping_character" value=","/>
        <parameter key="infinity_representation" value=""/>
        <parameter key="date_format" value=""/>
        <parameter key="first_row_as_names" value="true"/>
        <list key="annotations"/>
        <parameter key="time_zone" value="SYSTEM"/>
        <parameter key="locale" value="English (United States)"/>
        <parameter key="encoding" value="windows-1256"/>
        <parameter key="read_all_values_as_polynominal" value="false"/>
        <list key="data_set_meta_data_information">
          <parameter key="0" value="Name.true.polynominal.attribute"/>
          <parameter key="1" value="fruits.true.polynominal.attribute"/>
        </list>
        <parameter key="read_not_matching_values_as_missings" value="false"/>
      </operator>
      <operator activated="true" class="split" compatibility="9.9.002" expanded="true" height="82" name="Split" width="90" x="313" y="85">
        <parameter key="attribute_filter_type" value="all"/>
        <parameter key="attribute" value=""/>
        <parameter key="attributes" value=""/>
        <parameter key="use_except_expression" value="false"/>
        <parameter key="value_type" value="nominal"/>
        <parameter key="use_value_type_exception" value="false"/>
        <parameter key="except_value_type" value="file_path"/>
        <parameter key="block_type" value="single_value"/>
        <parameter key="use_block_type_exception" value="false"/>
        <parameter key="except_block_type" value="single_value"/>
        <parameter key="invert_selection" value="false"/>
        <parameter key="include_special_attributes" value="false"/>
        <parameter key="split_pattern" value=","/>
        <parameter key="split_mode" value="ordered_split"/>
      </operator>
      <operator activated="false" class="generate_attributes" compatibility="9.9.002" expanded="true" height="82" name="Generate Attributes (2)" width="90" x="581" y="85">
        <list key="function_descriptions">
          <parameter key="Result" value="&quot;NA&quot;"/>
        </list>
        <parameter key="keep_all" value="true"/>
      </operator>
      <operator activated="true" class="concurrency:loop_attributes" compatibility="9.9.002" expanded="true" height="82" name="Loop Attributes" width="90" x="715" y="85">
        <parameter key="attribute_filter_type" value="single"/>
        <parameter key="attribute" value="Name_1"/>
        <parameter key="attributes" value=""/>
        <parameter key="use_except_expression" value="false"/>
        <parameter key="value_type" value="attribute_value"/>
        <parameter key="use_value_type_exception" value="false"/>
        <parameter key="except_value_type" value="time"/>
        <parameter key="block_type" value="attribute_block"/>
        <parameter key="use_block_type_exception" value="false"/>
        <parameter key="except_block_type" value="value_matrix_row_start"/>
        <parameter key="invert_selection" value="true"/>
        <parameter key="include_special_attributes" value="false"/>
        <parameter key="attribute_name_macro" value="loop"/>
        <parameter key="reuse_results" value="false"/>
        <parameter key="enable_parallel_execution" value="false"/>
        <process expanded="true">
          <operator activated="false" class="handle_exception" compatibility="9.9.002" expanded="true" height="82" name="Handle Exception" width="90" x="179" y="136">
            <parameter key="exception_macro" value="%{Result}"/>
            <parameter key="add_details_to_log" value="false"/>
            <process expanded="true">
              <portSpacing port="source_in 1" spacing="0"/>
              <portSpacing port="source_in 2" spacing="0"/>
              <portSpacing port="sink_out 1" spacing="0"/>
              <portSpacing port="sink_out 2" spacing="0"/>
            </process>
            <process expanded="true">
              <operator activated="true" class="generate_attributes" compatibility="9.9.002" expanded="true" height="82" name="Generate Attributes (3)" width="90" x="45" y="34">
                <list key="function_descriptions">
                  <parameter key="Result" value="&quot;NA&quot;"/>
                </list>
                <parameter key="keep_all" value="true"/>
              </operator>
              <connect from_port="in 1" to_op="Generate Attributes (3)" to_port="example set input"/>
              <connect from_op="Generate Attributes (3)" from_port="example set output" to_port="out 1"/>
              <portSpacing port="source_in 1" spacing="0"/>
              <portSpacing port="source_in 2" spacing="0"/>
              <portSpacing port="sink_out 1" spacing="0"/>
              <portSpacing port="sink_out 2" spacing="0"/>
            </process>
          </operator>
          <operator activated="true" class="generate_attributes" compatibility="9.9.002" expanded="true" height="82" name="Generate Attributes" width="90" x="313" y="34">
            <list key="function_descriptions">
              <parameter key="Result" value="if (((%{inp})==eval(%{loop})),Name,%{Result})"/>
            </list>
            <parameter key="keep_all" value="true"/>
          </operator>
          <connect from_port="input 1" to_op="Generate Attributes" to_port="example set input"/>
          <connect from_op="Generate Attributes" from_port="example set output" to_port="output 1"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="source_input 2" spacing="0"/>
          <portSpacing port="sink_output 1" spacing="0"/>
          <portSpacing port="sink_output 2" spacing="0"/>
        </process>
      </operator>
      <connect from_op="Read CSV" from_port="output" to_op="Split" to_port="example set input"/>
      <connect from_op="Split" from_port="example set output" to_op="Loop Attributes" to_port="input 1"/>
      <connect from_op="Loop Attributes" from_port="output 1" to_port="result 1"/>
      <portSpacing port="source_input 1" spacing="0"/>
      <portSpacing port="sink_result 1" spacing="0"/>
      <portSpacing port="sink_result 2" spacing="0"/>
    </process>
  </operator>
</process>

this is the data 

Names |  Numbers
A  | 2,3
B  | 1,3,4,2
C  | 2,5
D  | 4,5
E  | 5,2 

i want to store the result in the next iteration. If I tick the reuse result i am just getting the last iteration result.

Please help here.

Answers

  • CKönig
    CKönig New Altair Community Member
    The Loop operator usually passes the same input to each iteration. So in each iteration, you would get the same full example set on the inner input port. The output of each iteration is then collected into a collection, indicated by the double line coming out of the operator.

    The "reuse results" option changes this behaviour and takes the output of the first iteration and feeds it into the second iteration as input. This way you always work on the same example set and only get the result of the last iteration as an output.

    If you want a mixture of this - working on the same example set AND keeping all the intermediate results, you will have to build your own logic there depending on your needs. One way could be a store operator inside the loop storing the intermediate results to a subfolder and using a name with the loop macro to store to separate data sets.

    Generally speaking, looping over attributes is usually not necessary. If you want to do an operation only on a subset of your data, you can always limit the scope of an operator using the "attribute filter" parameter.