Explorar o código

Implement improved beta metric

Kirk Trombley %!s(int64=3) %!d(string=hai) anos
pai
achega
f6edd77c1f
Modificáronse 2 ficheiros con 33 adicións e 7 borrados
  1. 18 4
      web/convert.js
  2. 15 3
      web/metrics.js

+ 18 - 4
web/convert.js

@@ -18,10 +18,24 @@ const buildVectorData = (vector, toHue, toLightness, toChroma, toHex) => {
   return { vector, sqMag, mag, unit, hue, lightness, chroma, hex };
 };
 
-const calcImportance = (chroma, lightness, proportion) => 
-  chroma // used linearly
-  - Math.abs((Math.max(0.4, lightness) / 0.75) - 1) // reduce contribution for overly light color - probably a highlight - and increase for low light
-  + 0.5 * Math.tanh(10 * (proportion - 0.25)) // steep ramp centered around 25%
+const calcImportance = (chroma, lightness, proportion) => (
+  // scale the final result by 100 just for clarity
+  100
+  // ramp the proportion value such that 
+  //    proportion > 85% => basically guaranteed to be most important, gets bonus
+  //    proportion < 15% => no way to be most important, goes negative
+  //    otherwise => depend approximately on sqrt(proportion)
+  * ( Math.tanh(100 * (proportion - 0.85))
+    + Math.tanh(100 * (proportion - 0.15))
+    + Math.sqrt(proportion) )
+  // consider the chroma based on the sqrt of its part of chroma + lightness
+  * Math.sqrt(chroma / (chroma + lightness)) 
+  // ramp the lightness value such that
+  //    lightness >> 50% => scale by 3
+  //    lightness << 50% => scale by 1
+  //    otherwise => slightly steep ramp
+  * (2 + Math.tanh(10 * (lightness - 0.5)))
+);
 
 const buildClusterData = (size, inertia, mu1, mu2, mu3, nu1, nu2, nu3, totalSize, toHue, toLightness, toChroma, toHex) => {
   const mu = buildVectorData([mu1, mu2, mu3], toHue, toLightness, toChroma, toHex);

+ 15 - 3
web/metrics.js

@@ -117,14 +117,26 @@ const metrics = {
     displayName: String.raw`\beta`,
     displayBody: p => String.raw`
       \begin{aligned}
-      &C\left(${p}\right) \\
-      - &\left|\frac{\max(\left\{0.4, L\left(${p}\right)\right\})}{0.75} - 1\right| \\
-      + &\frac{1}{2}\tanh{\left(10\left( \frac{\left|${p}\right|}{\left|P\right|} - 0.25 \right)\right)}
+          &100 \\
+        * &\left[
+            \begin{aligned}
+              &\sqrt{\frac{\left|${p}\right|}{\left|P\right|}} \\
+            + &\tanh{\left(100\left(\frac{\left|${p}\right|}{\left|P\right|} - 0.85\right)\right)} \\
+            + &\tanh{\left(100\left(\frac{\left|${p}\right|}{\left|P\right|} - 0.15\right)\right)}
+            \end{aligned}
+          \right] \\
+        * &\sqrt{\frac{C\left(${p}\right)}{C\left(${p}\right) + L\left(${p}\right)}} \\
+        * &\left[
+            2 + \tanh{\left(10\left(L\left(${p}\right) - 0.5\right)\right)}
+          \right]
       \end{aligned}
     `,
     evaluate: data => data.importance,
   },
 };
+// &C\left(${p}\right) \\
+// - &\left|\frac{\max(\left\{0.4, L\left(${p}\right)\right\})}{0.75} - 1\right| \\
+// + &\frac{1}{2}\tanh{\left(10\left( \frac{\left|${p}\right|}{\left|P\right|} - 0.25 \right)\right)}
 
 const applyMetrics = (data, target) => {
   const scores = Object.fromEntries(