Pages: [1]
  Print  
Author Topic: Compute rank within subgroups  (Read 2628 times)
keith
Full Member
***
Posts: 160


« on: November 20, 2008, 05:51:28 PM »

Is there an operator that will compute the rank of each row according to some attribute value?  If so, is it possible to do so for subgroups within an example set?

e.g.  Compute RANK based on VALUE within each GRP group

Code:
GRP ID   VALUE   RANK
1   a    5       1
1   b    10      2
1   c    20      3
2   d    7       1
2   e    50      2
2   f    51      3
 

Thanks.
Keith
Logged
Ingo Mierswa
Administrator
Hero Member
*****
Posts: 1226



WWW
« Reply #1 on: November 20, 2008, 06:55:53 PM »

Hi Keith,

not a single operator but you could use a combination of several operators (I am talking about the upcoming release 4.3 here):

- value iterator to iterate over the groups
- example filter to filter out only the current group
- sorting to build the rank
- id taggin to give numbers for the ranks
- io retriever to retrieve last result
- example set merge to merge the current group ranking with the last one (retrieved)
- io storer to store the current result again in the store

It's will be a nice process for such a "simple" task  Wink

Cheers,
Ingo
Logged

Did you try our new Marketplace? Upload or download new Extensions, add comments, and organize your operators. Have a look at  http://marketplace.rapid-i.com
jan87
Newbie
*
Posts: 14


« Reply #2 on: December 19, 2012, 05:16:09 PM »

Hello,

I 've got exactly the same problem like Keith.

Is there meanwhile any simpler solution to solve this?

If not: Would you mind to post an example process with the described solution?

Thanks a lot,
Jan
Logged
Marius
Administrator
Hero Member
*****
Posts: 1794



WWW
« Reply #3 on: January 11, 2013, 10:22:20 AM »

Well, now it's doable with only 5 operators oO

Here you go!

Best regards, Marius

Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.3.000">
  <context>
    <input/>
    <output/>
    <macros/>
  </context>
  <operator activated="true" class="process" compatibility="5.3.000" expanded="true" name="Process">
    <process expanded="true" height="549" width="701">
      <operator activated="true" class="subprocess" compatibility="5.3.000" expanded="true" height="76" name="Generate Data (3)" width="90" x="45" y="30">
        <process expanded="true" height="531" width="550">
          <operator activated="true" class="generate_data" compatibility="5.3.000" expanded="true" height="60" name="Generate Data" width="90" x="45" y="30">
            <parameter key="number_examples" value="5"/>
            <parameter key="number_of_attributes" value="1"/>
          </operator>
          <operator activated="true" class="generate_attributes" compatibility="5.3.000" expanded="true" height="76" name="Generate Attributes" width="90" x="179" y="30">
            <list key="function_descriptions">
              <parameter key="grp" value="&quot;1&quot;"/>
            </list>
          </operator>
          <operator activated="true" class="generate_data" compatibility="5.3.000" expanded="true" height="60" name="Generate Data (2)" width="90" x="45" y="120">
            <parameter key="number_examples" value="4"/>
            <parameter key="number_of_attributes" value="1"/>
          </operator>
          <operator activated="true" class="generate_attributes" compatibility="5.3.000" expanded="true" height="76" name="Generate Attributes (2)" width="90" x="179" y="120">
            <list key="function_descriptions">
              <parameter key="grp" value="&quot;2&quot;"/>
            </list>
          </operator>
          <operator activated="true" class="append" compatibility="5.3.000" expanded="true" height="94" name="Append" width="90" x="313" y="75"/>
          <connect from_op="Generate Data" from_port="output" to_op="Generate Attributes" to_port="example set input"/>
          <connect from_op="Generate Attributes" from_port="example set output" to_op="Append" to_port="example set 1"/>
          <connect from_op="Generate Data (2)" from_port="output" to_op="Generate Attributes (2)" to_port="example set input"/>
          <connect from_op="Generate Attributes (2)" from_port="example set output" to_op="Append" to_port="example set 2"/>
          <connect from_op="Append" from_port="merged set" to_port="out 1"/>
          <portSpacing port="source_in 1" spacing="0"/>
          <portSpacing port="sink_out 1" spacing="0"/>
          <portSpacing port="sink_out 2" spacing="0"/>
        </process>
      </operator>
      <operator activated="true" class="loop_values" compatibility="5.3.000" expanded="true" height="76" name="Loop Values" width="90" x="179" y="30">
        <parameter key="attribute" value="grp"/>
        <parameter key="iteration_macro" value="grp"/>
        <process expanded="true" height="549" width="433">
          <operator activated="true" class="filter_examples" compatibility="5.3.000" expanded="true" height="76" name="Filter Examples" width="90" x="45" y="30">
            <parameter key="condition_class" value="attribute_value_filter"/>
            <parameter key="parameter_string" value="grp=%{grp}"/>
          </operator>
          <operator activated="true" class="sort" compatibility="5.3.000" expanded="true" height="76" name="Sort" width="90" x="179" y="30">
            <parameter key="attribute_name" value="att1"/>
          </operator>
          <operator activated="true" class="generate_id" compatibility="5.3.000" expanded="true" height="76" name="Generate ID" width="90" x="313" y="30"/>
          <connect from_port="example set" to_op="Filter Examples" to_port="example set input"/>
          <connect from_op="Filter Examples" from_port="example set output" to_op="Sort" to_port="example set input"/>
          <connect from_op="Sort" from_port="example set output" to_op="Generate ID" to_port="example set input"/>
          <connect from_op="Generate ID" from_port="example set output" to_port="out 1"/>
          <portSpacing port="source_example set" spacing="0"/>
          <portSpacing port="sink_out 1" spacing="0"/>
          <portSpacing port="sink_out 2" spacing="0"/>
        </process>
      </operator>
      <operator activated="true" class="append" compatibility="5.3.000" expanded="true" height="76" name="Append (2)" width="90" x="313" y="30"/>
      <connect from_op="Generate Data (3)" from_port="out 1" to_op="Loop Values" to_port="example set"/>
      <connect from_op="Loop Values" from_port="out 1" to_op="Append (2)" to_port="example set 1"/>
      <connect from_op="Append (2)" from_port="merged 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>
Logged

Please add [SOLVED] to the topic title when your problem has been solved! (do so by editing the first post in the thread and modifying the title)
Please click here before posting.
Pages: [1]
  Print  
 
Jump to: