Is there a c# lib to fit data to normal distribution? - c#

I found a similar question but it has no exact answer.
What I need is given a real world data set: List<double> and assume it fits a normal distribution. I need to get the distribution(the mean and sdv). I am using math.net to calculate data in my application. Can math.net do this and how? Or is there any other C# library can do this?
Thanks a lot.

Wikipedia gives you formulas to calculate the estimates of the normal distribution parameters. The expressions are simple so you actually don't need any third party libraries to perform the calculations.

I'm on the CenterSpace NMath team. We use a robust trust region minimizer to solve this nonlinear fitting problem. Depending on your data you may be able to do this with the more widely accessible Levenberg-Marquardt minimization algorithm well documented on wikipedia.
http://www.centerspace.net/distribution-fitting-demo/
No our library isn't free...but this code may give you some ideas.
Best,
Paul

Related

Implementing probability density formula for skewed normal distribution in C#

I asked this question a while ago on math.stackexchange.
I was given the formula for the pdf of a skewed normal distribution but it involves integrals and I have no clue how to implement the formula in C#.
Like I said in the question linked, I'm writing a program where certain 'effects' are strong in the beginning and weaker later on or vice-versa. I've opted to use a skewed standard distribution.
I just want a formula where I input the skewness, 'x' and get the density for that particular x on the graph.
If I can understand how to implement the formula he gave perhaps I can also use it for non-standard distributions where the mean and standard deviation are something other than 0 and 1 respectively.
I checked out Math.NET but was unable to find something that could help me here. I have no clue where to start.
There are a number of ways to numerically solve integrals, with a few methods being more popular than others. A simple google search for "numerically solve integrals" will probably be more beneficial than a solitary answer here.
If you're looking for an example specifically in c#, this link will provide implementation in c# for a definite integral for the mid-point, simpson, and trapezoidal methods to solutions.
The integral mentioned in flawr's answer to your question is, as he/she says, the cdf of the normal distribution. There is a simple formula for that, namely Phi(x) = 1/2 (1 + erf(x/sqrt(2))), where erf is the Gaussian error function, which is commonly included in math libraries; I don't know about .Net in particular.
You don't have to compute the integral numerically; just find erf in some library. In fact, computing the integral numerically is almost certainly going to be less accurate than using erf from a library, and it will certainly be more work.
EDIT: Answers for this SO question seem to suggest that this implementation of erf for C# is useful.

C# graphs algorithms library

I'm looking for .NET library with the next graphs algorithms:
algorithm for finding a minimum
spanning tree;
algorithm for partitioning graph for N subgraphs with minimal number of connections.
I can write my own realization, but don't have too much time. Tell me, please, names of any existing libraries that can do this. Thanks.
yWorks provides several products for .NET
Depending on where you plan on deploying you can choose your flavor and perform lots of analyses on the graph.
Although I'm not fond of the API (a bit too java-ish), the biggest disadvantage is definitely the price.
The best solution was to use QuickGraph library. It already has algorithm for finding a minimum spanning tree. And I used their implementation of graph to write my own algorithm for partitioning it.

C++ / Java / C# Image processing library

What would be the best library choice for finding similar parts in images and similarity matching?
Thank you.
It sounds like the Scale Invariant Feature Transform (SIFT) is probably the algorithm you're really looking for. Offhand, I don't know of any general-purpose image processing library that includes it, but there are definitely standalone implementations to be found (and knowing the name should make Googling for it relatively easy).
ImageJ fastest image processing library in Java.
OpenCV is certainly a solid choice as always.
That said, VLFeat is also very good. It includes many popular feature detectors (including SIFT, MSER, Harris, etc.) as well as clustering algorithms like (kd-trees and quickshift). You can piece together something like a bag of words classifier using that very quickly.
While SIFT is certainly a solid general purpose solution, it actually is a pipeline composed of a feature detector (which points are interesting in the image), a feature descriptor (for each interesting point in the image, what's a good representation), and a feature matcher (given a descriptor and a database of descriptors, how do I determine what is the best match).
Depending upon your application, you may want to break apart this pipeline and swap in different components. VLFeat's SIFT implementation is very modular and lets you experiment with doing so easily.
Never did image processing, but I've heard from friends OpenCV is quite good, they usually use C++

Has C#/.NET builtin conversion routines for length units?

Has C#/the .NET library builtin routines or constants for converting e. g. millimetres to inches? If so, where can I find them? (I just do not want to produce duplicate code again and again.)
No, there are no such build in routines or constants in the framework.
Totally gratuiitous off topic reply
F# has built in support for units. This is a random blog I just Binged Units Of Measure In F#
Here's a CodeProject sample that does unit conversion:
http://www.codeproject.com/KB/cs/Thunder.aspx
It's not built-in to .Net, but it will save you from having to write all this stuff yourself.
Update: it makes a bit of sense that this would not be part of .Net, because there are issues regarding the degree of precision to use in the conversions and the constants which are probably best left to the developer.
just roll your own set of assemblies which contain the functions so that you don't have to duplicate the code. a simple google search will yield the common conversion formulas. here's a good page.
edited to add the second link...

Existing library to calculate code complexity of a block of code

I'm given a string which contains an arbitrary amount of code. I want to calculate a number which represents the code complexity of that string. Something like:
int complexity = Lib.FindComplexity(someString);
I realize there are a lot of tools out there that will do this for you. These tools will not work for me, because I want to do it programmatically. I'd love for the library to be in C#, but will work with anything at this point.
Thanks in advance!
Have you considered using one of those existing tools and wrapping it in a library? For instance, you might be able to use the NDepend.Console.exe by calling it from your code with the parameters you want, and parse out the result.
NDepend is a great tool, although not cheap at the time I looked at it. If money isn't an option, I'd look into using reflection and http://en.wikipedia.org/wiki/Cyclomatic_complexity. It doesn't meet your requirement with any string but you could definitely test assemblies you created.
You can also use reflector and the code metrics plug-in available for it.
A library such as this must be able to parse an arbitrary language
fragment, and then compute the complexity metrics over the parsed fragment.
Most metrics tools have at best a parser for the entire language,
not just a fragment, so you are likely to be hard pressed to find
many solutions.
There is one system that can provide you what you need:
our DMS Software Reengineering Toolkit. It provides parsers
for many languages (such as Java and C#;
it is unclear what language you want to analyze).
DMS has been used already to implement these kinds of metrics
for several langauges (Java, C#, JavaScript, COBOL)
and the process of doing this is straigtforward.
And DMS does parse langauge fragments, and amazingly,
the metrics implementation actually operate on such fragments.
You could customize DMS to implement exactly what you want.
See http://www.semanticdesigns.com/Products/DMS/DMSToolkit.html
and for derived metrics tools,
http://www.semdesigns.com/Products/Metrics/index.html

Categories

Resources