optimatika / okAlgo

Idiomatic Kotlin extensions for ojAlgo
MIT License
26 stars 3 forks source link

Linear Algebra DSL #3

Open thomasnield opened 6 years ago

thomasnield commented 6 years ago

Extensions need to be built for everything else outside the solver, including data structures and linear algebra API's.

thomasnield commented 6 years ago

Some pretty nice idioms are emerging :)


fun main(args: Array<String>) {

    val matrixA = primitivematrix(3,3) {
        populate { row, col -> 1 }
    }

    val matrixB = primitivematrix(3,1) {
        populate { row, col -> 10 }
    }

    println(matrixA * matrixB)
}
thomasnield commented 6 years ago

Really nice!

fun main(args: Array<String>) {

    val colors = sequenceOf(
            Color.RED,
            Color.PINK,
            Color.YELLOW,
            Color.BLUE,
            Color.GREEN
    )

    val matrix = colors.toPrimitiveMatrix(
            { it.red },
            { it.green },
            { it.blue }
    )

    println(matrix)
}
thomasnield commented 6 years ago

I think I'm almost ready for another release @apete. What do you think? I'll document some beautiful examples later.

https://github.com/optimatika/okAlgo/blob/master/src/main/kotlin/org/ojalgo/okalgo/algebra.kt

apete commented 6 years ago

Whenever I see people use BasicMatrix I worry they think that's the only option and/but it's not what they actually need or want. Did you read this?

https://github.com/optimatika/ojAlgo/wiki/Getting-Started

thomasnield commented 6 years ago

@apete yes many times. I can definitely add the other interfaces.

thomasnield commented 6 years ago

Rethinking the Kotlin functions here. Taking inventory again, it looks like I need to balance having a simple Kotlin API that doesn't worry itself about lower-level implementations, while streamlining access to the implementations.

https://github.com/optimatika/ojAlgo/wiki/Working-with-arrays https://github.com/optimatika/ojAlgo/wiki/Sparse-Matrices https://github.com/optimatika/ojAlgo/wiki/Getting-Started

thomasnield commented 6 years ago

I'd like to get this done by this weekend, as well as the ANN API, in time for KotlinConf 2018.

apete commented 6 years ago

What do you need from me?

thomasnield commented 6 years ago

I need to take inventory and make sure I fully understand every matrix flavor, and figure out how which ones should be the defaults in certain parts of the API. I'd like to get the linear algrebra up and running not just for KotlinConf, but also so I can start using it in my ML research.

So I may come to you with questions in the next few days.

If you like and don't mind getting your hands dirty with some Kotlin, please feel free to take a look at my work so far and make changes where you see fit. You should be able to clone the project and build it with Gradle.

https://github.com/optimatika/okAlgo/blob/master/src/main/kotlin/org/ojalgo/okalgo/algebra.kt

I'll add some unit tests later that will demonstrate how usage works.

thomasnield commented 5 years ago

@apete I wrote some passing unit tests that should also give an idea what the DSL looks like. Can you take a look and make sure I'm using the correct matrix types now?

After this I'd like to do a release. I'll start documenting this better and getting this much-prolonged project off the ground.

apete commented 5 years ago

I'm not sure what you want to achieve, and I'm not fluent in Kotlin.

org.ojalgo.matrix is for when you just need to use matrices in a relatively standard way.

org.ojalgo.matrix.store / org.ojalgo.matrix.decomposition is for when plan to implement algorithms and need lower level control.

I think maybe you should start out doing one of each, and pretty soon you're going to figure out which suits you.

At this point I think you can forget about Quaternions. Just use Primitive, ComplexNumber and RationalNumber if you like.

thomasnield commented 5 years ago

What I'm trying to achieve is making ojAlgo idiomatic for Kotlin via extension functions and builder functions.

And like you said those types are my only goal right now: just implement Primitive, ComplexNumber, and RationalNumber which are already done. I'll wait on quaternion when somebody I know actually uses it.

I don't see this library going into store or decomposition at the moment. I'll expand this with needed use cases to streamline in Kotlin.

But I'm ready to pull the trigger on a release 0.1.0 if that's okay.