Build tools update. Cleanup

This commit is contained in:
Alexander Nozik 2021-05-14 15:59:17 +03:00
parent fff7377687
commit 42d130f69c
7 changed files with 191 additions and 202 deletions

View File

@ -15,7 +15,7 @@ allprojects {
} }
group = "space.kscience" group = "space.kscience"
version = "0.3.0-dev-8" version = "0.3.0-dev-9"
} }
subprojects { subprojects {

View File

@ -11,10 +11,7 @@ import space.kscience.kmath.tensors.core.BroadcastDoubleTensorAlgebra
// Dataset normalization // Dataset normalization
fun main() { fun main() = BroadcastDoubleTensorAlgebra { // work in context with broadcast methods
// work in context with broadcast methods
BroadcastDoubleTensorAlgebra {
// take dataset of 5-element vectors from normal distribution // take dataset of 5-element vectors from normal distribution
val dataset = randomNormal(intArrayOf(100, 5)) * 1.5 // all elements from N(0, 1.5) val dataset = randomNormal(intArrayOf(100, 5)) * 1.5 // all elements from N(0, 1.5)
@ -43,4 +40,3 @@ fun main() {
println("Mean of scaled:\n${datasetScaled.mean(0, false)}") println("Mean of scaled:\n${datasetScaled.mean(0, false)}")
println("Mean of scaled:\n${datasetScaled.std(0, false)}") println("Mean of scaled:\n${datasetScaled.std(0, false)}")
} }
}

View File

@ -6,15 +6,12 @@
package space.kscience.kmath.tensors package space.kscience.kmath.tensors
import space.kscience.kmath.operations.invoke import space.kscience.kmath.operations.invoke
import space.kscience.kmath.tensors.core.DoubleTensor
import space.kscience.kmath.tensors.core.BroadcastDoubleTensorAlgebra import space.kscience.kmath.tensors.core.BroadcastDoubleTensorAlgebra
import space.kscience.kmath.tensors.core.DoubleTensor
// solving linear system with LUP decomposition // solving linear system with LUP decomposition
fun main () { fun main() = BroadcastDoubleTensorAlgebra {// work in context with linear operations
// work in context with linear operations
BroadcastDoubleTensorAlgebra {
// set true value of x // set true value of x
val trueX = fromArray( val trueX = fromArray(
@ -94,4 +91,3 @@ fun main () {
println("True x:\n$trueX") println("True x:\n$trueX")
println("x founded with LU method:\n$x") println("x founded with LU method:\n$x")
} }
}

View File

@ -25,7 +25,7 @@ interface Layer {
// activation layer // activation layer
open class Activation( open class Activation(
val activation: (DoubleTensor) -> DoubleTensor, val activation: (DoubleTensor) -> DoubleTensor,
val activationDer: (DoubleTensor) -> DoubleTensor val activationDer: (DoubleTensor) -> DoubleTensor,
) : Layer { ) : Layer {
override fun forward(input: DoubleTensor): DoubleTensor { override fun forward(input: DoubleTensor): DoubleTensor {
return activation(input) return activation(input)
@ -62,7 +62,7 @@ class Sigmoid : Activation(::sigmoid, ::sigmoidDer)
class Dense( class Dense(
private val inputUnits: Int, private val inputUnits: Int,
private val outputUnits: Int, private val outputUnits: Int,
private val learningRate: Double = 0.1 private val learningRate: Double = 0.1,
) : Layer { ) : Layer {
private val weights: DoubleTensor = DoubleTensorAlgebra { private val weights: DoubleTensor = DoubleTensorAlgebra {
@ -74,8 +74,8 @@ class Dense(
private val bias: DoubleTensor = DoubleTensorAlgebra { zeros(intArrayOf(outputUnits)) } private val bias: DoubleTensor = DoubleTensorAlgebra { zeros(intArrayOf(outputUnits)) }
override fun forward(input: DoubleTensor): DoubleTensor { override fun forward(input: DoubleTensor): DoubleTensor = BroadcastDoubleTensorAlgebra {
return BroadcastDoubleTensorAlgebra { (input dot weights) + bias } (input dot weights) + bias
} }
override fun backward(input: DoubleTensor, outputError: DoubleTensor): DoubleTensor = DoubleTensorAlgebra { override fun backward(input: DoubleTensor, outputError: DoubleTensor): DoubleTensor = DoubleTensorAlgebra {
@ -175,8 +175,7 @@ class NeuralNetwork(private val layers: List<Layer>) {
@OptIn(ExperimentalStdlibApi::class) @OptIn(ExperimentalStdlibApi::class)
fun main() { fun main() = BroadcastDoubleTensorAlgebra {
BroadcastDoubleTensorAlgebra {
val features = 5 val features = 5
val sampleSize = 250 val sampleSize = 250
val trainSize = 180 val trainSize = 180
@ -238,4 +237,3 @@ fun main() {
println("Test accuracy:$acc") println("Test accuracy:$acc")
} }
}

View File

@ -11,12 +11,9 @@ import space.kscience.kmath.tensors.core.BroadcastDoubleTensorAlgebra
// simple PCA // simple PCA
fun main(){ fun main() = BroadcastDoubleTensorAlgebra { // work in context with broadcast methods
val seed = 100500L val seed = 100500L
// work in context with broadcast methods
BroadcastDoubleTensorAlgebra {
// assume x is range from 0 until 10 // assume x is range from 0 until 10
val x = fromArray( val x = fromArray(
intArrayOf(10), intArrayOf(10),
@ -75,4 +72,3 @@ fun main(){
println("Original value:\n${dataset[n]}") println("Original value:\n${dataset[n]}")
println("Restored value:\n$restored") println("Restored value:\n$restored")
} }
}

View File

@ -19,6 +19,9 @@ import space.kscience.kmath.structures.Buffer
public interface ColumnarData<out T> { public interface ColumnarData<out T> {
public val size: Int public val size: Int
/**
* Provide a column by symbol or null if column with given symbol is not defined
*/
public operator fun get(symbol: Symbol): Buffer<T>? public operator fun get(symbol: Symbol): Buffer<T>?
} }

View File

@ -5,7 +5,7 @@ pluginManagement {
maven("https://repo.kotlin.link") maven("https://repo.kotlin.link")
} }
val toolsVersion = "0.9.6" val toolsVersion = "0.9.7"
val kotlinVersion = "1.5.0" val kotlinVersion = "1.5.0"
plugins { plugins {