https://kotlinlang.org logo
#mathematics
Title
# mathematics
a

alex cole

12/28/2020, 2:37 AM
I 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.kt
a

Andrew

12/29/2020, 3:09 AM
Not sure about the first part of your question. In junit the last parameter of assertEquals for values of type double should be the delta which represents the error, so for 2 decimal places you would use like 0.005
a

alex cole

12/29/2020, 3:20 AM
I have been working through a textbook of mine to build out a kotlin numerical methods package, however I am unsure of how to build an api to make each item more accessible. I could just copy the scipy api but I think I should be a bit more creative.
a

Andrew

12/29/2020, 3:36 AM
are you making a library or standalone app?
I wouldn't worry too much about the api at this point but as you add more things you might get more ideas how to better use it. For example on LinearRegression you have a dataset as input (array of double) but later you might decide to have a dataset as its own class if there are other usages for it, but right now that refactor doesn't make sense.
a

alex cole

12/29/2020, 3:49 AM
I think I will use kmath objects as the data sets later on and will tack that on in a constructor once I complete my own implementations of each numerical method in my book.
@Andrew What would you recommend for a dataset class? Would this become its own numpy like object?
a

Andrew

01/03/2021, 12:12 AM
Yes I can see it being useful later, for example your LinearRegression takes 1 or 2 arrays in the constructor. If you had several other classes that did the same thing it would make sense to move that to a Dataset class then those classes just accepted a dataset. Really depends on what else you plan on adding.
a

alex cole

01/03/2021, 12:15 AM
I have been thinking about writing my own NDArray class with operator overloads. Would this be the same as the DataSet class?
a

Andrew

01/03/2021, 3:14 AM
I'm not sure how operator overloads work with those so might be something different
a

alex cole

01/03/2021, 5:16 AM
I was looking at doing vector math and wanted something easier. This would be similar to making two objects
Copy code
val c = a + b
The same thing exists in matlab with .* or ./ operators for dealing with vectors or matricies.
a

Andrew

01/03/2021, 6:46 AM
yeah that make sense, just wanted to be clear this is different than a dataset which usually holds time series data but a N-dimensional array for vector operations would be a different use (even if the underlying data is an array of float/double)
a

alex cole

01/03/2021, 3:19 PM
Do you think you could post an example DataSet Class?