Channels

#mathematics

- a
alex cole

11/25/2020, 5:54 PMkmath 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?ab- 3
- 11

- i
Iaroslav Postovalov

11/29/2020, 1:53 PMHello,**@breandan**. We are experiencing problems with stable access to Princess library. Is it mandatory to use KotlinGrad

related interfaces? I suppose this library can either be published to more stable Maven repository or removed from KotlinGrad core module, then extracted to a separate module that does use Princess.`SFun`

b- 2
- 2

- a
altavir

11/30/2020, 8:49 AM**@alex cole**By the way, I just rememebered that I had an article about migration from Python notebook to Kotlin notebook: https://levelup.gitconnected.com/a-first-dive-into-kotlin-jupyter-eab43dca9472. The visualization and tooling became much better since then.a- 2
- 5

- i
Iaroslav Postovalov

12/08/2020, 8:41 AMJust sent a PR to KMath that replaces syntax of dynamic calls of algebraic operations from

to`algebra.binaryOperation("+", 1, 1)`

. This feature also affects ASM code generation so generated classes store functional objects returned by`algebra.binaryOperation("+")(1, 1)`

methods instead of storing algebraic structures.`*aryOperation("...")`

a- 2
- 1

- i
Iaroslav Postovalov

12/08/2020, 8:41 AM - z
zain

12/11/2020, 5:04 AMHi**@altavir**all the other issues are resolved while integrating the Plotly library. I had another question related to it I have tried to articulate it over here. https://stackoverflow.com/questions/65246043/how-to-plot-a-coordinate-graph-using-plotly-kt-for-y-1-x Please let me know once you are free.a- 2
- 2

- a
alex cole

12/28/2020, 2:37 AMI have been working on putting together a basic numerical methods library and was wondering what I could do to build an api primarily for this linear regression class. Also what is the best way to assert equals when the known values differ in significant figures from the actualValue. https://github.com/jalexcole/NumericalMethods/blob/master/src/main/kotlin/curveFitting/regression/LinearRegression.kta- 2
- 12

- b
breandan

01/05/2021, 1:56 AMDid some experiments with type classes. It's a nice pattern for abstract algebra: https://github.com/breandan/kotlingrad/blob/master/core/src/main/kotlin/edu/umontreal/kotlingrad/typelevel/TypeClassing.kt❤️ 1a- 2
- 9

- a
alex cole

01/14/2021, 12:05 AMIs there a preferred jdk, garbage collector, etc. that is best used for numerical loads?ai- 3
- 14

- a
altavir

