Blog

Archive for the ‘NMath Stats Tutorial’ Category

Calling External .NET Libraries from Excel

Wednesday, December 8th, 2010
There are many circumstances where you may need to access an external library of functions or routines from Excel.  For example, if you need a complex function such as fitting data to a surface, or portfolio optimization, that is not natively available in Excel.  There also may be a need to protect proprietary calculations by using user defined functions to process algorithms in a black box manner.  I was looking for a way to rapidly prototype some calculations without setting up a complex development environment. Harking back to the old rule of development projects of  “two out of three”, when the three metrics are fast, cheap, and quality.  On any time limited project you only can plan to achieve two metrics, never all three. Initially I like to dive in and start with fast and cheap and work my way towards quality as necessary.  So, we'll start with the quick and dirty approach to calling external libraries from Excel.

Project Setup

You must have a version of .NET Framework of 2.0 or greater.  The latest version is free from Microsoft at this link. http://www.microsoft.com/net/download.aspx. You'll also need:
  • Excel 97 or later.
  • External library assemblies that you need to access from Excel. In our case we will use Centerspace’s NMath.dll and NMathStats.dll.
  • A freeware product called ExcelDNA written by Govert van Drimmelen that can be downloaded at http://exceldna.codeplex.com/ .
The first order of business is to unpack the downloaded file, ExcelDNA.zip, into a working directory.  For our example, we will use CenterSpaceExcel as our directory name. After unpacking you should have two folders Distribution and Source in our CenterSpaceExcel directory.  Inside the Distribution folder locate the file ExcelDNA.xll and rename it to NMathExcel.xll. We now need to locate in the same directory the file ExcelDna.dna and rename it to NMathExcel.dna.  Then using notepad, or your favorite code editor, and open the file NMathExcel.dna. You should see the following code:

Assuming CenterSpace NMath and NStat are installed in the standard locations. Change it to read as follows and save:







 _
	    	Function NPower(x as double, y As double) As double
			NPower = NMath.NMathFunctions.PowFunction(x, y)
		End Function

		 _
		Function NRand() As double
			dim rand As New NMath.RandGenMTwist
			NRand = rand.Next53BitRes()
		End Function

		 _
		Function NBinomDist(NSuccess As Int32, NTrials As Int32, Prob As double, Cumul As Boolean) As double
			dim nbin As New Stats.BinomialDistribution
			nbin.N = NTrials
			nbin.P = Prob
			IF Cumul
				NBinomDist = nbin.CDF(NSuccess)
			Else
				NBinomDist = nbin.PDF(NSuccess)
			End If
		End Function

		Function NDoubleMatrixRand(rsize As integer, csize As integer, RandLBx As integer, RandUBy As integer) As Object(,)
			dim rng As New NMath.RandGenUniform(RandLBx,RandUBy)
			Rng.Reset(&H124)
			dim TempA As New NMath.DoubleMatrix(rsize, csize, Rng)
			NDoubleMatrixRand = NCopyArray(TempA, rsize, csize)

		End Function

		Function NCopyArray(IMatrix As Object, rsize As integer, csize As integer) As Object(,)
			dim i As Integer
			dim j As Integer
			dim OArray(rsize, csize) As Object
			for i = 0 to rsize - 1
			   for j = 0 to csize - 1
				OArray(i,j) = IMatrix(i,j)
			   next j
			next i
			NCopyArray = OArray
		End Function		

	End Module
]]>
We now have created the VB code to call our CenterSpace Math and Statistics libraries with the following five functions.
  1. The first function shows a simple math library call to the Power function which takes a number x and raises it to the y power and returns the value.
  2. The second function shows a call to obtain a fast random number from the math library.  Since we want a new number each time the spreadsheet is re-calculated we have made the function volatile.
  3. The third function call shows how to set values that need to be accessed by a function in our .NET assemble; in this case, the Binomial Distribution.
  4. The fourth function demonstrates the creation of a DoubleMatrix that is the filled with random uniformly distributed numbers.
  5. The fifth function is a helper sub-routine to transfer data across the com interface.

Test our setup in Excel

