Просмотр исходного кода

Merge branch 'prescore-matrix-updates' of fyindr/siimee into dev

tags/0.0.1^2
maeda 3 лет назад
Родитель
Сommit
4d7baa4b37
3 измененных файлов: 2453 добавлений и 2432 удалений
  1. 2
    2
      backend/db/data-generator/config.json
  2. 41
    21
      backend/db/data-generator/generate.ipynb
  3. 2410
    2409
      backend/db/generated/prescore_matrix.json

+ 2
- 2
backend/db/data-generator/config.json Просмотреть файл

1
 {
1
 {
2
     "mockOutputPath": "./db/generated",
2
     "mockOutputPath": "./db/generated",
3
-    "magic": 10000,
3
+    "magic": 1000,
4
     "total": 100,
4
     "total": 100,
5
     "batchSize": 10,
5
     "batchSize": 10,
6
     "percentageOfSeekers": 90,
6
     "percentageOfSeekers": 90,
7
-    "scoreVals": [107, 414, 721, 1028, 1336, 1648, 2056],
7
+    "scoreVals": [1, 2, 3, 4, 5, 6, 7],
8
     "header": "/**\n* GENERATED MOCK SIIMEE DATA\n*/",
8
     "header": "/**\n* GENERATED MOCK SIIMEE DATA\n*/",
9
     "possibleZipcodes": [
9
     "possibleZipcodes": [
10
         "90012",
10
         "90012",

+ 41
- 21
backend/db/data-generator/generate.ipynb Просмотреть файл

2
  "cells": [
2
  "cells": [
3
   {
3
   {
4
    "cell_type": "code",
4
    "cell_type": "code",
5
-   "execution_count": 15,
5
+   "execution_count": 10,
6
    "metadata": {},
6
    "metadata": {},
7
    "outputs": [
7
    "outputs": [
8
     {
8
     {
10
      "output_type": "stream",
10
      "output_type": "stream",
11
      "text": [
11
      "text": [
12
       "\n",
12
       "\n",
13
-      "Scoring: ((107, 107), (1336, 1336))\n",
14
-      "10000.0\n",
13
+      "Scoring: ((1, 1), (7, 7))\n",
14
+      "1515\n",
15
       "\n",
15
       "\n",
16
-      "Scoring: ((414, 107), (414, 414))\n",
17
-      "8616.0\n",
16
+      "Scoring: ((2, 1), (2, 2))\n",
17
+      "9000\n",
18
       "\n",
18
       "\n",
19
-      "Scoring: ((414, 2056), (1648, 721))\n",
20
-      "5738.0\n",
19
+      "Scoring: ((2, 7), (6, 3))\n",
20
+      "4343\n",
21
       "\n",
21
       "\n",
22
-      "Scoring: ((1648, 721), (107, 414))\n",
23
-      "6173.0\n",
22
+      "Scoring: ((6, 3), (1, 2))\n",
23
+      "4901\n",
24
       "\n",
24
       "\n",
25
-      "Scoring: ((1336, 1648), (1028, 1648))\n",
26
-      "9924.0\n",
25
+      "Scoring: ((5, 6), (4, 6))\n",
26
+      "9000\n",
27
       "\n",
27
       "\n",
28
-      "Scoring: ((107, 414), (721, 721))\n",
29
-      "8616.0\n"
28
+      "Scoring: ((1, 2), (3, 3))\n",
29
+      "7764\n",
30
+      "\n",
31
+      "Scoring: ((1, 1), (1, 1))\n",
32
+      "10000\n"
30
      ]
33
      ]
31
     }
34
     }
32
    ],
35
    ],
35
     "import copy\n",
38
     "import copy\n",
36
     "from itertools import product\n",
39
     "from itertools import product\n",
37
     "from scipy import spatial\n",
40
     "from scipy import spatial\n",
41
+    "import math\n",
42
+    "import numpy\n",
38
     "\n",
43
     "\n",
39
     " \n",
44
     " \n",
40
     "f = open('./config.json')\n",
45
     "f = open('./config.json')\n",
47
     "config[\"file\"] = \"../generated/prescore_matrix.json\"\n",
52
     "config[\"file\"] = \"../generated/prescore_matrix.json\"\n",
48
     "config[\"delimiter\"] = \"-\"\n",
53
     "config[\"delimiter\"] = \"-\"\n",
49
     "config[\"version\"] = \"0.1.0\"\n",
54
     "config[\"version\"] = \"0.1.0\"\n",
55
+    "# max distance = distance between top left and bottom right indices in matrix\n",
56
+    "config[\"max_euclidean_distance\"] =  math.sqrt(\n",
57
+    "    math.pow(len(config[\"all_possible_responses\"])-1, 2) +\n",
58
+    "    math.pow(len(config[\"all_possible_responses\"])-1, 2)\n",
59
+    "    ) \n",
50
     "f.close()\n",
60
     "f.close()\n",
51
     "\n",
61
     "\n",
52
     "def createPermutations(possibilities, size):\n",
62
     "def createPermutations(possibilities, size):\n",
79
     "    b = aspect_ab[1]\n",
89
     "    b = aspect_ab[1]\n",
80
     "    return (1 - spatial.distance.cosine(a,b)) * config[\"magic\"]\n",
90
     "    return (1 - spatial.distance.cosine(a,b)) * config[\"magic\"]\n",
81
     "\n",
91
     "\n",
92
+    "def euclideanDistance(aspect_ab):\n",
93
+    "    a = numpy.array(aspect_ab[0])\n",
94
+    "    b = numpy.array(aspect_ab[1])\n",
95
+    "    return numpy.linalg.norm(a - b)\n",
82
     "\n",
96
     "\n",
83
     "def prescore_matrix_from(vals):\n",
97
     "def prescore_matrix_from(vals):\n",
84
     "    m = {}\n",
98
     "    m = {}\n",
85
     "    for val in vals:\n",
99
     "    for val in vals:\n",
86
     "        m[val] = []\n",
100
     "        m[val] = []\n",
87
     "        for other_val in vals:\n",
101
     "        for other_val in vals:\n",
88
-    "            score = scoreAspect((val, other_val))\n",
102
+    "            distance = euclideanDistance((val,other_val))\n",
103
+    "            score = (config[\"max_euclidean_distance\"] - distance) * config[\"magic\"] + 1515\n",
104
+    "            # score = scoreAspect((val, other_val))\n",
89
     "            adjusted_score = round(score)\n",
105
     "            adjusted_score = round(score)\n",
90
     "            m[val].append(adjusted_score)\n",
106
     "            m[val].append(adjusted_score)\n",
91
     "    return m\n",
107
     "    return m\n",
120
     "        res[5], res[2],\n",
136
     "        res[5], res[2],\n",
121
     "        res[4], res[5],\n",
137
     "        res[4], res[5],\n",
122
     "        res[0], res[1],\n",
138
     "        res[0], res[1],\n",
139
+    "        res[0], res[0],\n",
123
     "    ]\n",
140
     "    ]\n",
124
     "    input_b = [\n",
141
     "    input_b = [\n",
125
-    "        res[4], res[4], # One aspect\n",
142
+    "        res[6], res[6], # One aspect\n",
126
     "        res[1], res[1],\n",
143
     "        res[1], res[1],\n",
127
     "        res[5], res[2],\n",
144
     "        res[5], res[2],\n",
128
     "        res[0], res[1],\n",
145
     "        res[0], res[1],\n",
129
     "        res[3], res[5],\n",
146
     "        res[3], res[5],\n",
130
     "        res[2], res[2],\n",
147
     "        res[2], res[2],\n",
148
+    "        res[0], res[0],\n",
131
     "    ]\n",
149
     "    ]\n",
132
     "    for i in range(round(input_a.__len__() / 2)):\n",
150
     "    for i in range(round(input_a.__len__() / 2)):\n",
133
     "        print(score_aspect(input_a, input_b, m, xy_axis_vals))\n",
151
     "        print(score_aspect(input_a, input_b, m, xy_axis_vals))\n",
150
   }
168
   }
151
  ],
169
  ],
152
  "metadata": {
170
  "metadata": {
153
-  "interpreter": {
154
-   "hash": "a4118c1262ac97709ca0d199809af279fe9249120a4ac5f6c92359d01f3f0cd0"
155
-  },
156
   "kernelspec": {
171
   "kernelspec": {
157
-   "display_name": "Python 3.7.10 64-bit ('base': conda)",
172
+   "display_name": "Python 3.10.6 64-bit",
158
    "language": "python",
173
    "language": "python",
159
    "name": "python3"
174
    "name": "python3"
160
   },
175
   },
168
    "name": "python",
183
    "name": "python",
169
    "nbconvert_exporter": "python",
184
    "nbconvert_exporter": "python",
170
    "pygments_lexer": "ipython3",
185
    "pygments_lexer": "ipython3",
171
-   "version": "3.6.9"
186
+   "version": "3.10.6"
172
   },
187
   },
173
-  "orig_nbformat": 4
188
+  "orig_nbformat": 4,
189
+  "vscode": {
190
+   "interpreter": {
191
+    "hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
192
+   }
193
+  }
174
  },
194
  },
175
  "nbformat": 4,
195
  "nbformat": 4,
176
  "nbformat_minor": 2
196
  "nbformat_minor": 2

+ 2410
- 2409
backend/db/generated/prescore_matrix.json
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


Загрузка…
Отмена
Сохранить