01/22/2021, 5:35 AMHello everyone, we are working on integrating PyTorch C++ API into Kmath (for both native and JVM). Have a look at the prototype here: https://github.com/mipt-npm/kmath/tree/feature/torch/kmath-torch Comments and suggestions are very welcome. Here are some rough local benchmarks mostly for you to get excited about the project as well: Benchmarking 20 x 20 Real matrices on CPU: K/N: 2.17us p.o. with 100000 iterations JVM: 2.25us p.o. with 100000 iterations C++: 1.98us p.o. with 2115299 iterations Benchmarking 200 x 200 Real matrices on CPU: K/N: 108us p.o. with 10000 iterations JVM: 85.1us p.o. with 10000 iterations C++: 81.36us p.o. with 53283 iterations Benchmarking 2000 x 2000 Real matrices on CPU: K/N: 75.3ms p.o. with 20 iterations JVM: 75.1ms p.o. with 20 iterations C++: 74.7ms p.o. with 58 iterations Benchmarking 20 x 20 Float matrices on CPU: K/N: 2.06us p.o. with 100000 iterations JVM: 2.05us p.o. with 100000 iterations C++: 1.82us p.o. with 378177 iterations Benchmarking 20 x 20 Float matrices on CUDA(index=0): K/N: 7.10us p.o. with 100000 iterations JVM: 7.02us p.o. with 100000 iterations C++: 6.93us p.o. with 101669 iterations Benchmarking 200 x 200 Float matrices on CPU: K/N: 41.6us p.o. with 10000 iterations JVM: 42.6us p.o. with 10000 iterations C++: 42.9us p.o. with 16088 iterations Benchmarking 200 x 200 Float matrices on CUDA(index=0): K/N: 10.3us p.o. with 10000 iterations JVM: 10.3us p.o. with 10000 iterations C++: 10.6us p.o. with 65344 iterations Benchmarking 2000 x 2000 Float matrices on CPU: K/N: 36.2ms p.o. with 20 iterations JVM: 37.6ms p.o. with 20 iterations C++: 36.8ms p.o with 76 iterations Benchmarking 2000 x 2000 Float matrices on CUDA(index=0): K/N: 1.46ms p.o. with 1000 iterations JVM: 1.48ms p.o. with 1000 iterations C++: 1.78ms p.o. with 1000 iterations Benchmarking generation of 100000 Normal samples on CPU: K/N: 688us p.o. with 100 iterations JVM: 855us p.o. with 100 iterations C++: 684us p.o. with 4149 iterations Benchmarking generation of 100000 Normal samples on CUDA(index=0): K/N: 5.94us p.o. with 100000 iterations JVM: 6.31us p.o. with 100000 iterations C++: 5.60us p.o. with 490027 iterations Benchmarking generation of 100000 Uniform samples on CPU: K/N: 396us p.o. with 100 iterations JVM: 476us p.o. with 100 iterations C++: 402us p.o. with 1765 iterations Benchmarking generation of 100000 Uniform samples on CUDA(index=0): K/N: 5.74us p.o. with 100000 iterations JVM: 6.21us p.o. with 100000 iterations C++: 5.59us p.o. with 126191 iterations Thread in Slack Conversation- 1
- 1

- a
Andrew

01/23/2021, 4:36 PMI'm pretty dumb when it comes to software licenses. What are the implications of porting and heavily modifying something like BigInteger from the openJdk source to kotlin? Is that allowed? Do I just need to keep the license part, and does that apply to my entire project or just that class?a- 2
- 8

- a
altavir

01/24/2021, 7:37 AMBy the way, here are the results of naive tests (no JMH, so be careful with conclusions) on GraalVM11:Boxing addition completed in 22157 millis

Specialized addition completed in 1840 millis

Nd4j specialized addition completed in 1309 millis

Viktor addition completed in 1966 millis

Parallel stream addition completed in 1457 millis

Automatic field addition completed in 1773 millis

Lazy addition completed in 14157 millis

ND4J uses OpenBlas under the hood. And I think**@Iaroslav Postovalov**told me that is uses parallel execution. I wonder if there is a large overhead on top of BLAS. Because the results are very close.i- 2
- 5

- b
breandan

01/31/2021, 3:48 PMInteresting, it seems the term "field" used in algebra and physics are related. To check if a set of matrices is an algebraic field, it must be closed under (+, -, *), have additive identity, multiplicative identity and commutativity, and a multiplicative inverse. The term vector/matrix field used differential geometry and physics is a actually a vector/matrix space*over*a field, i.e. the product of a field and a vector/matrix space, whose elements are vectors/matrices. The type signatures are slightly different. Algebraic field: ×: 𝔽 × 𝔽 → 𝔽 +: 𝔽 × 𝔽 → 𝔽 Vector field: +: 𝔽ⁿ × 𝔽ⁿ → 𝔽ⁿ ⋅: 𝔽 × 𝔽ⁿ → 𝔽ⁿ cc:**@altavir****@dievsky**aрa- 4
- 33

- a
altavir

02/03/2021, 4:05 PMIs the**@Aleksei Dievskii**the correct tag-name for Alexei, I think.👍 1a- 2
- 1

- b
breandan

02/06/2021, 8:27 PMHappy to see experimental support for sealed interfaces arriving in 1.5. Together with multiple inheritance and default methods, this opens up a path to implementing algebraic data types: https://blog.jetbrains.com/kotlin/2021/02/new-language-features-preview-in-kotlin-1-4-30/#sealed-interfaces AFAICT, this feature offers the same benefits of multiple receivers without needing to introduce a new syntax. Or is there some feature that KEEP-176 proposes which could not be implemented using the type class pattern on a sealed interface?ia- 3
- 11

