Feature/diff api #154

Merged
altavir merged 20 commits from feature/diff-api into dev 2020-10-28 13:25:24 +03:00
altavir commented 2020-10-26 19:37:12 +03:00 (Migrated from github.com)

Experimental API for symbols and automatic differentiation

Experimental API for symbols and automatic differentiation
CommanderTvis (Migrated from github.com) requested changes 2020-10-26 22:57:54 +03:00
CommanderTvis (Migrated from github.com) commented 2020-10-26 22:57:33 +03:00
  1. SAM interface.
  2. Does it have any uses, except the one in DifferentiableExpression? This trait can be extracted to separate into separate interface at any moment.
1. SAM interface. 2. Does it have any uses, except the one in DifferentiableExpression? This trait can be extracted to separate into separate interface at any moment.
@ -0,0 +10,4 @@
public fun <T> DifferentiableExpression<T>.derivative(orders: Map<Symbol, Int>): Expression<T> =
derivativeOrNull(orders) ?: error("Derivative with orders $orders not provided")
public fun <T> DifferentiableExpression<T>.derivative(vararg orders: Pair<Symbol, Int>): Expression<T> =
CommanderTvis (Migrated from github.com) commented 2020-10-26 22:55:36 +03:00

Overload with vararg symbols: Symbol for order 1 can be added, too.

Overload with `vararg symbols: Symbol` for order 1 can be added, too.
@ -12,30 +31,69 @@ public fun interface Expression<T> {
* @param arguments the map of arguments.
CommanderTvis (Migrated from github.com) commented 2020-10-26 22:43:11 +03:00

Why is it commented?

Why is it commented?
CommanderTvis (Migrated from github.com) commented 2020-10-26 22:43:42 +03:00

By the way, it is SAM-interface

By the way, it is SAM-interface
CommanderTvis (Migrated from github.com) commented 2020-10-26 22:46:41 +03:00

Operator form can be used: left(arguments)

Operator form can be used: `left(arguments)`
@ -0,0 +12,4 @@
*/
public open class AutoDiffValue<out T>(public val value: T)
CommanderTvis (Migrated from github.com) commented 2020-10-26 22:52:50 +03:00

I am sure that it may be replaced with sealed class to prevent one to extend AutoDiffValue with irrelevant object.

I am sure that it may be replaced with sealed class to prevent one to extend AutoDiffValue with irrelevant object.
altavir (Migrated from github.com) reviewed 2020-10-28 09:26:02 +03:00
altavir (Migrated from github.com) reviewed 2020-10-28 09:27:49 +03:00
@ -0,0 +10,4 @@
public fun <T> DifferentiableExpression<T>.derivative(orders: Map<Symbol, Int>): Expression<T> =
derivativeOrNull(orders) ?: error("Derivative with orders $orders not provided")
public fun <T> DifferentiableExpression<T>.derivative(vararg orders: Pair<Symbol, Int>): Expression<T> =
altavir (Migrated from github.com) commented 2020-10-28 09:27:49 +03:00

No sense in that. People will use first, maximum second derivatives. There is an extension for the first. The second one could be added any moment.

No sense in that. People will use first, maximum second derivatives. There is an extension for the first. The second one could be added any moment.
altavir (Migrated from github.com) reviewed 2020-10-28 09:51:39 +03:00
@ -0,0 +12,4 @@
*/
public open class AutoDiffValue<out T>(public val value: T)
altavir (Migrated from github.com) commented 2020-10-28 09:51:39 +03:00

The idea is that it could be extended anytime. Here AutoDiffValue is just a marker interface. It is possible to even replace it with an inline class, but we need performance measurements to make that change.

The idea is that it could be extended anytime. Here `AutoDiffValue` is just a marker interface. It is possible to even replace it with an inline class, but we need performance measurements to make that change.
altavir (Migrated from github.com) reviewed 2020-10-28 09:52:17 +03:00
altavir (Migrated from github.com) commented 2020-10-28 09:52:16 +03:00

Implementation detail and it looks more readable that way.

Implementation detail and it looks more readable that way.
CommanderTvis (Migrated from github.com) approved these changes 2020-10-28 12:57:33 +03:00
@ -0,0 +35,4 @@
* A factory that converts an expression in autodiff variables to a [DifferentiableExpression]
*/
public interface AutoDiffProcessor<T : Any, I : Any, A : ExpressionAlgebra<T, I>> {
public fun process(function: A.() -> I): DifferentiableExpression<T>
CommanderTvis (Migrated from github.com) commented 2020-10-28 12:56:06 +03:00

SAM

SAM
altavir (Migrated from github.com) reviewed 2020-10-28 13:04:12 +03:00
@ -0,0 +35,4 @@
* A factory that converts an expression in autodiff variables to a [DifferentiableExpression]
*/
public interface AutoDiffProcessor<T : Any, I : Any, A : ExpressionAlgebra<T, I>> {
public fun process(function: A.() -> I): DifferentiableExpression<T>
altavir (Migrated from github.com) commented 2020-10-28 13:04:11 +03:00

I see no reason for that. This interface is mostly implemented by companion objects. Also I plan to add additional methods later.

I see no reason for that. This interface is mostly implemented by companion objects. Also I plan to add additional methods later.
Sign in to join this conversation.
No description provided.