Traverse and operate an ExampleSet
Xannix
New Altair Community Member
Hi everyone!
I would like to multiply each value of attribute subset (Att2 - Att10) by value of other attribute (Att1), in a multiple exampleset:
For example:
Att1 Att2 Att3 .... Att10
1 2 2 3
2 3 2 1
3 1 2 1
2 2 1 2
will be:
Att1 Att2 Att3 .... Att10
1 2 2 3
2 6 4 2
3 3 6 3
2 4 2 4
I've worked with macros in this way:
Loop Examples -> Loop Attributes -> Set Data
I'm not sure if this is efficient, does anyone has a better solution?
Thanks !!! ; )
I would like to multiply each value of attribute subset (Att2 - Att10) by value of other attribute (Att1), in a multiple exampleset:
For example:
Att1 Att2 Att3 .... Att10
1 2 2 3
2 3 2 1
3 1 2 1
2 2 1 2
will be:
Att1 Att2 Att3 .... Att10
1 2 2 3
2 6 4 2
3 3 6 3
2 4 2 4
I've worked with macros in this way:
Loop Examples -> Loop Attributes -> Set Data
I'm not sure if this is efficient, does anyone has a better solution?
Thanks !!! ; )
Tagged:
0
Answers
-
I've donne in this way, does anyone has a better solution?
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.0">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.0.8" expanded="true" name="Process">
<process expanded="true" height="414" width="758">
<operator activated="true" class="generate_data" compatibility="5.0.8" expanded="true" height="60" name="Generate Data" width="90" x="45" y="30"/>
<operator activated="true" class="loop_examples" compatibility="5.0.8" expanded="true" height="76" name="Loop Examples" width="90" x="179" y="30">
<parameter key="iteration_macro" value="fila"/>
<process expanded="true" height="404" width="299">
<operator activated="true" class="extract_macro" compatibility="5.0.8" expanded="true" height="60" name="Extract Macro (2)" width="90" x="45" y="30">
<parameter key="macro" value="att1"/>
<parameter key="macro_type" value="data_value"/>
<parameter key="attribute_name" value="att1"/>
<parameter key="example_index" value="%{fila}"/>
</operator>
<operator activated="true" class="loop_attributes" compatibility="5.0.8" expanded="true" height="60" name="Loop Attributes" width="90" x="179" y="30">
<parameter key="attribute_filter_type" value="subset"/>
<parameter key="attributes" value="att2|att4|att3|att5"/>
<parameter key="iteration_macro" value="columna"/>
<process expanded="true" height="404" width="433">
<operator activated="true" class="extract_macro" compatibility="5.0.8" expanded="true" height="60" name="Extract Macro (3)" width="90" x="45" y="30">
<parameter key="macro" value="att"/>
<parameter key="macro_type" value="data_value"/>
<parameter key="attribute_name" value="%{columna}"/>
<parameter key="example_index" value="%{fila}"/>
</operator>
<operator activated="true" class="generate_macro" compatibility="5.0.8" expanded="true" height="76" name="Generate Macro" width="90" x="179" y="30">
<list key="function_descriptions">
<parameter key="resultado" value="if (%{att}>0, %{att1}*%{att}, %{att})"/>
</list>
</operator>
<operator activated="true" class="set_data" compatibility="5.0.8" expanded="true" height="76" name="Set Data" width="90" x="313" y="30">
<parameter key="attribute_name" value="%{columna}"/>
<parameter key="example_index" value="%{fila}"/>
<parameter key="value" value="%{resultado}"/>
</operator>
<connect from_port="example set" to_op="Extract Macro (3)" to_port="example set"/>
<connect from_op="Extract Macro (3)" from_port="example set" to_op="Generate Macro" to_port="through 1"/>
<connect from_op="Generate Macro" from_port="through 1" to_op="Set Data" to_port="example set input"/>
<connect from_op="Set Data" from_port="example set output" to_port="example set"/>
<portSpacing port="source_example set" spacing="0"/>
<portSpacing port="sink_example set" spacing="0"/>
</process>
</operator>
<connect from_port="example set" to_op="Extract Macro (2)" to_port="example set"/>
<connect from_op="Extract Macro (2)" from_port="example set" to_op="Loop Attributes" to_port="example set"/>
<connect from_op="Loop Attributes" 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_output 1" spacing="0"/>
</process>
</operator>
<connect from_op="Generate Data" from_port="output" to_op="Loop Examples" to_port="example set"/>
<connect from_op="Loop Examples" from_port="example set" 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>0 -
Hola Xannix!
You can also do it like this ..<?xml version="1.0" encoding="UTF-8" standalone="no"?>
You'll need to tidy up the attribute names etc., but you get the idea.
<process version="5.0">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.0.8" expanded="true" name="Process">
<process expanded="true" height="414" width="758">
<operator activated="true" class="generate_data" compatibility="5.0.8" expanded="true" height="60" name="Generate Data" width="90" x="45" y="30"/>
<operator activated="true" class="generate_products" compatibility="5.0.8" expanded="true" height="76" name="Generate Products" width="90" x="246" y="30">
<parameter key="first_attribute_name" value="att1"/>
<parameter key="second_attribute_name" value="att5|att4|att3|att2"/>
</operator>
<connect from_op="Generate Data" from_port="output" to_op="Generate Products" to_port="example set input"/>
<connect from_op="Generate Products" from_port="example set output" 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>
Good weekend0 -
Que bueno!
That's good for multiply like my example, but if it's more complicated funtion, Is it correct my way?
Thanks a lot Haddock : )0 -
Hola,
Good questions always have fuzzy answers On the one hand you correctly adjust the correct numbers, actually only the positive ones I think, on the other hand you need to be aware that you are altering the underlying data, and not just providing a formula evaluation upon it as when you apply an operator. That means of course that the original data gets consumed, so although you can alter the data you can't show that you have, unless of course you make a copy, and not just a memory copy, as the following shows.Is it correct my way? <?xml version="1.0" encoding="UTF-8" standalone="no"?>
All in all quite interesting really!
<process version="5.0">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.0.8" expanded="true" name="Process">
<process expanded="true" height="415" width="840">
<operator activated="true" class="generate_data" compatibility="5.0.8" expanded="true" height="60" name="Generate Data" width="90" x="45" y="30"/>
<operator activated="true" class="multiply" compatibility="5.0.8" expanded="true" height="130" name="Multiply (2)" width="90" x="179" y="120"/>
<operator activated="true" class="write_csv" compatibility="5.0.8" expanded="true" height="60" name="Write CSV" width="90" x="313" y="120">
<parameter key="csv_file" value="file"/>
<parameter key="quote_nominal_values" value="false"/>
</operator>
<operator activated="true" class="remember" compatibility="5.0.8" expanded="true" height="60" name="Remember" width="90" x="313" y="30">
<parameter key="name" value="ori"/>
<parameter key="io_object" value="ExampleSet"/>
</operator>
<operator activated="true" class="recall" compatibility="5.0.8" expanded="true" height="60" name="Recall" width="90" x="447" y="345">
<parameter key="name" value="ori"/>
<parameter key="io_object" value="ExampleSet"/>
<parameter key="remove_from_store" value="false"/>
</operator>
<operator activated="true" class="read_csv" compatibility="5.0.8" expanded="true" height="60" name="Read CSV" width="90" x="313" y="300">
<parameter key="file_name" value="file"/>
<parameter key="column_separators" value=";"/>
</operator>
<operator activated="true" class="loop_examples" compatibility="5.0.8" expanded="true" height="76" name="Loop Examples" width="90" x="313" y="210">
<parameter key="iteration_macro" value="fila"/>
<process expanded="true" height="404" width="299">
<operator activated="true" class="extract_macro" compatibility="5.0.8" expanded="true" height="60" name="Extract Macro (2)" width="90" x="45" y="30">
<parameter key="macro" value="att1"/>
<parameter key="macro_type" value="data_value"/>
<parameter key="attribute_name" value="att1"/>
<parameter key="example_index" value="%{fila}"/>
</operator>
<operator activated="true" class="loop_attributes" compatibility="5.0.8" expanded="true" height="60" name="Loop Attributes" width="90" x="179" y="30">
<parameter key="attribute_filter_type" value="subset"/>
<parameter key="attributes" value="att2|att4|att3|att5"/>
<parameter key="iteration_macro" value="columna"/>
<process expanded="true" height="404" width="815">
<operator activated="true" class="extract_macro" compatibility="5.0.8" expanded="true" height="60" name="Extract Macro (3)" width="90" x="45" y="30">
<parameter key="macro" value="att"/>
<parameter key="macro_type" value="data_value"/>
<parameter key="attribute_name" value="%{columna}"/>
<parameter key="example_index" value="%{fila}"/>
</operator>
<operator activated="true" class="generate_macro" compatibility="5.0.8" expanded="true" height="76" name="Generate Macro" width="90" x="179" y="30">
<list key="function_descriptions">
<parameter key="resultado" value="if (%{att}>0, %{att1}*%{att}, %{att})"/>
</list>
</operator>
<operator activated="true" class="set_data" compatibility="5.0.8" expanded="true" height="76" name="Set Data" width="90" x="313" y="30">
<parameter key="attribute_name" value="%{columna}"/>
<parameter key="example_index" value="%{fila}"/>
<parameter key="value" value="%{resultado}"/>
</operator>
<operator activated="true" class="provide_macro_as_log_value" compatibility="5.0.8" expanded="true" height="76" name="Provide Macro as Log Value" width="90" x="45" y="120">
<parameter key="macro_name" value="fila"/>
</operator>
<operator activated="true" class="provide_macro_as_log_value" compatibility="5.0.8" expanded="true" height="76" name="Provide Macro as Log Value (2)" width="90" x="45" y="255">
<parameter key="macro_name" value="columna"/>
</operator>
<operator activated="true" class="provide_macro_as_log_value" compatibility="5.0.8" expanded="true" height="76" name="Provide Macro as Log Value (3)" width="90" x="246" y="255">
<parameter key="macro_name" value="resultado"/>
</operator>
<operator activated="true" class="provide_macro_as_log_value" compatibility="5.0.8" expanded="true" height="76" name="Provide Macro as Log Value (4)" width="90" x="447" y="255">
<parameter key="macro_name" value="att"/>
</operator>
<operator activated="true" class="provide_macro_as_log_value" compatibility="5.0.8" expanded="true" height="76" name="Provide Macro as Log Value (5)" width="90" x="447" y="120">
<parameter key="macro_name" value="att1"/>
</operator>
<operator activated="true" class="log" compatibility="5.0.8" expanded="true" height="76" name="Log" width="90" x="648" y="120">
<list key="log">
<parameter key="Col" value="operator.Provide Macro as Log Value.value.macro_value"/>
<parameter key="Fil" value="operator.Provide Macro as Log Value (2).value.macro_value"/>
<parameter key="Res" value="operator.Provide Macro as Log Value (3).value.macro_value"/>
<parameter key="att" value="operator.Provide Macro as Log Value (4).value.macro_value"/>
<parameter key="att1" value="operator.Provide Macro as Log Value (5).value.macro_value"/>
</list>
</operator>
<connect from_port="example set" to_op="Extract Macro (3)" to_port="example set"/>
<connect from_op="Extract Macro (3)" from_port="example set" to_op="Generate Macro" to_port="through 1"/>
<connect from_op="Generate Macro" from_port="through 1" to_op="Set Data" to_port="example set input"/>
<connect from_op="Set Data" from_port="example set output" to_op="Provide Macro as Log Value" to_port="through 1"/>
<connect from_op="Provide Macro as Log Value" from_port="through 1" to_op="Provide Macro as Log Value (2)" to_port="through 1"/>
<connect from_op="Provide Macro as Log Value (2)" from_port="through 1" to_op="Provide Macro as Log Value (3)" to_port="through 1"/>
<connect from_op="Provide Macro as Log Value (3)" from_port="through 1" to_op="Provide Macro as Log Value (4)" to_port="through 1"/>
<connect from_op="Provide Macro as Log Value (4)" from_port="through 1" to_op="Provide Macro as Log Value (5)" to_port="through 1"/>
<connect from_op="Provide Macro as Log Value (5)" from_port="through 1" to_op="Log" to_port="through 1"/>
<connect from_op="Log" from_port="through 1" to_port="example set"/>
<portSpacing port="source_example set" spacing="0"/>
<portSpacing port="sink_example set" spacing="0"/>
</process>
</operator>
<connect from_port="example set" to_op="Extract Macro (2)" to_port="example set"/>
<connect from_op="Extract Macro (2)" from_port="example set" to_op="Loop Attributes" to_port="example set"/>
<connect from_op="Loop Attributes" 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_output 1" spacing="0"/>
</process>
</operator>
<connect from_op="Generate Data" from_port="output" to_op="Multiply (2)" to_port="input"/>
<connect from_op="Multiply (2)" from_port="output 1" to_op="Remember" to_port="store"/>
<connect from_op="Multiply (2)" from_port="output 2" to_op="Write CSV" to_port="input"/>
<connect from_op="Multiply (2)" from_port="output 3" to_port="result 4"/>
<connect from_op="Multiply (2)" from_port="output 4" to_op="Loop Examples" to_port="example set"/>
<connect from_op="Recall" from_port="result" to_port="result 2"/>
<connect from_op="Read CSV" from_port="output" to_port="result 3"/>
<connect from_op="Loop Examples" from_port="example set" 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"/>
<portSpacing port="sink_result 3" spacing="0"/>
<portSpacing port="sink_result 4" spacing="0"/>
<portSpacing port="sink_result 5" spacing="0"/>
</process>
</operator>
</process>
Good weekend 8)0