Class DScore

Inherits from:
Object
Declared in:
DScore.h

Class Hierarchy

    Object
      |
      +---DScore

Class Description

The DScore class implements a score in a (discrete) distribution. The score object is updated with new values and calculates the length, the average or mean, the variance, the standard deviation, the sum and the squared sum. A score object is not a collection: the update values are not stored in the object; the state of the object is updated with the new value.

Example:
#include <stdio.h>
#include "ofc/DDiscreteDistribution.h"

int main(int argc, char *argv[])
{
  DDiscreteDistribution *dis  = [DDiscreteDistribution new];
  DListIterator         *iter;

  double d;

                                       // Setup the discrete ranges
  for (d = 0.0; d < 5.0; d += 0.5)
  {
    [dis range :d :d+0.5];
  }

                                       // Set the values for the distribution
  if (![dis update :0.1]) printf("Value 0.1 is not valid for the distribution.\n");
  if (![dis update :4.2]) printf("Value 4.2 is not valid for the distribution.\n");
  if (![dis update :3.6]) printf("Value 4.2 is not valid for the distribution.\n");
  if (![dis update :2.2]) printf("Value 4.2 is not valid for the distribution.\n");
  if (![dis update :0.5]) printf("Value 4.2 is not valid for the distribution.\n");
  if (![dis update :3.0]) printf("Value 4.2 is not valid for the distribution.\n");
  if (![dis update :2.1]) printf("Value 4.2 is not valid for the distribution.\n");
  if (![dis update :4.9]) printf("Value 4.2 is not valid for the distribution.\n");

                                       // Calculate some numbers
  printf("Number of values in the distribution:%d.\n", [dis length]);
  printf("Sum    of values in the distribution:%.1f.\n", [dis sum]);
  printf("SqSum  of values in the distribution:%.1f.\n", [dis sumSquared]);
  printf("Mean   of values in the distribution:%.1f.\n", [dis mean]);
  printf("StdDev of values in the distribution:%.1f.\n", [dis standardDeviation]);

                                       // Scores iterator
  iter = [dis scores];
  if (iter != nil)
  {
    DScore *sc = [iter first];

    while (sc != nil)
    {
      printf("Score:[%.1f-%0.1f] sum:%.1f sq-sum:%.1f perc:%.1f%%.\n",
             [sc min], [sc max], [sc sum], [sc sumSquared], [sc percentage]);
      sc = [iter next];
    }
  }
  else
    printf("No scores in the distribution ?!\n");

  [iter free];
  [dis  free];                         // Cleanup

  return 0;
}
Last modified:
24-Jul-2008 (DScore.h)

Instance Variables

private long _length
the number of values in the object
private double _min
the minimum value of the range
private double _max
the maximum value of the range
private double _sum
the sum of the values
private double _sumSquared
the sum of the squared values
private double _percentage
the percentage of this score in the distribution (0.0 .. 100.0)

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0