"[Solved]Loop Macro Values"

aryan_hosseinzaaryan_hosseinza Member Posts: 74 Contributor II
edited June 2019 in Help
Hi everybody,

I want to do a random sampling by setting a macro & looping on different values , but it seems that when I loop through the values , only the first value is applied ,

Actually as the result of the following code I want to have a multiple files each containing the result of the X-validation , but it only applies the first value,


Thanks ,
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.2.008">
 <context>
   <input/>
   <output/>
   <macros/>
 </context>
 <operator activated="true" class="process" compatibility="5.2.008" expanded="true" name="Process">
   <process expanded="true" height="738" width="1907">
     <operator activated="true" class="read_csv" compatibility="5.2.008" expanded="true" height="60" name="Read CSV" width="90" x="514" y="120">
       <parameter key="csv_file" value="/home/arian/RM/result/dataSet_Nominal_10PercentRandomSample"/>
       <parameter key="column_separators" value=","/>
       <parameter key="date_format" value="yyyy-MM-dd HH:mm:ss"/>
       <list key="annotations"/>
       <list key="data_set_meta_data_information"/>
     </operator>
     <operator activated="true" class="loop_parameters" compatibility="5.2.008" expanded="true" height="76" name="Loop Parameters" width="90" x="1251" y="120">
       <list key="parameters">
         <parameter key="Set Macro.value" value=" 0.1315,0.19725,0.263,0.32875,0.3945,0.46025,0.526"/>
       </list>
       <parameter key="parallelize_subprocess" value="true"/>
       <process expanded="true" height="602" width="895">
         <operator activated="true" class="set_macro" compatibility="5.2.008" expanded="true" height="76" name="Set Macro" width="90" x="112" y="30">
           <parameter key="macro" value="%{r}"/>
         </operator>
         <operator activated="true" class="x_validation" compatibility="5.2.008" expanded="true" height="112" name="Validation" width="90" x="313" y="30">
           <parameter key="number_of_validations" value="3"/>
           <parameter key="use_local_random_seed" value="true"/>
           <parameter key="parallelize_training" value="true"/>
           <parameter key="parallelize_testing" value="true"/>
           <process expanded="true" height="620" width="951">
             <operator activated="true" class="multiply" compatibility="5.2.008" expanded="true" height="94" name="Multiply" width="90" x="45" y="30"/>
             <operator activated="true" class="filter_examples" compatibility="5.2.008" expanded="true" height="76" name="Filter Examples" width="90" x="246" y="30">
               <parameter key="condition_class" value="attribute_value_filter"/>
               <parameter key="parameter_string" value="event=f"/>
             </operator>
             <operator activated="true" class="sample" compatibility="5.2.008" expanded="true" height="76" name="DownSample" width="90" x="380" y="30">
               <parameter key="sample" value="relative"/>
               <parameter key="sample_ratio" value="%{r}"/>
               <list key="sample_size_per_class"/>
               <list key="sample_ratio_per_class"/>
               <list key="sample_probability_per_class"/>
               <parameter key="use_local_random_seed" value="true"/>
             </operator>
             <operator activated="true" class="filter_examples" compatibility="5.2.008" expanded="true" height="76" name="Filter Examples (2)" width="90" x="179" y="390">
               <parameter key="condition_class" value="attribute_value_filter"/>
               <parameter key="parameter_string" value="event=t"/>
             </operator>
             <operator activated="true" class="append" compatibility="5.2.008" expanded="true" height="94" name="Append" width="90" x="581" y="390"/>
             <operator activated="true" class="naive_bayes" compatibility="5.2.008" expanded="true" height="76" name="Naive Bayes" width="90" x="782" y="390"/>
             <connect from_port="training" to_op="Multiply" to_port="input"/>
             <connect from_op="Multiply" from_port="output 1" to_op="Filter Examples" to_port="example set input"/>
             <connect from_op="Multiply" from_port="output 2" to_op="Filter Examples (2)" to_port="example set input"/>
             <connect from_op="Filter Examples" from_port="example set output" to_op="DownSample" to_port="example set input"/>
             <connect from_op="DownSample" from_port="example set output" to_op="Append" to_port="example set 1"/>
             <connect from_op="Filter Examples (2)" from_port="example set output" to_op="Append" to_port="example set 2"/>
             <connect from_op="Append" from_port="merged set" to_op="Naive Bayes" to_port="training set"/>
             <connect from_op="Naive Bayes" from_port="model" to_port="model"/>
             <portSpacing port="source_training" spacing="0"/>
             <portSpacing port="sink_model" spacing="0"/>
             <portSpacing port="sink_through 1" spacing="0"/>
           </process>
           <process expanded="true" height="620" width="431">
             <operator activated="true" class="apply_model" compatibility="5.2.008" expanded="true" height="76" name="Apply Model" width="90" x="45" y="30">
               <list key="application_parameters"/>
             </operator>
             <operator activated="true" class="performance_binominal_classification" compatibility="5.2.008" expanded="true" height="76" name="Performance" width="90" x="238" y="30">
               <parameter key="accuracy" value="false"/>
               <parameter key="AUC" value="true"/>
               <parameter key="f_measure" value="true"/>
               <parameter key="false_positive" value="true"/>
               <parameter key="false_negative" value="true"/>
               <parameter key="true_positive" value="true"/>
               <parameter key="true_negative" value="true"/>
             </operator>
             <connect from_port="model" to_op="Apply Model" to_port="model"/>
             <connect from_port="test set" to_op="Apply Model" to_port="unlabelled data"/>
             <connect from_op="Apply Model" from_port="labelled data" to_op="Performance" to_port="labelled data"/>
             <connect from_op="Performance" from_port="performance" to_port="averagable 1"/>
             <portSpacing port="source_model" spacing="0"/>
             <portSpacing port="source_test set" spacing="0"/>
             <portSpacing port="source_through 1" spacing="0"/>
             <portSpacing port="sink_averagable 1" spacing="0"/>
             <portSpacing port="sink_averagable 2" spacing="0"/>
           </process>
         </operator>
         <operator activated="true" class="write_as_text" compatibility="5.2.008" expanded="true" height="76" name="Write as Text" width="90" x="581" y="30">
           <parameter key="result_file" value="/home/arian/Desktop/results_downsampling_Dec_5th/result_%{r}"/>
         </operator>
         <connect from_port="input 1" to_op="Set Macro" to_port="through 1"/>
         <connect from_op="Set Macro" from_port="through 1" to_op="Validation" to_port="training"/>
         <connect from_op="Validation" from_port="averagable 1" to_op="Write as Text" to_port="input 1"/>
         <connect from_op="Write as Text" from_port="input 1" to_port="result 1"/>
         <portSpacing port="source_input 1" spacing="0"/>
         <portSpacing port="source_input 2" spacing="0"/>
         <portSpacing port="sink_performance" spacing="0"/>
         <portSpacing port="sink_result 1" spacing="0"/>
         <portSpacing port="sink_result 2" spacing="0"/>
       </process>
     </operator>
     <connect from_op="Read CSV" from_port="output" to_op="Loop Parameters" to_port="input 1"/>
     <connect from_op="Loop Parameters" from_port="result 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>

Answers

  • SkirzynskiSkirzynski Member Posts: 164 Maven
    The error is in the "Set Macro" operator. The parameter "macro" has to be set without the "%{" and "}" but only "r". What happens behind the curtain is that the first iteration sets the value for the macro "r" correctly (the % and the curly brackets will be ignored here, because no macro with the name "r" is known), but in the second iterations the macro in the parameter "macro" will be replaced by the value of the macro "r" from first iteration. So in the end you will set "r" to the first value in the "Loop Parameters" operator and the last value to a macro with the name of your first value.

    To put it in a nutshell, replace "%{r}" with "r" in the "Set Macro" operator.
  • aryan_hosseinzaaryan_hosseinza Member Posts: 74 Contributor II
    Thanks , It works ! :)
Sign In or Register to comment.