Christian Babsek
06/27/2021, 8:38 AMfun main() {
val X = -1.0f..1.0f step 0.01f
val Y = X.map { it.pow(2) }
val dataset = OnHeapDataset.create(
features = X.map { floatArrayOf(it) }.toTypedArray(),
labels = Y.toList().toFloatArray()
)
val model = Sequential.of(
Input(1),
Dense(4, activation = Activations.Linear),
Dense(1, activation = Activations.Linear)
)
model.use {
it.compile(
optimizer = Adam(),
loss = Losses.MSE,
metric = Metrics.ACCURACY
)
it.summary()
repeat(1000) { i ->
val history = it.fit(
dataset = dataset,
epochs = 100
)
println(it.evaluate(dataset))
listOf(-1f, -0.5f, 0f, 0.5f, 1f)
.map { v -> v to it.predict(floatArrayOf(v)) }
.forEach { println("Prediction for ${it.first}: ${it.second}") }
}
}
}
Its really just a first try and no good code