diff --git a/Теория проверки гипотез/Hypothesis-test-demo.ipynb b/Теория проверки гипотез/Hypothesis-test-demo.ipynb
new file mode 100644
index 0000000..20cbe03
--- /dev/null
+++ b/Теория проверки гипотез/Hypothesis-test-demo.ipynb
@@ -0,0 +1,726 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "Rjpi65i51X4wmkUJdDMhaS",
+ "type": "CODE"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ " "
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/html": [
+ " \n",
+ " "
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "@file:Repository(\"https://repo.kotlin.link\")\n",
+ "@file:DependsOn(\"space.kscience:plotlykt-jupyter:0.5.0\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "QzMxgnnJPTHKNoOI418j2g",
+ "type": "CODE"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "Plotly notebook integration switch into the legacy mode.
\n"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "Plotly.jupyter.notebook()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "PjQ7NkcPIyTyKs8StevhmN",
+ "type": "CODE"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "import kotlin.random.Random\n",
+ "\n",
+ "data class Point(val x: Double, val y: Double){\n",
+ " fun distanceTo(other: Point) = sqrt((x-other.x).pow(2) + (y-other.y).pow(2))\n",
+ " \n",
+ " companion object{\n",
+ " val ZERO = Point(0.0, 0.0)\n",
+ " }\n",
+ "}\n",
+ "\n",
+ "\n",
+ "fun interface PointSampler{\n",
+ " fun sample(numPoints: Int, generator: Random): List\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "n0doaXXWBLzfmSnHoBaKQC",
+ "type": "CODE"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "class RectanglePointSampler(\n",
+ " val xRange: ClosedFloatingPointRange, \n",
+ " val yRange: ClosedFloatingPointRange\n",
+ "): PointSampler{\n",
+ " override fun sample(numPoints: Int, generator: Random): List = List(numPoints){\n",
+ " Point(\n",
+ " generator.nextDouble(xRange.start, xRange.endInclusive),\n",
+ " generator.nextDouble(yRange.start, yRange.endInclusive)\n",
+ " )\n",
+ " }\n",
+ "}\n",
+ "\n",
+ "class CirclePointSampler(\n",
+ " val r: Double,\n",
+ ") : PointSampler {\n",
+ " override fun sample(numPoints: Int, generator: Random): List = List(numPoints) {\n",
+ " var res: Point? = null\n",
+ " do {\n",
+ " val newPoint = Point(\n",
+ " generator.nextDouble(-r, r),\n",
+ " generator.nextDouble(-r, r)\n",
+ " )\n",
+ " if (newPoint.distanceTo(Point(0.0, 0.0)) <= r) {\n",
+ " res = newPoint\n",
+ " }\n",
+ " } while (res == null)\n",
+ "\n",
+ " res\n",
+ " }\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "Lez1mX3LFYLUs7ZktJbEze",
+ "type": "CODE"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "fun PointSampler.showPoints(numPoints: Int, generator: Random): Plot = Plotly.plot{\n",
+ " val points = sample(numPoints, generator)\n",
+ " scatter { \n",
+ " x.numbers = points.map { it.x }\n",
+ " y.numbers = points.map { it.y }\n",
+ " mode = ScatterMode.markers\n",
+ " }\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "YT3kegGKf8mXuPJ3lt7hdC",
+ "type": "CODE"
+ },
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ " \n",
+ " \n",
+ " Plotly.kt\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "
\n",
+ " \n",
+ "\n"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {
+ "text/html": {
+ "isolated": true
+ }
+ },
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "RectanglePointSampler(-1.0..1.0, -1.0..1.0).showPoints(2000, Random)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "pwz4QocHd7dmOGm9L7cEc5",
+ "type": "CODE"
+ },
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ " \n",
+ " \n",
+ " Plotly.kt\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "
\n",
+ " \n",
+ "\n"
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {
+ "text/html": {
+ "isolated": true
+ }
+ },
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "CirclePointSampler(1.0).showPoints(2000, Random)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "Tcls1BegHuuMvNgKzRh6sg",
+ "type": "CODE"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "fun interface PointComparisonStatistic{\n",
+ " fun test(lPoints: List, rPoints: List): Double\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "nqvsllZIiL4APzUOC5gehm",
+ "type": "CODE"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "data class SamplePair(val lSample: List, val rSample: List)\n",
+ "\n",
+ "class HypothesisTester(\n",
+ " val generator: Random, \n",
+ " val lSampler: PointSampler, \n",
+ " val rSampler: PointSampler,\n",
+ " val statistic: PointComparisonStatistic,\n",
+ " val numPoints: Int = 200\n",
+ "){\n",
+ " fun generate(numSamples: Int): List = List(numSamples){\n",
+ " val l = lSampler.sample(numPoints, generator)\n",
+ " var r = rSampler.sample(numPoints, generator)\n",
+ " SamplePair(l,r)\n",
+ " }\n",
+ "\n",
+ " fun testAll(numSamples: Int): List = generate(numSamples).map{ \n",
+ " statistic.test(it.lSample, it.rSample) \n",
+ " }\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "val nozikStatistic = PointComparisonStatistic{ lPoints: List, rPoints: List ->\n",
+ " Random.nextDouble() - Random.nextDouble()\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "PWwxzAec2DGNV0Haailwyi",
+ "type": "CODE"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "val svetlichnyiStatistic = PointComparisonStatistic{ lPoints: List, rPoints: List ->\n",
+ " lPoints.map { lPoint ->\n",
+ " rPoints.minOf { rPoint -> \n",
+ " lPoint.distanceTo(rPoint) \n",
+ " }\n",
+ " }.average()\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "pVFRwvJhrD9QKH2dpDk3Zo",
+ "type": "CODE"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "val tihomirovaStatistic = PointComparisonStatistic{ lPoints: List, rPoints: List ->\n",
+ " fun List.minDistance(): Double = map { point1 ->\n",
+ " minOf { point2 -> \n",
+ " if(point1===point2){\n",
+ " Double.MAX_VALUE\n",
+ " } else {\n",
+ " point2.distanceTo(point1)\n",
+ " }\n",
+ " }\n",
+ " }.average()\n",
+ "\n",
+ " lPoints.minDistance() - rPoints.minDistance()\n",
+ "\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "val zelenkinStatistic = PointComparisonStatistic{ lPoints: List, rPoints: List ->\n",
+ " fun List.radius() = max( maxOf{it.x}, maxOf{it.y} )\n",
+ " \n",
+ " fun List.pointsInCircle(): Int{\n",
+ " val radius = radius()\n",
+ " return count{it.distanceTo(Point.ZERO) <= radius}\n",
+ " }\n",
+ "\n",
+ " (lPoints.pointsInCircle() - rPoints.pointsInCircle()).toDouble()\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "HmSMmqRRX1txxfU0KqDhAY",
+ "type": "CODE"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ " \n",
+ " \n",
+ " Plotly.kt\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "
\n",
+ " \n",
+ "\n"
+ ]
+ },
+ "execution_count": 26,
+ "metadata": {
+ "text/html": {
+ "isolated": true
+ }
+ },
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "val squareSampler = RectanglePointSampler(-1.0..1.0, -1.0..1.0)\n",
+ "val circleSampler = CirclePointSampler(1.0)\n",
+ "\n",
+ "val numPoints = 200\n",
+ "val numSamples = 5000\n",
+ "val statistic: PointComparisonStatistic = zelenkinStatistic\n",
+ "\n",
+ "val h0 = HypothesisTester(Random(1234), squareSampler, squareSampler, statistic, numPoints)\n",
+ "val h1 = HypothesisTester(Random(1234), squareSampler, circleSampler, statistic, numPoints)\n",
+ "Plotly.plot {\n",
+ " histogram {\n",
+ " name = \"h0\"\n",
+ " x.numbers = h0.testAll(numSamples)\n",
+ " }\n",
+ " histogram {\n",
+ " name = \"h1\"\n",
+ " x.numbers = h1.testAll(numSamples)\n",
+ " }\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "mydQCeC7dp7J9ErZyKsNNl",
+ "type": "CODE"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "fun interface PointSetStatistic{\n",
+ " fun compute(points: List): Double\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "Lj5vOpsbMjYDZ4snIvASYl",
+ "type": "CODE"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "fun PointSetStatistic.sample(\n",
+ " sampler: PointSampler, \n",
+ " numSamples: Int, \n",
+ " numPoints: Int, \n",
+ " generator: Random = Random\n",
+ "): List = (0 until numSamples).map {\n",
+ " sampler.sample(numPoints, generator)\n",
+ "}.map { compute(it) }"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "mwvWmsV1UXJOZTw6ruoQWT",
+ "type": "CODE"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "val zero = Point(0.0, 0.0)\n",
+ "\n",
+ "fun sosninStstictic(r: Double) = PointSetStatistic{ points ->\n",
+ " points.count { it.distanceTo(zero) >= r }.toDouble()\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "1Kupd5kTvLCaV6ApQAtcyR",
+ "type": "CODE"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ " \n",
+ " \n",
+ " Plotly.kt\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "
\n",
+ " \n",
+ "\n"
+ ]
+ },
+ "execution_count": 30,
+ "metadata": {
+ "text/html": {
+ "isolated": true
+ }
+ },
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "Plotly.plot {\n",
+ " histogram {\n",
+ " name = \"circle 1.0\"\n",
+ " x.numbers = sosninStstictic(1.0).sample(circleSampler, 1000, 200)\n",
+ " }\n",
+ " histogram {\n",
+ " name = \"circle 0.8\"\n",
+ " x.numbers = sosninStstictic(0.8).sample(circleSampler, 1000, 200)\n",
+ " }\n",
+ " histogram {\n",
+ " name = \"square 1.0\"\n",
+ " x.numbers = sosninStstictic(1.0).sample(squareSampler, 1000, 200)\n",
+ " }\n",
+ " histogram {\n",
+ " name = \"square 0.8\"\n",
+ " x.numbers = sosninStstictic(0.8).sample(squareSampler, 1000, 200)\n",
+ " }\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "datalore": {
+ "hide_input_from_viewers": true,
+ "hide_output_from_viewers": true,
+ "node_id": "zh16VG4Q5PXopn2I83BFg6",
+ "type": "CODE"
+ }
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "datalore": {
+ "base_environment": "default",
+ "computation_mode": "JUPYTER",
+ "package_manager": "pip",
+ "packages": [],
+ "report_link": "https://datalore.jetbrains.com/report/ptQDfQAcrjNxzIO0AEqovZ/KHxo8B64QfRV9FrNzSvPIA",
+ "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
+}
diff --git a/Теория проверки гипотез/Naive classifier.ipynb b/Теория проверки гипотез/Naive classifier.ipynb
new file mode 100644
index 0000000..f6eb586
--- /dev/null
+++ b/Теория проверки гипотез/Naive classifier.ipynb
@@ -0,0 +1,617 @@
+{
+ "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",
+ "