kmath getting started and how to use examples. Wit...
# mathematics
a
kmath getting started and how to use examples. With kmath there seems to be very little documentation for getting started and transitioning from numpy to kmath. Is there any guide for this such as how to do a linspace function?
a
You are quite correct. Sadly, the documentation is the most problematic point right now. I would really welcome any contibutions in this area. As for linspace, you do not need it in Kotlin since Kotlin stdlib covers that pretty well. For example, if you want to create a uniformly distributed list of 100 elements from 0 to 100 with step 2.0, you need to write
Buffer.real(100){ 2.0 * it}
. You can then work with it as a list or convert to a 1D structure, you can than use
as1D
extension function. ND structures do not provide algebraic operations out of the box, so if you need to perform operations on arrays, you should use
RealVector(buffer)
.
Actually, It would be nice if you could write your python code in the issue and we could include the example of translating it into Kotlin as a part of documentation.
a
Something like this https://github.com/jalexcole/Notible-Homeworks/blob/master/Homework11.ipynb I really enjoy jupyter notebooks for trying out concepts. The argument for having things built in is that there can vector operations and overides where a function receives an ndarray and the vector or matrix functions exist. If you could give some advise on replicating the jupyter notebook with kmath, I might be able to build out example problems working with kmath for the github wiki and eventually a numerical methods library.
a
Thank you very much. I will look into it and start examples. We've been working a lot on features and concepts lately, there are only three people right now, so the documentation is a really sore point.
@alex cole Interesting, your example actuually does not seem to use numpy features. All you do is the appending of arrays and it is actually a bad thing to do in numpy performance-wise. It does not seem that you need Kmath here at all. Because kotlin MutableLists are beter suited for that. Still I will think about it more.
a
The basis of the idea, is that even if its not the best idea it can help as it becomes more of the goto library for numerical work. One other homework that I worked on that used more numpy features was curve fitting. https://github.com/jalexcole/Notible-Homeworks/blob/master/P7-7.ipynb Regarding making examples with kmath, I was planning on using openstax physics textbooks and working with kmath and some plottling library as a way of showing how one could use kmath features.
a
Nice. I will try to work more on the documentation soon. Sadly I am really pressed for time right now due to yearly reports. But I hope that I or @Peter Klimai will find time for it. We recently added very nice fitting features with autodiff. And I can send you examples tomorrow.
b
keep them coming that way as well
a
Also do you think you can add information on how to optimise for simd?
a
I hope I will have time for that today at last. As for SIMD, there are no manual optimization for it right now on JVM (they are planned in the next release of JVM). Still, our tests show that SIMD works perfectly well for basic matrix operations in KMath right now.
Autodif-driven optimization tests are here: https://github.com/mipt-npm/kmath/blob/dev/kmath-commons/src/test/kotlin/kscience/kmath/commons/optimization/OptimizeTest.kt. I am bit over whelmed with funding papers and reports right now, but I will try to find time for the release and docuemntation ASAP.
277 Views