Extreme Optimization™: Complexity made simple.

Numerical Components
for .NET

  • Home
  • Features
    • Math Library
    • Vector and Matrix Library
    • Statistics Library
    • Performance
    • Usability
  • Documentation
    • Introduction
    • Math Library User's Guide
    • Vector and Matrix Library User's Guide
    • Statistics Library User's Guide
    • Reference
  • Resources
    • Downloads
    • QuickStart Samples
    • Sample Applications
    • Frequently Asked Questions
    • Technical Support
  • Blog
  • Order
  • Company
    • About us
    • Testimonials
    • Customers
    • Press Releases
    • Careers
    • Contact us
Introduction
Deployment Guide
Using Parallelism
Expand Mathematics Library User's GuideMathematics Library User's Guide
Expand Vector and Matrix Library User's GuideVector and Matrix Library User's Guide
Expand Statistics Library User's GuideStatistics Library User's Guide
Expand ReferenceReference
  • Home
    • Features
    • Solutions
    • Documentation
    • QuickStart Samples
    • Sample Applications
    • Downloads
    • Technical Support
    • Download trial
    • How to buy
    • Blog
    • Company
    • Resources
  • Documentation
    • Introduction
    • Deployment Guide
    • Using Parallelism
    • Mathematics Library User's Guide
    • Vector and Matrix Library User's Guide
    • Statistics Library User's Guide
    • Reference
  • Statistics Library User's Guide
    • Statistical Variables
    • Continuous Variables
    • Categorical Variables
    • Variable Collections
    • General Linear Models
    • Regression Analysis
    • Analysis of Variance
    • Time Series Analysis
    • Multivariate Analysis
    • Continuous Distributions
    • Discrete Distributions
    • Multivariate Distributions
    • Hypothesis Tests
    • Histograms
    • Random Numbers
    • Appendices
  • Categorical Variables
    • Categorical Scales
    • Numerical Scales
    • Time Scales
    • Categorical Variables
  • Numerical Scales
Collapse image Expand Image Copy image CopyHover image
         




Numerical Scales

It is often necessary to group numerical data into categories. The range of the data is divided into a number of intervals, where each interval becomes a category in a numerical scale. This type of numerical scale is implemented by the NumericalScale class. This class inherits from CategoricalScale, but provides some additional functionality.

Constructing Numerical Scales

The NumericalScale class has four constructors. They come in two pairs, each pair offering one way of defining the intervals that make up the scale.

The first constructor takes one argument: a Double array that contains the boundaries of the intervals. The values in this array must be in ascending order, or an ArgumentException will be thrown.

C#  Copy imageCopy
double[] bounds = new double[] {50, 62, 74, 88, 100};
NumericalScale scale1 = new NumericalScale(bounds);
Visual Basic  Copy imageCopy
Dim bounds As Double() = New Double() {50, 62, 74, 88, 100}
Dim scale1 As NumericalScale = New NumericalScale(bounds)

The second constructor also has a Double array as its first argument, but has one additional argument: a SpecialBins value that specifies which special intervals to include in the scale.

The possible values are as follows:
Values of the SpecialBins enumeration.

Name

TH

None

No special intervals are included.

BelowMinimum

There is a special interval for values below the scale's minimum value.

AboveMaximum

There is a special interval for values above the scale's maximum value.

OutOfRange

There is a special interval for values that are outside the scale's range.

Missing

There is a special interval for missing values.

If BelowMinimum is included, an interval with lower bound Double.NegativeInfinity is inserted before all other intervals. If AboveMaximum is included, an interval with upper bound Double.PositiveInfinity is added at the end. The following creates a scale with the same boundaries as above, but with an extra interval to hold values less than 50:

C# Copy imageCopy
double[] bounds = new double[] {50, 62, 74, 88, 100};
NumericalScale scale2 = new NumericalScale(bounds, SpecialBins.BelowMinimum);
Visual Basic Copy imageCopy
Dim bounds As Double() = New Double() {50, 62, 74, 88, 100}
Dim scale2 As NumericalScale = New NumericalScale(bounds, SpecialBins.BelowMinimum)

The third constructor takes three arguments. The first two are the lower bound of the first interval, and the upper bound of the last interval. The third argument is the total number of intervals. This creates a scale with the specified number of intervals that are all equal in width. The fourth constructor has one additional argument: a SpecialBins value that indicates which special values should be tabulated in addition to those within the specified interval.

The code below creates a scale with five intervals for values between 50 and 100:

C# Copy imageCopy
NumericalScale scale3 = new NumericalScale(50, 100, 5);
Visual Basic Copy imageCopy
Dim scale3 As NumericalScale = New NumericalScale(50, 100, 5)

Properties and Methods

The Count property returns the number of intervals in the scale. The IsOrdered property indicates whether the scale is ordered or unordered. It always returns true.

The GetBounds()()()() method returns a Double array containing the boundaries of the intervals. If the BelowMinimum or AboveMaximum intervals were included, the return value includes these intervals as well.

The GetLowerBound(Int32) and GetUpperBound(Int32) methods take one argument and return the lower and upper bound of the interval with the specified index.

C#  Copy imageCopy
Console.WriteLine(scale3.GetLowerBound(2)); // Prints '70'
Console.WriteLine(scale3.GetUpperBound(2)); // Prints '80'
Visual Basic  Copy imageCopy
Console.WriteLine(scale3.GetLowerBound(2)) ' Prints '70'
Console.WriteLine(scale3.GetUpperBound(2)) ' Prints '80'

The GetCaption method returns the text label of the level at the specified level index. The GetCaptions()()()() method returns a string array containing the captions for each level.

The GetEnumerator()()()() method returns an IEnumerator object that can be used to iterate through the levels of the scale.

Mapping Values to Intervals

Numerical scales convert numbers to intervals. The Map()()()() method provides this functionality.

This method is overloaded. The first overload takes any object as its only argument. This object is converted to a number using the Convert.ToDouble method. If this conversion succeeds, the index of the interval containing the number is returned. If the number is outside the scale, -1 is returned.

The second overload takes an array of objects and returns an integer array of the indexes corresponding to those objects. Each of these methods takes an optional IFormatProvider argument that is used to convert the object value to a number.

The NumericalScale class also provides type-safe overloads. One maps a number to the index of the interval. The second takes an array and returns an array of indexes.

The example below uses the scale defined earlier. Each line of code prints the same value (1):

C#  Copy imageCopy
Console.WriteLine(scale3.Map(63.5));
Console.WriteLine(scale3.Map("63.5"));
IFormatProvider provider =    System.Globalization.CultureInfo.CreateSpecificCulture("NL-BE").NumberFormat
Console.WriteLine(scale3.Map("63,5", provider));
Visual Basic  Copy imageCopy
Console.WriteLine(scale3.Map(63.5))
Console.WriteLine(scale3.Map("63.5"))
Dim provider As IFormatProvider = _
    System.Globalization.CultureInfo.CreateSpecificCulture("NL-BE").NumberFormat
Console.WriteLine(scale3.Map("63,5", provider))

In the last line, the value is provided in a format that uses a comma as the decimal separator. The right NumberFormat is required to make the result correct.

Send comments on this topic to support@extremeoptimization.com

Copyright (c) 2004-2011 ExoAnalytics Inc.

Copyright © 2003-2013, Extreme Optimization. All rights reserved.
Extreme Optimization, Complexity made simple, M#, and M Sharp are trademarks of ExoAnalytics Inc.
Microsoft, Visual C#, Visual Basic, Visual Studio, Visual Studio.NET, and the Optimized for Visual Studio logo
are registered trademarks of Microsoft Corporation.