{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "datalore": { "hide_input_from_viewers": true, "hide_output_from_viewers": true, "node_id": "lQbSB87rNAn9lV6poArVWW", "type": "CODE" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%use kmath\n", "%use plotly(0.5.0)\n", "@file:DependsOn(\"org.apache.commons:commons-math3:3.6.1\")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "datalore": { "hide_input_from_viewers": true, "hide_output_from_viewers": true, "node_id": "0UP158hfccGgjQtHz0wAi6", "type": "CODE" } }, "outputs": [], "source": [ "//Plotly.jupyter.notebook()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "datalore": { "hide_input_from_viewers": true, "hide_output_from_viewers": true, "node_id": "Zhgz1Ui91PWz0meJiQpHol", "type": "CODE" } }, "outputs": [], "source": [ "class XYValues(val xValues: DoubleArray, val yValues: DoubleArray) {\n", " init {\n", " require(xValues.size == yValues.size)\n", " }\n", "}\n", "\n", "fun interface XYStatistic {\n", " operator fun invoke(values: XYValues): Double\n", "}\n", "\n", "fun generateParabola(xValues: DoubleArray, a: Double, b: Double, c: Double): XYValues {\n", " val yValues = xValues.map { x -> a * x * x + b * x + c }.toDoubleArray()\n", " return XYValues(xValues, yValues)\n", "}\n", "\n", "fun generateHyperbole(xValues: DoubleArray, gamma: Double, x0: Double, y0: Double): XYValues {\n", " val yValues = xValues.map { x -> y0 + gamma / (x - x0) }.toDoubleArray()\n", " return XYValues(xValues, yValues)\n", "}\n", "\n", "class ConvolutionalXYStatistic(val weights: DoubleArray) : XYStatistic {\n", " override fun invoke(values: XYValues): Double {\n", " require(weights.size == values.yValues.size)\n", " val norm = values.yValues.sum()\n", " return values.yValues.zip(weights) { value, weight -> value * weight }.sum()/norm\n", " }\n", "}" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "datalore": { "hide_input_from_viewers": true, "hide_output_from_viewers": true, "node_id": "ZE2atNvFzQsCvpAF8KK4ch", "type": "CODE" } }, "outputs": [ { "data": { "text/html": [ "