Open Excel and move your cursor the Tools menu item.  Usually towards the bottom of the drop down menu you will find the selection Add-Ins.  After selecting Add-Ins, you see the pop-up window with the option to select Microsoft supplied Add-ins.  Choose the Browse option and go to the working directory we created at the beginning.  In our case, this will be the CenterSpaceExcel directory.  Next select the Distribution folder and you should see the renamed file: NMathExcel.xll.  Select it and you should now see the following screen. [caption id="attachment_2899" align="alignnone" width="360" caption="Selecting a user created XLL as an Add-in for Excel"][/caption] Make sure NMathExcel is checked and click OK. If you get an error and this point it is probably due to a typo in the DNA file, otherwise you will get the expected new sheet ready for entry. Select an empty cell and then select from the menu bar Insert then from the pulldown Function.  You should see the following pop-up. [caption id="attachment_2902" align="alignnone" width="540" caption="Selecting the category containing our NMath functions"][/caption] At the bottom of the category pull down you should see our NMathExcel Functions;  Select it and you should have these options.: [caption id="attachment_2905" align="alignnone" width="540" caption="NMath Excel Function Category"][/caption] If we choose NPower, we will get the next screen, [caption id="attachment_2906" align="alignnone" width="540" caption="Calling NMath Library Power function in Excel"][/caption] I arbitrarily typed the value of 3.2 for x and 3.327 for y.  You can see the result of 47.9329301 before selecting OK. Select OK and Excel will insert the value into the cell.  Select another blank cell and this time choose our NRand() function.  You will notice there is no opportunity to enter values and finish by selecting OK.  At this point you should see a number between 0 and 1 in the cell.  Each time you press F9 (sheet recalc) a new random number will appear.  If we had not made this function volatile the number would not change unless you edit the cell. To test our Binomial Distribution function, again we will select a new cell and use the insert function option to insert the NBinomDist function with the following values. [caption id="attachment_2909" align="alignnone" width="540" caption="Calling NMath Statistical function Binomial Distribution from Excel"][/caption] At this point we have made successful calls into both of CenterSpace's NMath and NMath Stats .NET math libraries. In our fourth example, we will see how Excel handles matrices and look at issues passing array arguments across the COM interface.  Excel 2003 was limited to a maximum of 60,000 cells in an array, but Excel 2007 was expanded to handle 2 million.  Excel has some quirky ways of displaying matrices, and I'll cover the in's and out's of these quirks. We have written the basic code to set up a function called NDoubleMatrixRand for the purpose of creating a matrix with supplied dimensions and filled with uniform Random numbers over a specified distribution.  We will select another blank cell and again go to insert function and this time choose NDoubleMatrixRand.  Suppose we want to create a 6x6 matrix filled with random numbers between -2 and 2.  Our input will look like the following screen. [caption id="attachment_2910" align="alignnone" width="600" caption="Creating a DoubleMatrix in Excel using NMath"][/caption] Notice the equal sign in the middle right of the above screen is equal to {-0.994818527251482,-0.08 Values inclosed in curly brackets that are separated by commas indicates that an matrix was actually created, but you can see the Formula result is only displaying a partial value due to display size. At this point when you select OK, you will have a cell with a single value.  Here is where the fun begins.  Start at the cell and drag a 6x6 range as shown in the following screen. [caption id="attachment_2911" align="alignnone" width="564" caption="Selecting the area the matrix is to be displayed in"][/caption] Now get your fingers limbered. Here is where it gets a bit obscure - do exactly as follows.
  • Press the F2 key.  (pressing F2 may be  optional but is recommended by Excel as the cell leaves the edit mode)
  • Press and hold the Ctrl key followed by
  • pressing and holding the Shift key followed by
  • pressing the Enter key
and presto chango!  You should see a screen like this. [caption id="attachment_2913" align="alignnone" width="561" caption="Displaying a Matrix in Excel "][/caption] Notice that your cell's formula is now enclosed in { }, indicating to Excel that the contained formula is an array function.  This is the only way to get matrices displayed.  Also, if you try to edit this cell you will get an error that changes are not allowed.  If  you want to change the dimensions simply reference the values from another cell when you create the function. The fifth function NCopyArray copies the library matrix across the COM bridge into an Excel array object.  As I stated in the beginning this would be a quick and dirty approach and would leave room for improvement.

Summary

In my next post, I will provide the above code in C# and add more function calls with some matrices with hopefully an improved approach to NCopyArray.  Future posts will include creating a packaged XLL and a more complex example such as curve fitting. Since time is our most precious asset, being able to quickly access complex math functions with a general purpose tool like Excel should save time and money! At CenterSpace, we are interested if this blog is helpful and if there is a need for more examples of how our libraries can be accessed by Excel.  Let us know what areas are of interest to you. Mike  Magee Thanks and Resources Also, a special thanks to Govert van Drimmelen for writing a wonderful tool such as ExcelDNA.

Ds Bactrim

Wednesday, August 11th, 2010

Ds bactrim, Statistical quality control charts, or Shewart quality control charts, are used across nearly all sectors of industry to maintain and improve product quality. Quality control charts provide a means to detect when a time varying process exceeds its historic process variation and needs analysis and/or intervention to remedy the out-of-control process (known as special cause variation). These process control charts are independent of any engineering decision-making about the particular process at hand, bactrim hair loss, but are instead based on the statistical nature of the process itself. Chlamydia bactrim, This standardized statistical control framework was created and refined by Walter Shewart at Bell Telephone Laboratories from 1925 to his retirement in 1956. It is this independence of process details that make Mr. Shewart's techniques powerful, widely applicable, decision-making aids, ds bactrim.

With their ongoing partnership, bactrim suspension concentration, CenterSpace Software and Nevron have teamed up to create some free code examples for creating Shewart charts. Bactrim headache,

Quality Chart Types


Statistical quality control charts can be generally divided into two categories, those for tracking discrete attribute variables (e.g. a pass/fail test), bactrim otitis media, and those for tracking continuous process variables (e.g. Bactrim ds 800-160 tab, pipe diameter, temperature).
















































Chart Process Observation Process Observation Variable
X-bar and R chart Quality characteristic measurement within one subgroup Variables
X-bar and s chart Quality characteristic measurement within one subgroup Variables
Shewhart individuals control chart (I-R chart or I chart) Quality characteristic measurement for one observation Variables
Three-way chart Quality characteristic measurement within one subgroup Variables
p-chart Fraction nonconforming within one subgroup Attributes
np-chart Number nonconforming within one subgroup Attributes
c-chart Number of nonconformances within one subgroup Attributes
u-chart Nonconformances per unit within one subgroup Attributes
Ds bactrim, The statistical modeling language, "R", provides a package (qcc) for creating these and other statistical process control charts. This R package was created by Luca Scrucca and is actively maintained and can be found in CRAN repository, bactrim expiration.







[caption id="attachment_2364" align="alignleft" width="200" caption="c-chart generated by R package qcc"]c-chart generated the R package qcc[/caption]

[caption id="attachment_2365" align="alignright" width="200" caption="u-chart generated by R package qcc"]u-chart generated by the R package qcc[/caption]


These two images demonstrate the standard look of the 'c' and 'u' attribute quality control chart. Bactrim in children, Some typical chart features include the highlighting of out-of-control data points and time varying upper and lower control limits. The charts generated by the R qcc package have served as our standard for recreating these in the .NET / C# development environment. The real world data used in our examples below was copied from the qcc package so direct comparisons can be made, ds bactrim.

Creating a Quality Chart with .NET


To integrate these quality controls charts into a .NET/C# data driven quality monitoring application, buy generic bactrim, we need both a statistical analysis library and a visualization tool that can manage the special chart style demanded by quality control engineers. Bactrim manufacturer, CenterSpace, in partnership with Nevron, has created an extensible example application to build these types of specialized charts, bactrim resistance. Once you have these free helper classes, Bactrim medication, building an attribute u-chart is as simple or simpler than prototyping charts in R.
    public void UChart()
{

// u-Chart sample data
// This data-set was copied from the 'dyedcloth' data set packaged with
// the R-package qcc by Luca Scrucca
//
// Example Data Description
// In a textile finishing plant, dyed cloth is inspected for the occurrence of
// defects per 50 square meters, bactrim injection. Ds bactrim, // The data on ten rolls of cloth are presented
// x number of nonconformities per 50 square meters (inspection units)
// samplesize number of inspection units in roll (variable sample size
DoubleVector x =
new DoubleVector(14, 12, 20, 11, 7, 10, 21, 16, 19, 23);
DoubleVector samplesize =
new DoubleVector(10.0, 8.0, 13.0, 10.0, 9.5, 10.0, 12.0, 10.5, 12.0, 12.5);

// This builds the statistical information for the drawing the chart.
IAttributeChartStats stats_u = new Stats_u(x, Bactrim ds more drug_uses, samplesize);

// Build and display the Nevron u-Chart visualization
NevronControlChart.AutoRefresh = true;
NevronControlChart.Clear();
AttributeChart cChart =
new AttributeChart(stats_u, this.NevronControlChart);

}


This code creates a u-Chart that looks like this below.

[caption id="attachment_2503" align="aligncenter" width="300" caption="u-Chart, pcp bactrim, or Unit Chart"][/caption]

For those familiar with the aforementioned R-package qcc, Bactrim ds drug, these .NET/C# classes follow the same R naming convention for the particular chart statistics objects, but with an improved object model. So as seen in this example, bactrim pill, the u-chart statistics are contained in a class named Stats_u, Bactrim expiration, similar to the R stats.u command. Each of these statistical chart objects implements either an IAttributeChartStats or an IVariableChartStats interface, which is used by the chart generating class (AttributeChart) as seen in the last line of the code above, double strength bactrim.

Building control charts boils down to three steps using these example classes, ds bactrim.


  1. Build the necessary data vectors.

  2. Build the desired chart's statistics object, Bactrim used for, e.g. IAttributeChartStats Stats = new Stats_c(DoubleVector data);

  3. Show chart using Nevrons .NET chart control,
    e.g, cellulitis bactrim. new AttributeChart(IAttributeChartStats Stats, Bactrim cost, NChartControl Chart)


Free Example Code


The example code now available on github can currently create all four essential attribute quality control charts, as seen below.











[caption id="attachment_2503" align="alignnone" width="180" caption="c-Chart, another name for bactrim, or Count Chart"]
c-Chart, <b>Bactrim for sore throat</b>, or Count Chart
[/caption]

[caption id="attachment_2503" align="alignnone" width="180" caption="u-Chart, or Unit Chart"]
[/caption]

[caption id="attachment_2507" align="alignnone" width="180" caption="p-Chart, Percentage Chart"][/caption]

[caption id="attachment_2508" align="alignnone" width="180" caption="np-Chart"][/caption]


To download and run these examples just navigate to our Nevron / CenterSpace github repository and either click on the "Download Source" button in the upper right-hand corner and download either a .zip or .tar file of the project, prophylactic bactrim, or just clone the repository. Ds bactrim, For those unfamiliar with git, git is a source code control system designed specifically for collaborative projects such as this one. To clone the project, after installing git, simply type at your command prompt:
 git clone git@github.com:MilenMetodiev/CenterSpaceNevronExamples.git

This will create a clone of this project code at your current drive location in a directory call "CenterSpaceNevronExamples".

Other Quality Control Charts and Future Development


Currently we have only implemented the attribute control charts. Other common quality system charts including EWMA (exponential weighted moving average), Pareto, and CumSum (cumulative sum) have not been implemented in this example, but can be using the same tool set and class patterns established in this example. If you would like help or need any assistance in getting the project running or extending this to other chart types, drop us an email .

Happy Computing,
-Paul

Resources


  • The table above is adapted from the Wikipedia control chart article.

  • "qcc: An R package for quality control charting and statistical process control", R News, Volume 4/1 , June 2004.

  • The standard qcc documentation from the CRAN project was very helpful with this project.

.

Similar posts: Doryx buy. Vibramycin online. Vibramycin 100 mg. Doxycycline 100mg. Cheap vibramycin. Bactrim double strength.
Trackbacks from: Ds bactrim. Ds bactrim. Ds bactrim. Ds bactrim. Ds bactrim. Augmentin 875mg.

Vibramycin Buy

Monday, January 11th, 2010

Vibramycin buy, In this continuing series, we explore the NMath Stats functions for performing cluster analysis. (For previous posts, see Part 1 - PCA , Part 2 - K-Means, Vibramycin doxycycline, Part 3 - Hierarchical, and Part 4 - NMF.) The sample data set we're using classifies 89 single malt scotch whiskies on a five-point scale (0-4) for 12 flavor characteristics. To visualize the data set and clusterings, we make use of the free Microsoft Chart Controls for .NET, which provide a basic set of charts, doxycycline vibramycin.

In this post, the last in the series, we'll look at how NMath provides a Monte Carlo method for performing multiple non-negative matrix factorization (NMF) clusterings using different random starting conditions, Vibramycin suspension, and combining the results.

NMF uses an iterative algorithm with random starting values for W and H. This, coupled with the fact that the factorization is not unique, means that if you cluster the columns of V multiple times, you may get different final clusterings, vibramycin buy. The consensus matrix is a way to average multiple clusterings, to produce a probability estimate that any pair of columns will be clustered together.

To compute the consensus matrix, the columns of V are clustered using NMF n times, vibramycin drug. Each clustering yields a connectivity matrix. Recall that the connectivity matrix is a symmetric matrix whose i, jth entry is 1 if columns i and j of V are clustered together, Order vibramycin, and 0 if they are not. The consensus matrix is also a symmetric matrix, whose i, jth entry is formed by taking the average of the i, jth entries of the n connectivity matrices.

Thus, vibramycin drug, each i, jth entry of the consensus matrix is a value between 0, when columns i and j are not clustered together on any of the runs, Vibramycin suspension, and 1, when columns i and j were clustered together on all runs. Vibramycin buy, The i, jth entry of a consensus matrix may be considered, in some sense, a "probability" that columns i and j belong to the same cluster.

NMF uses an iterative algorithm with random starting values for W and H. (See Part IV for more information on NMF.) This, coupled with the fact that the factorization is not unique, means that if you cluster the columns of V multiple times, vibramycin doxycycline, you may get different final clusterings. The consensus matrix is a way to average multiple clusterings, to produce a probability estimate that any pair of columns will be clustered together. Comprare vibramycin online, To compute the consensus matrix, the columns of V are clustered using NMF n times. Each clustering yields a connectivity matrix. Recall that the connectivity matrix is a symmetric matrix whose i, jth entry is 1 if columns i and j of V are clustered together, and 0 if they are not, vibramycin buy. The consensus matrix is also a symmetric matrix, whose i, vibramycin dose, jth entry is formed by taking the average of the i, jth entries of the n connectivity matrices. The i, Doxycycline vibramycin, jth entry of a consensus matrix may be considered a "probability" that columns i and j belong to the same cluster.

NMath Stats provides class NMFConsensusMatrix for computing a consensus matrix. NMFConsensusMatrix is parameterized on the NMF update algorithm to use. Vibramycin buy, Additional constructor parameters specify the matrix to factor, the order k of the NMF factorization (the number of columns in W), and the number of clustering runs. The consensus matrix is computed at construction time, so be aware that this may be an expensive operation, vibramycin uses.

For example, the following C# code creates a consensus matrix for 100 runs, clustering the scotch data (loaded into a dataframe in Part I) into four clusters:

int k = 4;
int numberOfRuns = 100;
NMFConsensusMatrix<NMFDivergenceUpdate> consensusMatrix =
new NMFConsensusMatrix<NMFDivergenceUpdate>(
data.ToDoubleMatrix().Transpose(), Vibramycin syrup, k,
numberOfRuns);

Console.WriteLine("{0} runs out of {1} converged.",
consensusMatrix.NumberOfConvergedRuns, numberOfRuns);


The output is:
100 runs out of 100 converged.

NMFConsensusMatrix provides a standard indexer for getting the element value at a specified row and column in the consensus matrix. For instance, vibramycin chlamydia, one of the goals of Young et al. was to identify single malts that are particularly good representatives of each cluster. This information could be used, for example, to purchase a representative sampling of scotches, vibramycin buy. As described in Part IV, Vibramycin doxycycline hyclate, they reported that these whiskies were the closest to each flavor profile:

  • Glendronach and Macallan

  • Tomatin and Speyburn

  • AnCnoc and Miltonduff

  • Ardbeg and Clynelish


The consensus matrix reveals, however, that the pairings are not equally strong:
Console.WriteLine("Probability that Glendronach is clustered with Macallan = {0}",
consensusMatrix[data.IndexOfKey("Glendronach"), data.IndexOfKey("Macallan")]);
Console.WriteLine("Probability that Tomatin is clustered with Speyburn = {0}", vibramycin medication,
consensusMatrix[data.IndexOfKey("Tomatin"), data.IndexOfKey("Speyburn")]);
Console.WriteLine("Probability that AnCnoc is clustered with Miltonduff = {0}",
consensusMatrix[data.IndexOfKey("AnCnoc"), Vibramycin tablets, data.IndexOfKey("Miltonduff")]);
Console.WriteLine("Probability that Ardbeg is clustered with Clynelish = {0}",
consensusMatrix[data.IndexOfKey("Ardbeg"), data.IndexOfKey("Clynelish")]);

The output is:
Probability that Glendronach is clustered with Macallan = 1
Probability that Tomatin is clustered with Speyburn = 0.4
Probability that AnCnoc is clustered with Miltonduff = 0.86
Probability that Ardbeg is clustered with Clynelish = 1

Thus, although Glendronach and Macallan are clustered together in all 100 runs, Tomatin and Speyburn are only clustered together 40% of the time, vibramycin hyclate.

A consensus matrix, C, can itself be used to cluster objects, Generic vibramycin, by perform a hierarchical cluster analysis using the distance function:

nmf_distance_function

For example, this C# code creates an hierarchical cluster analysis using this distance function, then cuts the tree at the level of four clusters, printing out the cluster members:

DoubleMatrix colNumbers = new DoubleMatrix(consensusMatrix.Order, 1, vibramycin dosage, 0, 1);
string[] names = data.StringRowKeys;

Distance.Function distance =
delegate(DoubleVector data1, DoubleVector data2)
{
int i = (int)data1[0];
int j = (int)data2[0];
return 1.0 - consensusMatrix[i, Vibramycin for cats, j];
};

ClusterAnalysis ca = new ClusterAnalysis(colNumbers, distance, Linkage.WardFunction);

int k = 4;
ClusterSet cs = ca.CutTree(k);
for (int clusterNumber = 0; clusterNumber < cs.NumberOfClusters; clusterNumber++)
{
int[] members = cs.Cluster(clusterNumber);
Console.Write("Objects in cluster {0}: ", clusterNumber);
for (int i = 0; i < members.Length; i++)
{
Console.Write("{0} ", names[members[i]]);
}
Console.WriteLine("\n");
}


The output is:
Objects in cluster 0:
Aberfeldy Auchroisk Balmenach Dailuaine Glendronach
Glendullan Glenfarclas Glenrothes Glenturret Macallan
Mortlach RoyalLochnagar Tomore

Objects in cluster 1:
Aberlour ArranIsleOf Belvenie BenNevis Benriach Benromach
Bladnoch BlairAthol Bowmore Craigallechie Dalmore
Dalwhinnie Deanston GlenElgin GlenGarioch GlenKeith
GlenOrd Glenkinchie Glenlivet Glenlossie Inchgower
Knochando Linkwood OldFettercairn RoyalBrackla
Speyburn Teaninich Tomatin Tomintoul Tullibardine

Objects in cluster 2:
AnCnoc Ardmore Auchentoshan Aultmore Benrinnes
Bunnahabhain Cardhu Craigganmore Dufftown Edradour
GlenGrant GlenMoray GlenSpey Glenallachie Glenfiddich
Glengoyne Glenmorangie Loch Lomond Longmorn
Mannochmore Miltonduff Scapa Speyside Strathisla
Strathmill Tamdhu Tamnavulin Tobermory

Objects in cluster 3:
Ardbeg Balblair Bruichladdich Caol Ila Clynelish
GlenDeveronMacduff GlenScotia Highland Park
Isle of Jura Lagavulin Laphroig Oban OldPulteney
Springbank Talisker


Once again using the cluster assignments to color the objects in the plane of the first two principal components, vibramycin uses, we can see the grouping represented by the consensus matrix (k=4).

nmf2

Well, this concludes are tour through the NMath clustering functionality. Vibramycin chlamydia, Techniques such as principal component analysis, k-means clustering, hierarchical cluster analysis, and non-negative matrix factorization can all be applied to data such as these to explore various clusterings. Vibramycin buy, Choosing among these approaches is ultimately a matter of domain knowledge and performance requirements. Is it appropriate to cluster based on distance in the original space, vibramycin hyclate, or should dimension reduction be applied. If dimension reduction is used, are negative component parameters meaningful. Doxycycline vibramycin, Are there sufficient computational resource available to construct a complete hierarchical cluster tree, or should a k-means approach be used. If an hierarchical cluster tree is computed, what distance and linkage function should be used. NMath provides a powerful, flexible set of clustering tools for data mining and data analysis, vibramycin buy.

Ken

References

Young, S.S., Fogel, P., Hawkins, D. M. (unpublished manuscript). “Clustering Scotch Whiskies using Non-Negative Matrix Factorization”. Retrieved December 15, 2009 from http://niss.org/sites/default/files/ScotchWhisky.pdf.

Similar posts: Where to buy bactrim. Buy cheap vibramycin. Buy doryx online. Buy vibramycin. Ampicillin drug. Antibiotic ampicillin.
Trackbacks from: Vibramycin buy. Vibramycin buy. Vibramycin buy. Vibramycin buy. Vibramycin buy. Vibramycin online.

Vibramycin Online

Wednesday, January 6th, 2010

Vibramycin online, In this continuing series, we explore the NMath Stats functions for performing cluster analysis. (For previous posts, see Part 1 - PCA , Part 2 - K-Means, and Part 3 - Hierarchical.) The sample data set we're using classifies 89 single malt scotch whiskies on a five-point scale (0-4) for 12 flavor characteristics, vibramycin tablets. To visualize the data set and clusterings, we make use of the free Microsoft Chart Controls for .NET, which provide a basic set of charts. Doxycycline vibramycin, In this post, we'll cluster the scotches using non-negative matrix factorization (NMF). NMF approximately factors a matrix V into two matrices, W and H:

wh

If V in an n x m matrix, then NMF can be used to approximately factor V into an n x r matrix W and an r x m matrix H, vibramycin medication. Usually r is chosen to be much smaller than either m or n, for dimension reduction, vibramycin online. Thus, each column of V is approximated by a linear combination of the columns of W, with the coefficients being the corresponding column H. Vibramycin dosage, This extracts underlying features of the data as basis vectors in W, which can then be used for identification, clustering, and compression.

Earlier in this series, vibramycin for cats, we used principal component analysis (PCA) as a means of dimension reduction for the purposes of visualizing the scotch data. NMF differs from PCA in two important respects:


  1. NMF enforces the constraint that the factors W and H must be non-negative-that is, all elements must be equal to or greater than zero. By not allowing negative entries in W and H Vibramycin online, , NMF enables a non-subtractive combination of the parts to form a whole, and in some contexts, more meaningful basis vectors. Vibramycin uses, In the scotch data, for example, what would it mean for a scotch to have a negative value for a flavor charactistic?

  2. NMF does not require the basis vectors to be orthogonal. If we are using NMF to extract meaningful underlying components of the data, there is no a priori reason to require the components to be orthogonal.


Let's begin by reproducing the NMF analysis of the scotch data presented in Young et al., order vibramycin. The authors performed NMF with r=4, to identify four major flavor factors in scotch whiskies, and then asked whether there are single malts that appear to be relatively pure embodiments of these four flavor profiles. Doxycycline vibramycin, NMath Stats provides class NMFClustering for performing data clustering using iterative nonnegative matrix factorization (NMF), where each iteration step produces a new W and H. At each iteration, each column v of V is placed into a cluster corresponding to the column w of W which has the largest coefficient in H, vibramycin online. That is, column v of V is placed in cluster i if the entry hij in H is the largest entry in column hj of H. Results are returned as an adjacency matrix whose i, vibramycin chlamydia, jth value is 1 if columns i and j of V are in the same cluster, and 0 if they are not. Iteration stops when the clustering of the columns of the matrix V stabilizes. Comprare vibramycin online, NMFClustering is parameterized on the NMF update algorithm to use. For instance:
NMFClustering<NMFDivergenceUpdate> nmf =
new NMFClustering<NMFDivergenceUpdate>();

This specifies the divergence update Vibramycin online, algorithm, which minimizes a divergence functional related to the Poisson likelihood of generating V from W and H. (For more information, see Brunet, Jean-Philippe et al. , vibramycin doxycycline, 2004.)

The Factor() method performs the actual iterative factorization. The following C# code clusters the scotch data (loaded into a dataframe in Part I) into four clusters:

int k = 4;

// specify starting conditions (optional)
int seed = 1973;
RandGenUniform rnd = new RandGenUniform(seed);
DoubleMatrix starting_W = new DoubleMatrix(data.Cols, k, Vibramycin hyclate, rnd);
DoubleMatrix starting_H = new DoubleMatrix(k, data.Rows, rnd);

nmf.Factor(data.ToDoubleMatrix().Transpose(),
k,
starting_W, vibramycin drug,
starting_H);
Console.WriteLine("Factorization converged in {0} iterations.\n",
nmf.Iterations);


There are a couple things to note in this code:

  • By default, NMFact uses random starting values for W and H. Vibramycin tablets, This, coupled with the fact that the factorization is not unique, means that if you cluster the columns of V multiple times, you may get different final clusterings. In order to reproduce the results in Young et al. the code above specifies a particular random seed for the initial conditions.

  • The scotch data needs to be transposed before clustering, since NMFClustering requires each object to be clustered to be a column in the input matrix.


The output is:
Factorization converged in 530 iterations.

We can examine the four flavor factors (columns of W) to see what linear combination of the original flavor characteristics each represents, vibramycin online. The following code orders each factor, vibramycin dose, normalized so the largest value is 1.0, similar to the data shown in Table 1 of Young et al.:
ReproduceTable1(nmf.W, data.ColumnHeaders);

private static void ReproduceTable1(DoubleMatrix W, Vibramycin for cats, object[] rowKeys)
{
// normalize
for (int i = 0; i < W.Cols; i++)
{
W[Slice.All, i] /= NMathFunctions.MaxValue(W.Col(i));
}

// Create data frame to hold W
string[] factorNames = GetFactorNames(W.Cols);
DataFrame df_W = new DataFrame(W, factorNames);
df_W.SetRowKeys(rowKeys);

// Print out sorted columns
for (int i = 0; i < df_W.Cols; i++)
{
df_W.SortRows(new int[] { i },
new SortingType[] { SortingType.Descending });
Console.WriteLine(df_W[Slice.All, new Slice(i, vibramycin suspension, 1)]);
Console.WriteLine();
}
Console.WriteLine();
}


The output is:
#	Factor 0
Fruity 1.0000
Floral 0.8681
Sweetness 0.8292
Malty 0.6568
Nutty 0.5855
Body 0.4295
Smoky 0.2805
Honey 0.2395
Spicy 0.0000
Winey 0.0000
Tobacco 0.0000
Medicinal 0.0000

# Factor 1
Winey 1.0000
Body 0.6951
Nutty 0.5078
Sweetness 0.4257
Honey 0.3517
Malty 0.3301
Fruity 0.2949
Smoky 0.2631
Spicy 0.0000
Floral 0.0000
Tobacco 0.0000
Medicinal 0.0000

# Factor 2
Spicy 1.0000
Honey 0.4885
Sweetness 0.4697
Floral 0.4301
Smoky 0.3508
Malty 0.3492
Body 0.3160
Fruity 0.0036
Nutty 0.0000
Winey 0.0000
Tobacco 0.0000
Medicinal 0.0000

# Factor 3
Medicinal 1.0000
Smoky 0.8816
Body 0.7873
Spicy 0.3936
Sweetness 0.3375
Malty 0.3069
Nutty 0.2983
Fruity 0.2441
Tobacco 0.2128
Floral 0.0000
Winey 0.0000
Honey 0.0000


Thus:

  • Factor 0 contains Fruity, Floral, and Sweetness flavors.

  • Factor 1 emphasizes the Winey flavor.

  • Factor 2 contains Spicy and Honey flavors.

  • Factor 3 contains Medicinal and Smokey flavors.


The objects are placed into clusters corresponding to the column of W which has the largest coefficient in H. Vibramycin dosage, The following C# code prints out the contents of each cluster, ordered by largest coefficient, after normalizing so the sum of each component is 1.0:
ReproduceTable2(nmf.H, data.RowKeys, nmf.ClusterSet);

private static void ReproduceTable2(DoubleMatrix H, vibramycin syrup, object[] rowKeys, ClusterSet cs)
{
// normalize
for (int i = 0; i < H.Rows; i++)
{
H[i, Slice.All] /= NMathFunctions.Sum(H.Row(i));
}

// Create data frame to hold H
string[] factorNames = GetFactorNames(H.Rows);
DataFrame df_H = new DataFrame(H.Transpose(), Generic vibramycin, factorNames);
df_H.SetRowKeys(rowKeys);

// Print information on each cluster
for (int clusterNumber = 0; clusterNumber < cs.NumberOfClusters; clusterNumber++)
{
int[] members = cs.Cluster(clusterNumber);
int factor = NMathFunctions.MaxIndex(H.Col(members[0]));
Console.WriteLine("Cluster {0} ordered by {1}: ", clusterNumber, factorNames[factor]);

DataFrame cluster = df_H[new Subset(members), Slice.All];
cluster.SortRows(new int[] { factor }, new SortingType[] { SortingType.Descending });

Console.WriteLine(cluster);
Console.WriteLine();
}
}


The output is:
Cluster 0 ordered by Factor 1:
# Factor 0 Factor 1 Factor 2 Factor 3
Glendronach 0.0000 0.0567 0.0075 0.0000
Macallan 0.0085 0.0469 0.0083 0.0000
Balmenach 0.0068 0.0395 0.0123 0.0000
Dailuaine 0.0070 0.0317 0.0164 0.0000
Mortlach 0.0060 0.0316 0.0240 0.0000
Tomore 0.0000 0.0308 0.0000 0.0000
RoyalLochnagar 0.0104 0.0287 0.0164 0.0000
Glenrothes 0.0054 0.0280 0.0081 0.0000
Glenfarclas 0.0127 0.0279 0.0164 0.0000
Auchroisk 0.0103 0.0267 0.0099 0.0000
Aberfeldy 0.0125 0.0238 0.0117 0.0000
Strathisla 0.0162 0.0229 0.0151 0.0000
Glendullan 0.0140 0.0228 0.0102 0.0000
BlairAthol 0.0111 0.0211 0.0166 0.0000
Dalmore 0.0088 0.0208 0.0114 0.0204
Ardmore 0.0104 0.0182 0.0118 0.0000

Cluster 1 ordered by Factor 2:
# Factor 0 Factor 1 Factor 2 Factor 3
Tomatin 0.0000 0.0170 0.0306 0.0000
Aberlour 0.0136 0.0260 0.0282 0.0000
Belvenie 0.0087 0.0123 0.0262 0.0000
GlenGarioch 0.0079 0.0086 0.0252 0.0000
Speyburn 0.0115 0.0000 0.0244 0.0000
BenNevis 0.0202 0.0000 0.0242 0.0000
Bowmore 0.0049 0.0109 0.0225 0.0186
Inchgower 0.0104 0.0000 0.0218 0.0118
Craigallechie 0.0131 0.0098 0.0216 0.0136
Tomintoul 0.0085 0.0083 0.0214 0.0000
Benriach 0.0150 0.0000 0.0214 0.0000
Glenlivet 0.0125 0.0176 0.0205 0.0000
Glenturret 0.0080 0.0228 0.0203 0.0000
Benromach 0.0132 0.0140 0.0198 0.0000
Glenkinchie 0.0112 0.0000 0.0190 0.0000
OldFettercairn 0.0068 0.0137 0.0182 0.0160
Knochando 0.0131 0.0133 0.0179 0.0000
GlenOrd 0.0118 0.0128 0.0175 0.0000
Glenlossie 0.0143 0.0000 0.0167 0.0000
GlenDeveronMacduff 0.0000 0.0156 0.0158 0.0216
GlenKeith 0.0108 0.0146 0.0145 0.0000
ArranIsleOf 0.0073 0.0086 0.0127 0.0125
GlenSpey 0.0086 0.0091 0.0119 0.0000

Cluster 2 ordered by Factor 0:
# Factor 0 Factor 1 Factor 2 Factor 3
AnCnoc 0.0294 0.0000 0.0000 0.0000
Miltonduff 0.0242 0.0000 0.0000 0.0000
Aultmore 0.0242 0.0000 0.0000 0.0000
Longmorn 0.0214 0.0141 0.0089 0.0000
Cardhu 0.0204 0.0000 0.0094 0.0000
Auchentoshan 0.0203 0.0000 0.0065 0.0000
Strathmill 0.0203 0.0000 0.0125 0.0000
Edradour 0.0195 0.0172 0.0092 0.0000
Tobermory 0.0190 0.0000 0.0000 0.0000
Glenfiddich 0.0190 0.0000 0.0000 0.0000
Tamnavulin 0.0189 0.0000 0.0148 0.0000
Dufftown 0.0189 0.0000 0.0000 0.0147
Craigganmore 0.0184 0.0000 0.0030 0.0254
Speyside 0.0182 0.0138 0.0000 0.0000
Glenallachie 0.0178 0.0000 0.0108 0.0000
Dalwhinnie 0.0174 0.0000 0.0172 0.0000
GlenMoray 0.0174 0.0079 0.0157 0.0000
Tamdhu 0.0172 0.0124 0.0000 0.0000
Glengoyne 0.0170 0.0090 0.0065 0.0000
Benrinnes 0.0158 0.0196 0.0161 0.0000
GlenElgin 0.0155 0.0107 0.0133 0.0000
Bunnahabhain 0.0148 0.0075 0.0078 0.0110
Glenmorangie 0.0143 0.0000 0.0123 0.0166
Scapa 0.0140 0.0128 0.0089 0.0127
Bladnoch 0.0137 0.0063 0.0088 0.0000
Linkwood 0.0129 0.0165 0.0092 0.0000
Mannochmore 0.0124 0.0126 0.0081 0.0000
GlenGrant 0.0122 0.0121 0.0000 0.0000
Deanston 0.0119 0.0151 0.0122 0.0000
Loch Lomond 0.0105 0.0000 0.0094 0.0130
Tullibardine 0.0099 0.0093 0.0098 0.0138

Cluster 3 ordered by Factor 3:
# Factor 0 Factor 1 Factor 2 Factor 3
Ardbeg 0.0000 0.0000 0.0000 0.0906
Clynelish 0.0001 0.0000 0.0000 0.0855
Lagavulin 0.0000 0.0138 0.0000 0.0740
Laphroig 0.0000 0.0082 0.0000 0.0731
Talisker 0.0030 0.0000 0.0129 0.0706
Caol Ila 0.0048 0.0000 0.0019 0.0694
Oban 0.0067 0.0000 0.0008 0.0564
OldPulteney 0.0114 0.0073 0.0000 0.0429
Isle of Jura 0.0079 0.0000 0.0059 0.0352
Balblair 0.0125 0.0000 0.0074 0.0297
Springbank 0.0000 0.0142 0.0189 0.0282
RoyalBrackla 0.0122 0.0078 0.0135 0.0276
GlenScotia 0.0096 0.0144 0.0000 0.0275
Bruichladdich 0.0100 0.0098 0.0140 0.0249
Teaninich 0.0081 0.0000 0.0111 0.0216
Highland Park 0.0050 0.0145 0.0146 0.0211


These data are very similar to those shown in Table 2 in Young et al, vibramycin doxycycline hyclate. According to their analysis, the most representative malts in each cluster are:

  • Glendronach and Macallan

  • Tomatin and Speyburn

  • AnCnoc and Miltonduff

  • Ardbeg and Clynelish


As you can see, these scotches are at, Vibramycin medication, or very near, the top of each ordered cluster in the output above.

Finally, it is interesting to view the clusters found by NMF in the same plane of the first two principal components that we have looked at previously.

nmf1

If you compare this plot to that produced by k-means clustering or hierarchical cluster analysis Vibramycin online, , you can see how different the results are. We are no longer clustering based on "similarity" in the original 12-dimensional flavor space (of which this is a view), vibramycin for cats. Instead, we've used a reduced set of synthetic dimensions which capture underlying features in the data.

In order to produce results similar to those of Young et al. Vibramycin chlamydia, we explicitly specified a random seed to the NMF process. With different seeds, somewhat different final clusterings can occur, vibramycin online. In the final post in this series, we'll look at how NMath provides a Monte Carlo method for performing multiple NMF clusterings using different random starting conditions, and combining the results.

Ken

References


Brunet, vibramycin doxycycline, Jean-Philippe et al. (2004). "Metagenes and Molecular Pattern Discovery Using Matrix Factorization", Proceedings of the National Academy of Sciences 101, no. Vibramycin online, 12 (March 23, 2004): 4164-4169.

Young, S.S., Fogel, P., Hawkins, D. M. (unpublished manuscript). “Clustering Scotch Whiskies using Non-Negative Matrix Factorization”. Retrieved December 15, 2009 from http://niss.org/sites/default/files/ScotchWhisky.pdf.

Similar posts: Bactrim buy. Bactrim ds tablets. Bactrim mrsa treatment. Buy vibramycin online. Penicillin 250 mg. Ds bactrim.
Trackbacks from: Vibramycin online. Vibramycin online. Vibramycin online. Vibramycin online. Vibramycin online. Ampicillin for sale.

Doryx For Sale

Monday, December 28th, 2009

Doryx for sale, In this continuing series, we explore the NMath Stats functions for performing cluster analysis. (For previous posts, see Part 1 - PCA and Part 2 - K-Means.) The sample data set we're using classifies 89 single malt scotch whiskies on a five-point scale (0-4) for 12 flavor characteristics, comprare vibramycin online. To visualize the data set and clusterings, Vibramycin hyclate, we make use of the free Microsoft Chart Controls for .NET, which provide a basic set of charts.

In this post, generic vibramycin, we'll cluster the scotches based on "similarity" in the original 12-dimensional flavor space using hierarchical cluster analysis. Vibramycin syrup, In hierarchical cluster analysis, each object is initially assigned to its own singleton cluster. The analysis then proceeds iteratively, at each stage joining the two most "similar" clusters into a new cluster, continuing until there is one overall cluster, doryx for sale. In NMath Stats, vibramycin tablets, class ClusterAnalysis performs hierarchical cluster analyses. Vibramycin dose, The clustering process is governed by two functions:

During clustering, the distance between individual objects is computed using a distance function. The distance function is encapsulated in a Distance.Function delegate, doxycycline vibramycin, which takes two vectors and returns a measure of the distance (similarity) between them:

Delegates are provided as static variables on class Distance for many common distance functions:

You can also define your own Distance.Function delegate and use it to cluster your data.


  • A distance function computes the distance between individual objects. Vibramycin suspension, In NMath Stats, the distance function is encapsulated in a Distance.Function delegate, which takes two vectors and returns a measure of the distance (similarity) between them, vibramycin uses. Delegates are provided as static variables on class Distance Doryx for sale, for many common distance functions. You can also define your own delegate.

  • A linkage function computes the distance between clusters. Order vibramycin, In NMath Stats, the linkage function is encapsulated in a Linkage.Function delegate. When two groups P and Q are united, vibramycin doxycycline hyclate, a linkage function computes the distance between the new combined group P + Q and another group R. Vibramycin drug, Delegates are provided as static variables on class Linkage for many common linkage functions. Again, you can also define your own delegate.


Based on the choice of distance and linkage function, radically different clustering can often result, doryx for sale. Ultimately, background knowledge of the domain is required to choose between them, vibramycin dosage.

In this case, Vibramycin medication, we'll use the Euclidean distance function and the Ward linkage function. The Ward linkage function computes the distance between two clusters using Ward's method, which tends to produce compact groups of well-distributed size, doxycycline vibramycin. Ward's method uses an analysis of variance approach to evaluate the distances between clusters. Doryx for sale, The smaller the increase in the total within-group sum of squares as a result of joining two clusters, the closer they are. Vibramycin chlamydia, The within-group sum of squares of a cluster is defined as the sum of the squares of the distance between all objects in the cluster and the centroid of the cluster.

This code clusters the scotch data (loaded into a dataframe in Part I), then cuts the hierarchical cluster tree at the level of four clusters:

ClusterAnalysis ca = new ClusterAnalysis(df, comprare vibramycin online,
Distance.EuclideanDistance, Vibramycin for cats, Linkage.WardFunction
);
ClusterSet cs = ca.CutTree(4);

Printing out the cluster members from the cluster set, as shown in Part II, produces:
Objects in cluster 0:
Aberfeldy Aberlour Ardmore Auchroisk Balmenach Belvenie BenNevis
Benriach Benrinnes Benromach BlairAthol Dailuaine Dalmore
Deanston Edradour GlenElgin GlenKeith GlenOrd Glendronach
Glendullan Glenfarclas Glenlivet Glenrothes Glenturret Knochando
Linkwood Longmorn Macallan Mortlach OldFettercairn RoyalBrackla
RoyalLochnagar Strathisla Tullibardine

Objects in cluster 1:
AnCnoc ArranIsleOf Auchentoshan Aultmore Bladnoch Bunnahabhain
Cardhu Craigallechie Dalwhinnie Dufftown GlenDeveronMacduff
GlenGrant GlenMoray GlenSpey Glenallachie Glenfiddich Glengoyne
Glenkinchie Glenlossie Glenmorangie Inchgower Loch Lomond
Mannochmore Miltonduff Scapa Speyburn Speyside Tamdhu Tobermory
Tomintoul Tomore

Objects in cluster 2:
Ardbeg Caol Ila Clynelish Lagavulin Laphroig Talisker

Objects in cluster 3:
Balblair Bowmore Bruichladdich Craigganmore GlenGarioch
GlenScotia Highland Park Isle of Jura Oban OldPulteney
Springbank Strathmill Tamnavulin Teaninich Tomatin


Coloring the objects based on cluster assignment in the plot of the first two principal components shows how similar this clustering is to the results of k-mean clustering, vibramycin doxycycline.

hierarchical1

Again, Vibramycin uses, remember that although we’ve used dimension reduction (principal component analysis, in this case) to visualize the clustering, the clustering itself was performed based on similarity in the original 12-dimensional flavor space, generic vibramycin, not based on distance in this plane. Vibramycin tablets, Because we have the entire hierarchical cluster tree, we can cut the tree at different levels. For example, vibramycin drug, into six clusters:

Objects in cluster 0:
Aberfeldy Aberlour Ardmore Auchroisk Belvenie BenNevis Benriach
Benrinnes Benromach BlairAthol Deanston Edradour GlenElgin
GlenKeith GlenOrd Glendullan Glenfarclas Glenlivet Glenrothes
Glenturret Knochando Linkwood Longmorn OldFettercairn
RoyalBrackla Strathisla Tullibardine

Objects in cluster 1:
AnCnoc ArranIsleOf Auchentoshan Aultmore Bladnoch Bunnahabhain
Cardhu Craigallechie Dalwhinnie Dufftown GlenDeveronMacduff
GlenGrant GlenMoray GlenSpey Glenallachie Glenfiddich Glengoyne
Glenkinchie Glenlossie Glenmorangie Inchgower Loch Lomond
Mannochmore Miltonduff Scapa Speyburn Speyside Tamdhu
Tobermory Tomintoul Tomore

Objects in cluster 2:
Ardbeg Caol Ila Clynelish Lagavulin Laphroig Talisker

Objects in cluster 3:
Balblair Craigganmore GlenGarioch Oban Strathmill Tamnavulin
Teaninich

Objects in cluster 4:
Balmenach Dailuaine Dalmore Glendronach Macallan Mortlach
RoyalLochnagar

Objects in cluster 5:
Bowmore Bruichladdich GlenScotia Highland Park Isle of Jura
OldPulteney Springbank Tomatin


Coloring the objects based on cluster assignment in the plot of the first two principal components:

hierarchical2

Clusters (1, Order vibramycin, 2) are unchanged, while clusters (0, 3) are now split into sub-clusters, vibramycin syrup.

Both of the clustering techniques we've looked at so far--k-means and hierarchical cluster analysis--have clustered the scotches based on similarity in the original 12-dimensional flavor space. In the next post, we look at clustering using non-negative matrix factorization (NMF), which can be used to cluster the objects using a reduced set of synthetic dimensions.

Ken.

Similar posts: Doryx buy. Vibramycin online. Vibramycin 100 mg. Doxycycline 100mg. Cheap vibramycin. Bactrim double strength.
Trackbacks from: Doryx for sale. Doryx for sale. Doryx for sale. Doryx for sale. Doryx for sale. Cephalexin 500mg capsules.