- a
altavir

02/09/2021, 2:05 PMSomebody ever tried to solve the problem of the classes schedule optimization? I not it is not simple, but I know it could be solved. I asked different students to do the algorithm for that for years, but nobody managed to do that. And it requires more knowledge of descreete optimization, than I have.bl- 3
- 4

- a
altavir

02/17/2021, 1:51 PMCheck out Multik v 0.0.1: easy-to-use, type-safe and powerful Kotlin API for mathematical operations over multidimensional arrays with swappable JVM and native computational engines. https://blog.jetbrains.com/kotlin/2021/02/multik-multidimensional-arrays-in-kotlin/ TwitterK 3🐍 1a- 2
- 4

- a
altavir

02/21/2021, 2:44 PMFollowing the week of mathematical releases in Kotlin, I am happy to present KMath release 0.2.0: https://github.com/mipt-npm/kmath/releases/tag/v0.2.0. The release contains numerous new features and API fixes as well as new pacckage name (

) and a completely new understanding of library aims. KMath does not want to follow numpy path and provide bindings for a single implementation of nd-arrays and numerics. Instead, we are working on a Kotlin-first API, that allows us to better tap into the kotlin lagnuage potential and allow to create the same or similar API to different`space.kscience`

**existing**libraries, so one could easily switch implementations withot a lot of changes in the code. Also we provide simple multiplatform implementations for people, who do not need super-optimized performance. Those basic implementations are thereby referenced as**kmath-core**to avoid confusion with library bindings like kmath-commons, kmath-ejml, kmath-viktor etc. The important feature of the new release is the new documenation and stability policy. Ecch module has a Maturity level shown in the documentation: • PROTOTYPE - both idea an the implementation may change. • EXPERIMENTAL - we have an idea how it should look like, but implementation could change in minor versions. • DEVELOPMENT - API compatibility between monitor versions is controlled via https://github.com/Kotlin/binary-compatibility-validator. • STABLE - no module has reached this stage yet, but we plan to enforce production-ready stability guarantees. New documentation plugin allows to maintain the list of module features. Here is the list of key feature modules: • kmath-core Core classes, algebra definitions, basic linear algebra, nd-structures, expressions etc. • kmath-commons Bindings for Commons-math library. • kmath-complex Complex numbers and quternions (separated from core in this release. • kmath-nd4j ND4J bindings for nd-structures implementation. • kmath-ejml EJML bindings for linear algebra implementatiion. • kmath-viktor JetBrains Research Viktor bindings for real-valued nd-structures. • kmath-histograms Univariate and multivariate histograms. • kmath-ast MST (mathematical syntax tree) definition, JIT expression compilation with ASM on JVM and JS interpreter on JS. Symbolic algebra. • kmath-kotlingrad Automatic differentiation via MST and kotlingrad library. The significant part of the release is done by**@Iaroslav Postovalov**. I would also like to thank a lot of people, including**@breandan**,**@Peter Klimai**,**@elizarov**,**@Ролан**,**@Aleksei Dievskii**,**@roman.belov**,**@Pavel Gorgulov**and numerous others (I can't remember them all, we need a list), for discussions and contributions. The project is supported by the JetBrains Research.🎉 12ze- 3
- 10

- a
altavir

03/08/2021, 9:24 AM**@Aleksei Dievskii**A question about algebras. Could you give an example of a

which does not have a numeric scaling of its members? We have some problems bringing KMath inheritance model in check and keep it practical so I am thinkgin about different architectural approaches.`Space`

aр- 3
- 43

- b
breandan

