My Math Forum  

Go Back   My Math Forum > Science Forums > Computer Science

Computer Science Computer Science Forum


Reply
 
LinkBack Thread Tools Display Modes
February 26th, 2013, 07:48 AM   #1
Newbie
 
Joined: Feb 2013

Posts: 1
Thanks: 0

Reverse recurrence relation for Third and Fourth Moment

Hello!
In this post: viewtopic.php?f=44&t=14057
I found the online algorithm for mean and variance, and most interestingly the reverse. (take a value out as if it had never been added)

Now I'm wondering about the same for Skewness and Kurtosis, (or actually just third and fourth moments).
How do you go about solving this? Do you set up some sort of recurrence relation, g(n-1) = ...?

Code:
        
public void add(double value ) {
            numEntries++;

            double delta            = value - firstMoment; //deviance?
            double deltaN           = (delta / numEntries);
            double deltaNSq         = deltaN*deltaN;
            double prevSecond       = secondMoment;
            double prevThird        = thirdMoment;

            firstMoment += deltaN;
            secondMoment += (delta * (value - firstMoment) );


            thirdMoment = thirdMoment - (3.0 * deltaN * prevSecond)
                                      + (numEntries-1) * (numEntries-2) * deltaNSq * delta;


            fourthMoment = fourthMoment - ( 4.0 * deltaN * prevThird)
                                        + (6.0 * deltaNSq * prevSecond)
                                        + ((numEntries * numEntries) - 3 * (numEntries -1)) * (deltaNSq * deltaNSq * (numEntries - 1) * numEntries);
        }
Code:
        
public void remove(double value) {
            double oldMean = firstMoment;
            firstMoment *= numEntries;
            numEntries--;

            firstMoment  = (firstMoment - value) / numEntries;
            secondMoment -= (value - oldMean)*(value - firstMoment);

            //third?
            //fourth?
        }
jerdavis is offline  
 
Reply

  My Math Forum > Science Forums > Computer Science

Tags
fourth, moment, recurrence, relation, reverse



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recurrence relation Joselynn Real Analysis 2 September 14th, 2013 12:52 AM
Recurrence relation Dragonkiller Linear Algebra 2 May 15th, 2012 10:49 AM
recurrence relation fn+4 fe phi fo Applied Math 3 December 4th, 2011 09:22 AM
recurrence relation tuzzi-i Real Analysis 1 October 6th, 2007 10:25 AM
recurrence relation fn+4 fe phi fo Real Analysis 1 December 31st, 1969 04:00 PM





Copyright © 2019 My Math Forum. All rights reserved.