618 lines
3.6 MiB
Plaintext
618 lines
3.6 MiB
Plaintext
|
{
|
||
|
"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": [
|
||
|
" <div id=\"kotlin_out_0\"></div>\n",
|
||
|
" <script type=\"text/javascript\">\n",
|
||
|
" if(!window.kotlinQueues) {\n",
|
||
|
" window.kotlinQueues = {};\n",
|
||
|
" }\n",
|
||
|
" if(!window.kotlinQueues[\"plotly\"]) {\n",
|
||
|
" var resQueue = [];\n",
|
||
|
" window.kotlinQueues[\"plotly\"] = resQueue;\n",
|
||
|
" window[\"call_plotly\"] = function(f) {\n",
|
||
|
" resQueue.push(f);\n",
|
||
|
" }\n",
|
||
|
" }\n",
|
||
|
" (function (){\n",
|
||
|
" var modifiers = [(function(script) {\n",
|
||
|
" script.src = \"https://cdn.plot.ly/plotly-1.54.6.min.js\"\n",
|
||
|
" script.type = \"text/javascript\";\n",
|
||
|
"}),\n",
|
||
|
"(function(script) {\n",
|
||
|
" script.textContent = \"/**\\r\\n* plotly.js v1.54.6\\r\\n* Copyright 2012-2020, Plotly, Inc.\\r\\n* All rights reserved.\\r\\n* Licensed under the MIT license\\r\\n*/\\r\\n!function(t){if(\\\"object\\\"==typeof exports&&\\\"undefined\\\"!=typeof module)module.exports=t();else if(\\\"function\\\"==typeof define&&define.amd)define([],t);else{(\\\"undefined\\\"!=typeof window?window:\\\"undefined\\\"!=typeof global?global:\\\"undefined\\\"!=typeof self?self:this).Plotly=t()}}((function(){return function t(e,r,n){function a(o,s){if(!r[o]){if(!e[o]){var l=\\\"function\\\"==typeof require&&require;if(!s&&l)return l(o,!0);if(i)return i(o,!0);var c=new Error(\\\"Cannot find module '\\\"+o+\\\"'\\\");throw c.code=\\\"MODULE_NOT_FOUND\\\",c}var u=r[o]={exports:{}};e[o][0].call(u.exports,(function(t){return a(e[o][1][t]||t)}),u,u.exports,t,e,r,n)}return r[o].exports}for(var i=\\\"function\\\"==typeof require&&require,o=0;o<n.length;o++)a(n[o]);return a}({1:[function(t,e,r){\\\"use strict\\\";var n=t(\\\"../src/lib\\\"),a={\\\"X,X div\\\":\\\"direction:ltr;font-family:'Open Sans', verdana, arial, sans-serif;margin:0;padding:0;\\\",\\\"X input,X button\\\":\\\"font-family:'Open Sans', verdana, arial, sans-serif;\\\",\\\"X input:focus,X button:focus\\\":\\\"outline:none;\\\",\\\"X a\\\":\\\"text-decoration:none;\\\",\\\"X a:hover\\\":\\\"text-decoration:none;\\\",\\\"X .crisp\\\":\\\"shape-rendering:crispEdges;\\\",\\\"X .user-select-none\\\":\\\"-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;\\\",\\\"X svg\\\":\\\"overflow:hidden;\\\",\\\"X svg a\\\":\\\"fill:#447adb;\\\",\\\"X svg a:hover\\\":\\\"fill:#3c6dc5;\\\",\\\"X .main-svg\\\":\\\"position:absolute;top:0;left:0;pointer-events:none;\\\",\\\"X .main-svg .draglayer\\\":\\\"pointer-events:all;\\\",\\\"X .cursor-default\\\":\\\"cursor:default;\\\",\\\"X .cursor-pointer\\\":\\\"cursor:pointer;\\\",\\\"X .cursor-crosshair\\\":\\\"cursor:crosshair;\\\",\\\"X .cursor-move\\\":\\\"cursor:move;\\\",\\\"X .cursor-col-resize\\\":\\\"cursor:col-resize;\\\",\\\"X .cursor-row-resize\\\":\\\"cursor:row-resize;\\\",\\\"X .cursor-ns-resize\\\":\\\"cursor:ns-resize;\\\",\\\"X .cursor-ew-resize\\\":\\\"cursor:ew-resize;\\\",\\\"X .cursor-sw-resize\\\":\\\"cursor:sw-resize;\\\",\\\"X .cursor-s-resize\\\":\\\"cursor:s-resize;\\\",\\\"X .cursor-se-resize\\\":\\\"cursor:se-resize;\\\",\\\"X .cursor-w-resize\\\":\\\"cursor:w-resize;\\\",\\\"X .cursor-e-resize\\\":\\\"cursor:e-resize;\\\",\\\"X .cursor-nw-resize\\\":\\\"cursor:nw-resize;\\\",\\\"X .cursor-n-resize\\\":\\\"cursor:n-resize;\\\",\\\"X .cursor-ne-resize\\\":\\\"cursor:ne-resize;\\\",\\\"X .cursor-grab\\\":\\\"cursor:-webkit-grab;cursor:grab;\\\",\\\"X .modebar\\\":\\\"position:absolute;top:2px;right:2px;\\\",\\\"X .ease-bg\\\":\\\"-webkit-transition:background-color 0.3s ease 0s;-moz-transition:background-color 0.3s ease 0s;-ms-transition:background-color 0.3s ease 0s;-o-transition:background-color 0.3s ease 0s;transition:background-color 0.3s ease 0s;\\\",\\\"X .modebar--hover>:not(.watermark)\\\":\\\"opacity:0;-webkit-transition:opacity 0.3s ease 0s;-moz-transition:opacity 0.3s ease 0s;-ms-transition:opacity 0.3s ease 0s;-o-transition:opacity 0.3s ease 0s;transition:opacity 0.3s ease 0s;\\\",\\\"X:hover .modebar--hover .modebar-group\\\":\\\"opacity:1;\\\",\\\"X .modebar-group\\\":\\\"float:left;display:inline-block;box-sizing:border-box;padding-left:8px;position:relative;vertical-align:middle;white-space:nowrap;\\\",\\\"X .modebar-btn\\\":\\\"position:relative;font-size:16px;padding:3px 4px;height:22px;cursor:pointer;line-height:normal;box-sizing:border-box;\\\",\\\"X .modebar-btn svg\\\":\\\"position:relative;top:2px;\\\",\\\"X .modebar.vertical\\\":\\\"display:flex;flex-direction:column;flex-wrap:wrap;align-content:flex-end;max-height:100%;\\\",\\\"X .modebar.vertical svg\\\":\\\"top:-1px;\\\",\\\"X .modebar.vertical .modebar-group\\\":\\\"display:block;float:none;padding-left:0px;padding-bottom:8px;\\\",\\\"X .modebar.vertical .modebar-group .modebar-btn\\\":\\\"d
|
||
|
" script.type = \"text/javascript\";\n",
|
||
|
"})];\n",
|
||
|
" var e = document.getElementById(\"kotlin_out_0\");\n",
|
||
|
" modifiers.forEach(function (gen) {\n",
|
||
|
" var script = document.createElement(\"script\");\n",
|
||
|
" gen(script)\n",
|
||
|
" script.addEventListener(\"load\", function() {\n",
|
||
|
" window[\"call_plotly\"] = function(f) {f();};\n",
|
||
|
" window.kotlinQueues[\"plotly\"].forEach(function(f) {f();});\n",
|
||
|
" window.kotlinQueues[\"plotly\"] = [];\n",
|
||
|
" }, false);\n",
|
||
|
" script.addEventListener(\"error\", function() {\n",
|
||
|
" window[\"call_plotly\"] = function(f) {};\n",
|
||
|
" window.kotlinQueues[\"plotly\"] = [];\n",
|
||
|
" var div = document.createElement(\"div\");\n",
|
||
|
" div.style.color = 'darkred';\n",
|
||
|
" div.textContent = 'Error loading resource plotly';\n",
|
||
|
" document.getElementById(\"kotlin_out_0\").appendChild(div);\n",
|
||
|
" }, false);\n",
|
||
|
" \n",
|
||
|
" e.appendChild(script);\n",
|
||
|
" });\n",
|
||
|
" })();\n",
|
||
|
" </script>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
" <div id=\"kotlin_out_1\"></div>\n",
|
||
|
" <script type=\"text/javascript\">\n",
|
||
|
" if(!window.kotlinQueues) {\n",
|
||
|
" window.kotlinQueues = {};\n",
|
||
|
" }\n",
|
||
|
" if(!window.kotlinQueues[\"plotlyConnect\"]) {\n",
|
||
|
" var resQueue = [];\n",
|
||
|
" window.kotlinQueues[\"plotlyConnect\"] = resQueue;\n",
|
||
|
" window[\"call_plotlyConnect\"] = function(f) {\n",
|
||
|
" resQueue.push(f);\n",
|
||
|
" }\n",
|
||
|
" }\n",
|
||
|
" (function (){\n",
|
||
|
" var modifiers = [(function(script) {\n",
|
||
|
" script.textContent = \"/**\\r\\n * Use existing plotly or load it from the CDN if it is not available\\r\\n * @param action\\r\\n */\\r\\nfunction withPlotly(action) {\\r\\n if (typeof Plotly !== \\\"undefined\\\") {\\r\\n action(Plotly);\\r\\n } else if (typeof window.promiseOfPlotly !== \\\"undefined\\\") {\\r\\n window.promiseOfPlotly.then(plotly => action(plotly));\\r\\n } else {\\r\\n console.warn(\\\"Plotly not defined. Loading the script from CDN\\\")\\r\\n window.promiseOfPlotly = new Promise((accept, reject) => {\\r\\n let plotlyLoaderScript = document.createElement(\\\"script\\\");\\r\\n plotlyLoaderScript.src = \\\"https://cdnjs.cloudflare.com/ajax/libs/plotly.js/1.54.6/plotly.min.js\\\";\\r\\n plotlyLoaderScript.type = 'text/javascript';\\r\\n plotlyLoaderScript.onload = () => {\\r\\n accept(Plotly);\\r\\n }\\r\\n plotlyLoaderScript.onerror = (error) => {\\r\\n console.error(error);\\r\\n reject(error)\\r\\n }\\r\\n document.head.appendChild(plotlyLoaderScript);\\r\\n });\\r\\n }\\r\\n}\\r\\n\\r\\n/**\\r\\n * Request and parse json from given address\\r\\n * @param url {URL}\\r\\n * @param callback\\r\\n * @return Promise<Json>\\r\\n */\\r\\nfunction getJSON(url, callback) {\\r\\n\\r\\n function handleErrors(response) {\\r\\n if (!response.ok) {\\r\\n throw Error(response.statusText);\\r\\n }\\r\\n return response;\\r\\n }\\r\\n\\r\\n try {\\r\\n fetch(url, {\\r\\n method: 'GET',\\r\\n headers: {\\r\\n Accept: 'application/json',\\r\\n }\\r\\n })\\r\\n .then(handleErrors)\\r\\n .then(response => response.json())\\r\\n .then(json => callback(json))\\r\\n .catch(error => console.log(error));\\r\\n } catch (e) {\\r\\n alert(\\\"Fetch of plot data failed with error: \\\" + e)\\r\\n }\\r\\n}\\r\\n\\r\\n/**\\r\\n * Safe call for Plotly.newPlot\\r\\n * @param id\\r\\n * @param data\\r\\n * @param layout\\r\\n * @param config\\r\\n */\\r\\nfunction makePlot(id, data, layout, config) {\\r\\n withPlotly(plotly => plotly.newPlot(id, data, layout, config))\\r\\n}\\r\\n\\r\\n/**\\r\\n * Create a plot taking data from given url\\r\\n * @param id {string} element id for plot\\r\\n * @param from {URL} json server url\\r\\n * @param config {object} plotly configuration\\r\\n * @return {JSON}\\r\\n */\\r\\nfunction createPlotFrom(id, from, config = {}) {\\r\\n getJSON(from, json => withPlotly(plotly => {\\r\\n plotly.newPlot(id, json.data, json.layout, config)\\r\\n }));\\r\\n}\\r\\n\\r\\n/**\\r\\n * Update a plot taking data from given url\\r\\n * @param id {string} element id for plot\\r\\n * @param from {URL} json server url\\r\\n * @return {JSON}\\r\\n */\\r\\nfunction updatePlotFrom(id, from) {\\r\\n getJSON(from, json => withPlotly(plotly => plotly.react(id, json.data, json.layout)));\\r\\n}\\r\\n\\r\\n/**\\r\\n * Start pull updates with regular requests from client side\\r\\n * @param id {string}\\r\\n * @param from\\r\\n * @param millis\\r\\n */\\r\\nfunction startPull(id, from, millis) {\\r\\n let action = function () {\\r\\n updatePlotFrom(id, from)\\r\\n };\\r\\n window.setInterval(action, millis)\\r\\n}\\r\\n\\r\\n/**\\r\\n * Start push updates via websocket\\r\\n * @param id {string} element id for plot\\r\\n * @param ws {URL} a websocket address\\r\\n */\\r\\nfunction startPush(id, ws) {\\r\\n let socket = new WebSocket(ws);\\r\\n\\r\\n socket.onopen = function () {\\r\\n console.log(\\\"[Plotly.kt] A connection for plot with id = \\\" + id + \\\" with server established on \\\" + ws);\\r\\n };\\r\\n\\r\\n socket.onclose = function (event) {\\r\\n if (event.wasClean) {\\r\\n console.log(\\\"The connection with server is closed\\\");\\r\\n } else {\\r\\n console.log(\\\"The conne
|
||
|
" script.type = \"text/javascript\";\n",
|
||
|
"})];\n",
|
||
|
" var e = document.getElementById(\"kotlin_out_1\");\n",
|
||
|
" modifiers.forEach(function (gen) {\n",
|
||
|
" var script = document.createElement(\"script\");\n",
|
||
|
" gen(script)\n",
|
||
|
" script.addEventListener(\"load\", function() {\n",
|
||
|
" window[\"call_plotlyConnect\"] = function(f) {f();};\n",
|
||
|
" window.kotlinQueues[\"plotlyConnect\"].forEach(function(f) {f();});\n",
|
||
|
" window.kotlinQueues[\"plotlyConnect\"] = [];\n",
|
||
|
" }, false);\n",
|
||
|
" script.addEventListener(\"error\", function() {\n",
|
||
|
" window[\"call_plotlyConnect\"] = function(f) {};\n",
|
||
|
" window.kotlinQueues[\"plotlyConnect\"] = [];\n",
|
||
|
" var div = document.createElement(\"div\");\n",
|
||
|
" div.style.color = 'darkred';\n",
|
||
|
" div.textContent = 'Error loading resource plotlyConnect';\n",
|
||
|
" document.getElementById(\"kotlin_out_1\").appendChild(div);\n",
|
||
|
" }, false);\n",
|
||
|
" \n",
|
||
|
" e.appendChild(script);\n",
|
||
|
" });\n",
|
||
|
" })();\n",
|
||
|
" </script>"
|
||
|
]
|
||
|
},
|
||
|
"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": [
|
||
|
"<div>\n",
|
||
|
" <div id=\"space.kscience.plotly.Plot@4c2575df\">\n",
|
||
|
" <script>if(typeof Plotly !== \"undefined\"){\n",
|
||
|
" Plotly.react(\n",
|
||
|
" 'space.kscience.plotly.Plot@4c2575df',\n",
|
||
|
" [{\"type\":\"scatter\",\"x\":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0],\"y\":[1.0,0.5,0.3333333333333333,0.25,0.2,0.16666666666666666,0.14285714285714285,0.125,0.1111111111111111,0.1]}],\n",
|
||
|
" {},\n",
|
||
|
" {\"responsive\":true}\n",
|
||
|
" ); \n",
|
||
|
"} else {\n",
|
||
|
" console.error(\"Plotly not loaded\")\n",
|
||
|
"}</script>\n",
|
||
|
" </div>\n",
|
||
|
"</div>\n"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 4,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"val xValues = (1.0..10.0).step(1.0).toDoubleArray()\n",
|
||
|
"\n",
|
||
|
"val xy = generateHyperbole(xValues, 1.0, 0.0, 0.0)\n",
|
||
|
"\n",
|
||
|
"Plotly.plot {\n",
|
||
|
" scatter {\n",
|
||
|
" this.x.doubles = xValues\n",
|
||
|
" this.y.doubles = xy.yValues\n",
|
||
|
" }\n",
|
||
|
"}"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 5,
|
||
|
"metadata": {
|
||
|
"datalore": {
|
||
|
"hide_input_from_viewers": true,
|
||
|
"hide_output_from_viewers": true,
|
||
|
"node_id": "EA5HaydTddRKYrtAUwd29h",
|
||
|
"type": "CODE"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"0.05690285869123425"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"val statistic = ConvolutionalXYStatistic(DoubleArray(xValues.size){if(it == 5) 1.0 else 0.0})\n",
|
||
|
"statistic(xy)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"metadata": {
|
||
|
"datalore": {
|
||
|
"hide_input_from_viewers": true,
|
||
|
"hide_output_from_viewers": true,
|
||
|
"node_id": "t5t6IYmD7Q1ykeo9uijFfQ",
|
||
|
"type": "CODE"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import kotlin.random.Random\n",
|
||
|
"\n",
|
||
|
"val random = Random(1288)\n",
|
||
|
"\n",
|
||
|
"val parabolae = buildList{\n",
|
||
|
" repeat(500){\n",
|
||
|
" add(\n",
|
||
|
" generateParabola(\n",
|
||
|
" xValues, \n",
|
||
|
" random.nextDouble(), \n",
|
||
|
" random.nextDouble(), \n",
|
||
|
" random.nextDouble()\n",
|
||
|
" )\n",
|
||
|
" )\n",
|
||
|
" }\n",
|
||
|
"}\n",
|
||
|
"\n",
|
||
|
"val hyperbolae: List<XYValues> = buildList{\n",
|
||
|
" repeat(500){\n",
|
||
|
" add(\n",
|
||
|
" generateHyperbole(\n",
|
||
|
" xValues, \n",
|
||
|
" random.nextDouble()*10, \n",
|
||
|
" random.nextDouble(), \n",
|
||
|
" random.nextDouble()\n",
|
||
|
" )\n",
|
||
|
" )\n",
|
||
|
" }\n",
|
||
|
"}"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"metadata": {
|
||
|
"datalore": {
|
||
|
"hide_input_from_viewers": true,
|
||
|
"hide_output_from_viewers": true,
|
||
|
"node_id": "oXB8lmju7YVYjMRXITKnhO",
|
||
|
"type": "CODE"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
" <div id=\"space.kscience.plotly.Plot@4f62e5c\">\n",
|
||
|
" <script>if(typeof Plotly !== \"undefined\"){\n",
|
||
|
" Plotly.react(\n",
|
||
|
" 'space.kscience.plotly.Plot@4f62e5c',\n",
|
||
|
" [{\"type\":\"scatter\",\"x\":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0],\"y\":[1.8182515643146964,3.898270010290904,7.009592148587894,11.152217979205668,16.326147502144224,22.53138071740356,29.767917624983685,38.03575822488459,47.33490251710628,57.66535050164875]},{\"type\":\"scatter\",\"x\":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0],\"y\":[70.15572488236927,5.619652350116167,3.2181795882334874,2.377473409641433,1.9491511000360195,1.68954932684251,1.5153808262475597,1.390431243595367,1.2964201174448773,1.223122449259014]}],\n",
|
||
|
" {},\n",
|
||
|
" {\"responsive\":true}\n",
|
||
|
" ); \n",
|
||
|
"} else {\n",
|
||
|
" console.error(\"Plotly not loaded\")\n",
|
||
|
"}</script>\n",
|
||
|
" </div>\n",
|
||
|
"</div>\n"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"Plotly.plot { \n",
|
||
|
" scatter { \n",
|
||
|
" x.doubles = xValues\n",
|
||
|
" y.doubles = parabolae[257].yValues\n",
|
||
|
" }\n",
|
||
|
" scatter { \n",
|
||
|
" x.doubles = xValues\n",
|
||
|
" y.doubles = hyperbolae[252].yValues\n",
|
||
|
" }\n",
|
||
|
" }"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 8,
|
||
|
"metadata": {
|
||
|
"datalore": {
|
||
|
"hide_input_from_viewers": true,
|
||
|
"hide_output_from_viewers": true,
|
||
|
"node_id": "8EIIecUZrt2NNrOkhxG5P0",
|
||
|
"type": "CODE"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
" <div id=\"space.kscience.plotly.Plot@2fa00216\">\n",
|
||
|
" <script>if(typeof Plotly !== \"undefined\"){\n",
|
||
|
" Plotly.react(\n",
|
||
|
" 'space.kscience.plotly.Plot@2fa00216',\n",
|
||
|
" [{\"type\":\"histogram\",\"name\":\"parabolae\",\"x\":[0.09757215681863905,0.09506787910530536,0.09469705613755637,0.09554243114607222,0.10488703337158449,0.09465575540566883,0.09496402062198539,0.09521189202019646,0.09424878503591488,0.1069891604390308,0.1023875993443646,0.09561197433235648,0.0975322619072328,0.10099509616110883,0.09448200832999312,0.10573787784002067,0.09718975708499752,0.09683300325053476,0.09568826840852142,0.09586437742682363,0.09423769961962467,0.09541228962610762,0.09475173809680576,0.09638997161500627,0.09398620953138123,0.09514756368448843,0.09509787905871547,0.09542745511750463,0.09582072235854568,0.09535869322729791,0.09694386740435504,0.09399796332647745,0.09804868547570228,0.09731078747399381,0.09459002406240734,0.09649487220762976,0.09506588431374384,0.09906491774431342,0.09410653460133694,0.09914061875219363,0.09451033394232748,0.0951825650118008,0.09475046929808631,0.09592391362405235,0.09635589843147122,0.09915869191596265,0.09384445706837016,0.0936693112029842,0.09978157224868686,0.09479017620312273,0.09526794646989532,0.09459044539629406,0.09754184663628725,0.09669521579193519,0.09491969583610975,0.0957061430564647,0.09359882542486013,0.09481170620536078,0.09565377082841475,0.0982728671573899,0.09960558508242019,0.09580138436512914,0.094349389828034,0.09672802722483817,0.10285101882480681,0.09614203375438002,0.10117249753516211,0.09507608663760128,0.09431909797716746,0.09649522200535625,0.10089323962791498,0.09607897768683837,0.10779688085371181,0.09747390685413773,0.09632033419370431,0.09436353722386642,0.09363773698196881,0.09649633718879289,0.09582625503214796,0.09997400091411106,0.10054457476468298,0.0979150885441069,0.09573848020630078,0.09490321607792368,0.09483685723462824,0.10476630888003173,0.09769222342989194,0.09562862060530472,0.0967365991664387,0.09506341205257485,0.09631966597683762,0.09457481000057415,0.09671576057505434,0.09370979490138888,0.09464560247414136,0.09560709034657551,0.10527850942324246,0.0961240270919987,0.0943463763508137,0.0948657170203369,0.0965105363299553,0.10220158414522926,0.09476712067984416,0.09517512643360825,0.09413990924245205,0.09386934455963675,0.09642536065226409,0.09486706875154785,0.0946204076567158,0.0955400750539939,0.09375083807017524,0.10707779054936965,0.0955809262161496,0.09583227772200778,0.09614778779102928,0.09436069024575357,0.09369227896571851,0.09434082992450205,0.09557055869132965,0.10014706984527026,0.09416220418841548,0.09707686107412601,0.09468556578968586,0.09490399768288064,0.09502525779013034,0.09489851231154552,0.09658147254417436,0.0941601244170636,0.09531788138104264,0.09547806790997097,0.09560149359646651,0.09548289836836013,0.09470797088460163,0.09399425010832946,0.09403325861268304,0.09451099685947767,0.09905334968891391,0.10314775186450587,0.09483351493685706,0.09556186753353518,0.09885224920641007,0.09455836595924011,0.09583840382213948,0.0973483365660293,0.09514334024015031,0.09599663386214617,0.10617201173450978,0.09809133128886383,0.09506725551446439,0.09561726102479817,0.09489762246875097,0.09540939817251086,0.09534775445765586,0.09691098130438737,0.09631864185692304,0.09583325990387614,0.09409289260931547,0.09395864580060516,0.09652489018452651,0.09822740067214257,0.09651540462812573,0.09539062553373284,0.09589193832822389,0.09548973126332225,0.0951105259291199,0.09538370024131217,0.0942400681963109,0.09744541896179808,0.09480941878147979,0.09694004398146862,0.09573491653131593,0.09511132852824111,0.09454024831318741,0.09950391862472713,0.09412864315677937,0.09438106951272378,0.09886302535923353,0.09473949890032601,0.0946498041950058,0.0975661428195182,0.09377599148677097,0.09496209582791418,0.09423120352920973,0.09530234358330869,0.0937010978853049,0.09701364930424508,0.09506997111894701,0.0957475381934772,0.09443141258426249,0.09777405997371556,0.09741172037118681,0.09473807638766289,0.09399338236405246,0.09490491106523975,0.09514315919690072,0.09393055348133578,0.09386009123636509,0.09496595827742478,0.09735757874793294,0.09451009280657374,0.09419594560777463,0.10026999203282123,0.0966
|
||
|
" {},\n",
|
||
|
" {\"responsive\":true}\n",
|
||
|
" ); \n",
|
||
|
"} else {\n",
|
||
|
" console.error(\"Plotly not loaded\")\n",
|
||
|
"}</script>\n",
|
||
|
" </div>\n",
|
||
|
"</div>\n"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 8,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"Plotly.plot { \n",
|
||
|
" histogram { \n",
|
||
|
" name = \"parabolae\"\n",
|
||
|
" x.numbers = parabolae.map { statistic(it) }\n",
|
||
|
" }\n",
|
||
|
" histogram { \n",
|
||
|
" name = \"hyperbolae\"\n",
|
||
|
" x.numbers = hyperbolae.map { statistic(it) }\n",
|
||
|
" }\n",
|
||
|
"}"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"metadata": {
|
||
|
"datalore": {
|
||
|
"hide_input_from_viewers": true,
|
||
|
"hide_output_from_viewers": true,
|
||
|
"node_id": "h7UmglJW5zXkAfKHK40oIL",
|
||
|
"type": "CODE"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"val lossFunction: (XYStatistic) -> Double = { statistic ->\n",
|
||
|
" - abs(parabolae.sumOf { statistic(it) } - hyperbolae.sumOf { statistic(it) })\n",
|
||
|
"}"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 10,
|
||
|
"metadata": {
|
||
|
"datalore": {
|
||
|
"hide_input_from_viewers": true,
|
||
|
"hide_output_from_viewers": true,
|
||
|
"node_id": "VpQCNmHqHGWNEWDU21jh1D",
|
||
|
"type": "CODE"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import org.apache.commons.math3.optimization.*\n",
|
||
|
"import org.apache.commons.math3.analysis.*\n",
|
||
|
"import org.apache.commons.math3.optimization.direct.*\n",
|
||
|
"\n",
|
||
|
"val cmFunction = object: MultivariateFunction{\n",
|
||
|
" override fun value(point: DoubleArray) = lossFunction(ConvolutionalXYStatistic(point))\n",
|
||
|
"}"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"metadata": {
|
||
|
"datalore": {
|
||
|
"hide_input_from_viewers": true,
|
||
|
"hide_output_from_viewers": true,
|
||
|
"node_id": "0EG3K4aCUciMlgGQKPvJ57",
|
||
|
"type": "CODE"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"val optimizer = BOBYQAOptimizer(20)\n",
|
||
|
"\n",
|
||
|
"val result = optimizer.optimize(1000, cmFunction, GoalType.MINIMIZE, xValues)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 12,
|
||
|
"metadata": {
|
||
|
"datalore": {
|
||
|
"hide_input_from_viewers": true,
|
||
|
"hide_output_from_viewers": true,
|
||
|
"node_id": "LelUlY0ZSlJEO9yC6SLk5B",
|
||
|
"type": "CODE"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"[-1.357757502856414E8, -2.0157729926862407E7, -1.003627060413469E7, -3516890.1555952034, 2318972.567610743, 8257264.5552848, 1.4601023119437138E7, 2.149227167045051E7, 2.9007620324898317E7, -1.740750223163073E7]"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 12,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"result.point"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 13,
|
||
|
"metadata": {
|
||
|
"datalore": {
|
||
|
"hide_input_from_viewers": true,
|
||
|
"hide_output_from_viewers": true,
|
||
|
"node_id": "AuFOq5t9KpOIkGrOLsVXNf",
|
||
|
"type": "CODE"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
" <div id=\"space.kscience.plotly.Plot@5e2db79d\">\n",
|
||
|
" <script>if(typeof Plotly !== \"undefined\"){\n",
|
||
|
" Plotly.react(\n",
|
||
|
" 'space.kscience.plotly.Plot@5e2db79d',\n",
|
||
|
" [{\"type\":\"scatter\",\"y\":[-1.357757502856414E8,-2.0157729926862407E7,-1.003627060413469E7,-3516890.1555952034,2318972.567610743,8257264.5552848,1.4601023119437138E7,2.149227167045051E7,2.9007620324898317E7,-1.740750223163073E7]}],\n",
|
||
|
" {},\n",
|
||
|
" {\"responsive\":true}\n",
|
||
|
" ); \n",
|
||
|
"} else {\n",
|
||
|
" console.error(\"Plotly not loaded\")\n",
|
||
|
"}</script>\n",
|
||
|
" </div>\n",
|
||
|
"</div>\n"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 13,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"Plotly.plot { \n",
|
||
|
" scatter { \n",
|
||
|
" y.doubles = result.point\n",
|
||
|
" }\n",
|
||
|
"}"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 14,
|
||
|
"metadata": {
|
||
|
"datalore": {
|
||
|
"hide_input_from_viewers": true,
|
||
|
"hide_output_from_viewers": true,
|
||
|
"node_id": "zvmq42DRdM5mZ3SpzviHwI",
|
||
|
"type": "CODE"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
" <div id=\"space.kscience.plotly.Plot@7fafd693\">\n",
|
||
|
" <script>if(typeof Plotly !== \"undefined\"){\n",
|
||
|
" Plotly.react(\n",
|
||
|
" 'space.kscience.plotly.Plot@7fafd693',\n",
|
||
|
" [{\"type\":\"histogram\",\"name\":\"parabolae\",\"x\":[5205515.312809579,6375246.324648815,5987352.155067531,6392817.26840609,3468645.9061235017,6356880.509818827,6288855.075270301,4968140.793213679,6662583.625132771,315116.19432778587,4607912.598175749,6288910.747441099,5950207.983352768,4160404.9257723507,6402423.903940164,4166851.7579148333,5816858.710931451,6011232.323993853,6095512.734119172,6018427.235380331,6358894.348755626,6466126.109068893,6195009.958410565,6048698.822564775,6885988.811321244,6560181.804128059,6403444.103974401,6400738.573386058,5831737.328346927,6581924.011333345,4701839.329062742,6600389.573549389,5587092.903460046,6113549.876285723,6664550.70410929,6020603.653728937,6236526.733507094,4528514.756342761,6482887.7738151,5477147.188158768,6185837.33939533,6460442.243562793,6315069.843434949,6239885.3156025745,6139871.50475478,5786782.465022334,6565341.48177999,6887776.98173683,4767990.694593278,6354308.062345656,6216632.10792922,6103581.987787359,5488932.557683226,5618226.9622049155,6134300.301246585,6280943.58164353,6851486.367523645,6370580.878121566,6482227.05699627,5606003.968669994,5428990.3974561365,6292858.781609072,6387690.454065881,5724451.659730009,4942119.347742107,6417506.4204417225,4016312.2938123047,6382975.836903243,6493579.298267665,6086854.375324883,5285452.377091059,5776484.92896115,1854444.8122344178,5740553.659527526,6252644.798231345,6476089.978933662,6686149.03823202,5708767.467264858,6386964.592029514,4957004.857490777,4845465.316134362,5668111.4740538765,6430535.879265748,6594814.889043934,6353234.407269365,2269872.2815472647,5822696.9586473955,6251092.444350771,5651817.841749826,6171169.994512965,6085132.578765606,6391811.261600065,5912056.874622286,6860704.801028186,6530620.366077397,6134881.576316113,4108578.8295060266,6337351.960902405,6215921.234149143,6697039.44516111,6315892.200840112,4372093.88521664,6298316.418878413,6395976.1850995775,6849285.154969529,6527525.6553815175,5783890.677509628,6115608.314626916,6373451.493794314,6248477.619259579,6579280.012679917,1967070.2689800144,5941012.825458731,6069804.581421209,6358833.575333485,6713283.917270753,6481713.014501566,6238670.058580119,6265737.685649242,4905082.912737624,6749152.768644526,644623.2574856771,6512300.442914708,6568523.588120869,6374183.043567706,6564125.079147203,5905893.588385889,6698600.890128288,3300503.0761333266,6217492.529463973,6297802.649174991,6395012.425226948,6703417.61357797,6860048.263554827,6481806.781774196,6775715.484899393,5019201.802506458,2803068.296857572,6646212.580110549,5832852.867511986,4992051.435682885,6755284.595057569,5985848.442479344,6171230.768074214,6516170.5308415145,6397830.265254039,591372.8128092716,5270164.134906723,6463763.489466165,5660106.35156448,6510307.208260574,6307566.921226029,6148747.535935668,5612055.97862828,6362400.557326031,6136942.975499027,6421086.248222246,6482000.908556945,5946858.093630122,4804282.528557823,5744960.6850120295,6000235.660908746,5474566.091333541,6330005.5536124855,6374384.208135502,6445248.698511702,6537723.008232231,4898582.299232096,6506883.054902393,5615698.1047811685,5866116.057958944,6375945.636574254,6264027.190097913,5562705.704104284,6282875.884687965,6521023.161766601,5384783.240294777,6232308.189475747,6354515.656423085,5497267.925736422,6625752.537813869,6398675.745454431,6131643.900782975,6372516.746628279,6533838.895872966,4582179.132794289,6516142.520428681,6253350.395308536,6216287.068301194,5319357.300903487,1203081.3277107554,6325502.944611457,6402391.089380275,6583797.802090447,6266315.548097466,6195961.615216198,6644859.897671813,6556884.471282139,5403181.599371933,6696660.95159377,6737727.376923087,5018117.986382562,6097339.143048919,6748844.930157353,6124415.80169035,6395163.95042537,6787138.647759103,1455225.4162812799,6159415.76454279,6304521.352175346,6564257.480400635,6358406.321510715,6827662.536290725,6054806.804704506,6388547.169830894,6882823.1751508685,6727005.667630157,2626077.1312669674,4953850.480372147,2714844.071342984,6301326.698982298,6066576.469453993,6435850.666002125,62
|
||
|
" {},\n",
|
||
|
" {\"responsive\":true}\n",
|
||
|
" ); \n",
|
||
|
"} else {\n",
|
||
|
" console.error(\"Plotly not loaded\")\n",
|
||
|
"}</script>\n",
|
||
|
" </div>\n",
|
||
|
"</div>\n"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 14,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"val resultStatistic = ConvolutionalXYStatistic(result.point)\n",
|
||
|
"Plotly.plot { \n",
|
||
|
" histogram { \n",
|
||
|
" name = \"parabolae\"\n",
|
||
|
" x.numbers = parabolae.map { resultStatistic(it) }\n",
|
||
|
" }\n",
|
||
|
" histogram { \n",
|
||
|
" name = \"hyperbolae\"\n",
|
||
|
" x.numbers = hyperbolae.map { resultStatistic(it) }\n",
|
||
|
" }\n",
|
||
|
"}"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {
|
||
|
"datalore": {
|
||
|
"hide_input_from_viewers": true,
|
||
|
"hide_output_from_viewers": true,
|
||
|
"node_id": "1lBar7ejuP92idI3yiquIG",
|
||
|
"type": "CODE"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"datalore": {
|
||
|
"base_environment": "default",
|
||
|
"computation_mode": "JUPYTER",
|
||
|
"package_manager": "pip",
|
||
|
"packages": [],
|
||
|
"report_row_ids": [],
|
||
|
"version": 3
|
||
|
},
|
||
|
"kernelspec": {
|
||
|
"display_name": "Kotlin",
|
||
|
"language": "kotlin",
|
||
|
"name": "kotlin"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": "text/x-kotlin",
|
||
|
"file_extension": ".kt",
|
||
|
"mimetype": "text/x-kotlin",
|
||
|
"name": "kotlin",
|
||
|
"nbconvert_exporter": "",
|
||
|
"pygments_lexer": "kotlin",
|
||
|
"version": "1.9.23"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 4
|
||
|
}
|