03/22/2021, 7:15 PMThis Friday Mar. 26th at 12:00 EDT / 16:00 UTC we are hosting Erik Meijer at our reading group. He will discuss some mathematical topics, possibly related to Kotlin somehow. In case anyone here is available, please feel welcome to drop by and say hello! It would be great to have your feedback.**Inside Every Calculus Is A Little Algebra Waiting To Get Out**Because of deep learning, there has been a surge in interest in automatic differentiation, especially from the functional programming community. As a result there are many recent papers that look at AD from a Category Theory perspective. However, Category Theorists have already been looking at differentiation and calculus in general since the late 60’s in the context of Synthetic Differential Geometry, but it seems that this work is largely ignored by those interested in AD. In this talk, we will provide a gentle introduction to the ideas of SDG, by relating them to dual numbers, and show how it provides a simple and purely algebraic approach to (automatic) differentiation.

https://mcgill.zoom.us/j/89551971819👀 1👍 1aр- 3
- 5

- a
altavir

03/25/2021, 5:01 PMAn article on Viktor: https://blog.jetbrains.com/kotlin/2021/03/viktor-efficient-vectorized-computations-in-kotlin/👍 7👍🏼 2🙏 4za- 3
- 2

- i
Iaroslav Postovalov

03/31/2021, 12:41 PMI've created Jupyter integration supporting the display of KMath's MST objects.👍 12ia- 3
- 7

- a
altavir

04/16/2021, 12:53 PM**@Ролан**You will probably like this one. A universal multiplatform Gauss-Legendre numerical integration, which could work on

.`StructureND`

🙌 1- 1
- 2

- z
Zhelenskiy

04/16/2021, 7:19 PMCurrent implementation of BigInteger implementation and power is slow so I provided it with corresponding tests: PR .👍 2ab- 3
- 23

- f
Filipe Duarte

04/17/2021, 1:25 AMOperator overload of Nd4j INDArray**#kotlindl**a- 2
- 17

- a
altavir

04/30/2021, 11:38 AM**@Pavel Gorgulov****@zaleslaw**I would like to invite you to a public review of our (aniversary #300) PR by**@Ролан**and his interns: https://github.com/mipt-npm/kmath/pull/300. The PR introduces API and basic multiplatform implementation of tensor algebra. It is huge. Also I would like to start some kind of discusstion about what features do we want from tensors mathematics. Current implementation has one significant benifit, it works on top of generic KMath

meaning it is compatible with any other library which have binings for KMath and one could pass those structures around between different implementations (like Viktor for example).`StructureND`

**@Ролан**I also would like for your students to make a public seminar (in English) describing what have they done and sharing their experience.👍 2👌 1metal 5K 6zр- 3
- 2

- i
Iaroslav Postovalov

05/02/2021, 7:03 PMWe just merged Jupyter integration to the KMath

branch.`dev`

🙌 1рai- 4
- 10

- i
Iaroslav Postovalov

05/02/2021, 7:21 PMimage.png👍 7- 1
- 1

- z
Zhelenskiy

05/06/2021, 4:45 PMOne of the problems of many big int implementations is that they work extremely slow for not so big numbers.. I think it is a common case when number of really big numbers operations is slow so real numbers can be used with longs in most cases and overflows are rare. So, I created a demo to demonstrate it. I didn't compare with KMath's implementation but compared with java.lang.Math's one. Even when I give no helping info, it is about 4 times faster. When I used explicit

type, it became 10 faster than generic one. The speed was the same with just manual long checking. This is because I used inline types. However, it is still a lot slower than just pure usage of`LongBased`

s and `Long`s. But that may be achieved if the code is run under HotSpot and it decides to use intrinsic there. Here is the repo: https://github.com/zhelenskiy/BigInteger/tree/main.`Int`

ia- 3
- 78

- р
Ролан

05/07/2021, 5:51 AMThanks to Andrey Kislitsin, we have a example of a neural network on kotlin mutliplatform using kmath's tensors and including both forward and backward pass (so you can train it everywhere) https://github.com/mipt-npm/kmath/blob/feature/tensor-algebra/examples/src/main/kotlin/space/kscience/kmath/tensors/NeuralNetwork.kt🔥 1🦜 2🙌 2hai- 4
- 29