Options

Cumulative average

vinothrajanvinothrajan Member Posts: 3 Contributor I
edited November 2018 in Help
Hi ..
Need to calculate cumulative average,able to do cumulative sum. But want to calculate cumulative average like below

C1 C2 C3
1    1    1
2    3    1.5
3    6    2

here C1 - real value,c2 cumulative sum,c3 cumulative average-which need to calculate.

thanks in advance. :)

Answers

  • Options
    qwertzqwertz Member Posts: 130 Contributor II

    Hi,

    so if I get you right, you have already C1 and C2 as an example set. In this case you can simply use "generate attributes" to calculate C3.
    In case you don't have C2 you can use loop operator to generate is as well.

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="6.0.008">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="6.0.008" expanded="true" name="Process">
        <process expanded="true">
          <operator activated="true" class="generate_data" compatibility="6.0.008" expanded="true" height="60" name="Generate Data" width="90" x="45" y="30">
            <parameter key="number_examples" value="10"/>
          </operator>
          <operator activated="true" class="generate_attributes" compatibility="6.0.008" expanded="true" height="76" name="Generate Attributes" width="90" x="179" y="30">
            <list key="function_descriptions">
              <parameter key="C3" value="att2/att1"/>
            </list>
          </operator>
          <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_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>

    Cheers
    Sachs
  • Options
    vinothrajanvinothrajan Member Posts: 3 Contributor I
    thanks for your reply, but in code you mentioned like c3=c2/c1. Let me explain my example more clear. Need to calculate cumulative average for below values.

    input:
    ?
    ?
    77841
    11992369
    782045.444
    4690112.111
    176680.111
    --------------------------

    output:

    ?
    ?
    77841
    6035105 <== ((77841+11992369)/2)
    4284085.148 <== ((77841+11992369+782045.444)/3)
    4385591.88875 <== ((77841+11992369+782045.444+4690112.111)/4)
    176680.111
  • Options
    qwertzqwertz Member Posts: 130 Contributor II
    Ok, got your point. Have a look to this post here: http://rapid-i.com/rapidforum/index.php/topic,5413.0.html
    It shows how to loop (iterate) through an attribute (column) and write the difference of two proximate data values to a new attribute.
    As this is quite similar to your question and provides all the tools (macros, loop, etc.) you need I hope that you can easily adapt it.
    In case you still have troubles go as far as you can get and post your code here.

    Cheers
    Sachs
Sign In or Register to comment.