Need C# advice

  • Thread starter Thread starter Tsotne
  • Start date Start date
Joined
1/13/11
Messages
1,362
Points
93
Hello! I need ideas regarding the programming techniques in math. I've been developing linear algebra(matrices) and statistical classes in C#. I have defined all the functionality and they work well but from the programming point of view, it still requires to be streamlined and modified. So, I have one specific question: Generally (very generally) how could you define a class hierarchy in statistics or calculus. To be more precise: What would you have defined as a base class and derived classes??? Im thinking about one idea and that may help you understand the concept of this question. The idea is as follows: I want to define some common methods like combination, permutation, factorial, etc... as a base class and the discrete and continuous distributions as derived classes. So what do you think? Currently I have defined all the classes (Lin_alg, Statistics) as static classes as well as their methods... Any response will be acceptable. Thank you
 
Go with abstract classes and virtual methods implementing common functionality on a low class hierarchy level and adding something more specific in derived classes. The class hierarchy can be built based on your classification techniques.
 
Start with tests! If you have some classes for numeric operations than you need to have test cases. Just write the simple client for your code, when you will start working on test cases you will see possible problems with your code - somewhere it would be hard to inject dependencies, somewhere it would require heavy initialization before you can start working, whether it's easy to reuse some abstractions or not etc. And ... there is no "silver bullet".
 
How to do this is well known. I recommend benchmarking best in class C++ libs (forget Java) to see how they do it and then try something similar in C#. Examples: Boost Math, uBLAS, Multiarray.

http://www.boost.org/doc/libs/1_45_0/libs/math/doc/sf_and_dist/html/index.html

Using base classes, polymorphic functions and classic OOP is sub-optimal in this context.

I would certainly use C# generics, extension methods and Visitor pattern.

There is no point reinventing the wheel.
 
I'll second Daniel Duffy's remarks. It'll get messy, quickly, if you try to create a type hierarchy for this. I'd probably take a "hybrid" approach and create a basic, clean hierarchy using ONLY interfaces (e.g., IDistribution&lt;T&gt;<t>, then derived interfaces IContinuousDistribution<t></t></t>&lt;T&gt;<t><t> and IDiscreteDistribution</t></t>&lt;T&gt;<t><t><t>), then implement everything with a combination of concrete types (example, DoubleNormalDistribution</t></t></t><t><t><t> : IContinuousDistribution<double></double></t></t></t>&lt;double&gt;<t><t><t><double>) and use extension methods to "glue" everything together.</double></t></t></t>
 
I'll second Daniel Duffy's remarks. It'll get messy, quickly, if you try to create a type hierarchy for this. I'd probably take a "hybrid" approach and create a basic, clean hierarchy using ONLY interfaces (e.g., IDistribution<T><T>, then derived interfaces IContinuousDistribution<T></T></T><T><T><T> and IDiscreteDistribution</T></T><T><T><T><T>), then implement everything with a combination of concrete types (example, DoubleNormalDistribution</T></T></T><T><T><T> : IContinuousDistribution<DOUBLE></DOUBLE></T></T></T><DOUBLE><T><T><T><DOUBLE>) and use extension methods to "glue" everything together.</DOUBLE></T></T></T>

I think extension methods are a great feature, The user thinks it's a method and the creator's job becomes easier.
 
Back
Top Bottom