|
@@ -61,8 +61,8 @@ const computeVectorData = (vector, toHex, toHue) => {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
-const computeStats = (varFromZero, trueMeanVec, kMeanStruct, toHex, toHue) => ({
|
|
|
- varFromZero,
|
|
|
+const computeStats = (inertia, trueMeanVec, kMeanStruct, toHex, toHue) => ({
|
|
|
+ inertia,
|
|
|
trueMean: computeVectorData(trueMeanVec, toHex, toHue),
|
|
|
kMeans: kMeanStruct.slice(0, 3).map(z => computeVectorData(z, toHex, toHue)),
|
|
|
kWeights: kMeanStruct[3],
|
|
@@ -140,7 +140,7 @@ const selectedSummary = (stats, q) => summarySelectors[state.meanArgument](stats
|
|
|
|
|
|
const metrics = [
|
|
|
// RMS
|
|
|
- (stats, q) => stats.varFromZero - 2 * vectorDot(selectedSummary(stats, q)[0].vector, q.vector),
|
|
|
+ (stats, q) => stats.inertia - 2 * vectorDot(selectedSummary(stats, q)[0].vector, q.vector),
|
|
|
// mean angle
|
|
|
(stats, q) => -vectorDot(selectedSummary(stats, q)[0].unit, q.unit),
|
|
|
// mean dist
|
|
@@ -152,7 +152,7 @@ const metrics = [
|
|
|
// hue angle
|
|
|
(stats, q) => angleDiff(selectedSummary(stats, q)[0].hue, q.hue),
|
|
|
// custom
|
|
|
- (stats, q) => (state.includeX ? stats.varFromZero : 0) - state.closeCoeff * vectorDot(
|
|
|
+ (stats, q) => (state.includeX ? stats.inertia : 0) - state.closeCoeff * vectorDot(
|
|
|
selectedSummary(stats, q)[0][state.normQY ? "unit" : "vector"],
|
|
|
state.normQY ? q.unit : q.vector,
|
|
|
),
|
|
@@ -175,8 +175,8 @@ const calcDisplayMetrics = ({ jabStats, rgbStats }) => {
|
|
|
const yTermRGB = cosAngleRGB * rgbStats.trueMean.magnitude * state.targetColor.rgbData.magnitude;
|
|
|
|
|
|
return {
|
|
|
- stdDevJAB: Math.sqrt(jabStats.varFromZero - 2 * yTermJAB + state.targetColor.jabData.magSq),
|
|
|
- stdDevRGB: Math.sqrt(rgbStats.varFromZero - 2 * yTermRGB + state.targetColor.rgbData.magSq),
|
|
|
+ stdDevJAB: Math.sqrt(jabStats.inertia - 2 * yTermJAB + state.targetColor.jabData.magSq),
|
|
|
+ stdDevRGB: Math.sqrt(rgbStats.inertia - 2 * yTermRGB + state.targetColor.rgbData.magSq),
|
|
|
angleJAB: rad2deg * Math.acos(cosAngleJAB),
|
|
|
angleRGB: rad2deg * Math.acos(cosAngleRGB),
|
|
|
meanDistJAB: vectorDist(state.targetColor.jabData.vector, jabStats.trueMean.vector),
|
|
@@ -196,37 +196,38 @@ const mathArgBest = (mxn, arg) => `\\underset{${arg}}{\\arg\\${mxn}}`;
|
|
|
const mathDefinitions = {
|
|
|
"main-definition": String.raw`
|
|
|
\begin{aligned}
|
|
|
- \text{RMS}_{P}\left(q\right) &= \sqrt{E\left[\left|\left|\vec{q} - \vec{p}\right|\right|^2\right]} = \sqrt{\frac{1}{|P|}\sum_{p \in P}{\left|\left|\vec{p} - \vec{q}\right|\right|^2}} \\
|
|
|
- \vec{\mu}\left(P\right) &= \frac{1}{\left|P\right|}\sum_{p\in P}{\vec{p}} \\
|
|
|
I\left(P\right) &= \frac{1}{\left|P\right|}\sum_{p\in P}{\left|\left|\vec{p}\right|\right|^2} \\
|
|
|
+ \vec{\mu}\left(P\right) &= \frac{1}{\left|P\right|}\sum_{p\in P}{\vec{p}} \\
|
|
|
+ \delta\left(P\right) &= \left|\left| \vec{q} - \vec{\mu}\left(P\right) \right|\right| \\
|
|
|
+ \end{aligned}
|
|
|
+ `,
|
|
|
+ "angle-definition": String.raw`
|
|
|
+ \begin{aligned}
|
|
|
+ \theta\left(P\right) &= \angle \left(\vec{q}, \vec{\mu}\left(P\right)\right) \\
|
|
|
\vec{x}_{\perp} &= \text{oproj}_{\left\{\vec{J}, \vec{L}\right\}}{\vec{x}} \\
|
|
|
- \Delta{\theta}\left(P\right) &= \angle \left(\vec{q}_{\perp}, \vec{\mu}\left(P\right)_{\perp} \right)
|
|
|
+ \phi\left(P\right) &= \angle \left(\vec{q}_{\perp}, \vec{\mu}\left(P\right)_{\perp} \right)
|
|
|
\end{aligned}
|
|
|
`,
|
|
|
+ "rms-definition": String.raw`
|
|
|
+ \sigma\left(P\right) = \sqrt{E\left[\left(\vec{q} - P\right)^2\right]} = \sqrt{\frac{1}{|P|}\sum_{p \in P}{\left|\left|\vec{p} - \vec{q}\right|\right|^2}}
|
|
|
+ `,
|
|
|
"cluster-definition": String.raw`
|
|
|
\begin{aligned}
|
|
|
\left\{P_1, P_2, P_3\right\} &= ${mathArgBest("max", String.raw`\left\{P_1, P_2, P_3\right\}`)} \sum_{i=1}^3 \sum_{p\inP_i} \left|\left| \vec{p} - \vec{\mu}\left(P_i\right) \right|\right|^2 \\
|
|
|
+ \pi_i &= \frac{\left|P_i\right|}{\left|P\right|} \\
|
|
|
M\left(P\right) &= ${mathArgBest("max", "P_i")} \left( \left|P_i\right| \right) \\
|
|
|
m\left(P\right) &= ${mathArgBest("min", "P_i")} \left( \left|P_i\right| \right) \\
|
|
|
- \alpha\left(P\right) &= ${mathArgBest("min", "P_i")} \left[ \frac{\left|P\right|}{\left|P_i\right|} \left|\left| \vec{q} - \vec{\mu}\left(P_i\right) \right|\right| \right] \\
|
|
|
- \omega\left(P\right) &= ${mathArgBest("max", "P_i")} \left[ \frac{\left|P\right|}{\left|P_i\right|} \left|\left| \vec{q} - \vec{\mu}\left(P_i\right) \right|\right| \right]
|
|
|
+ \alpha\left(P\right) &= ${mathArgBest("min", "P_i")} \left[ \frac{1}{\pi_i} \left|\left| \vec{q} - \vec{\mu}\left(P_i\right) \right|\right| \right] \\
|
|
|
+ \omega\left(P\right) &= ${mathArgBest("max", "P_i")} \left[ \frac{1}{\pi_i} \left|\left| \vec{q} - \vec{\mu}\left(P_i\right) \right|\right| \right]
|
|
|
\end{aligned}
|
|
|
`,
|
|
|
- "result-definition": String.raw`
|
|
|
- \left(
|
|
|
- \text{RMS}_P\left(q\right),
|
|
|
- \angle \left(\vec{q}, \vec{\mu}\left(P\right)\right),
|
|
|
- \left|\left| \vec{q} - \vec{\mu}\left(P\right) \right|\right|,
|
|
|
- \Delta{\theta}\left(P\right)
|
|
|
- \right)
|
|
|
- `,
|
|
|
};
|
|
|
|
|
|
const metricText = [
|
|
|
muArg => String.raw`${mathArgBest("min", "P")}\left[I\left(P\right) - 2\vec{q}\cdot \vec{\mu}\left(${muArg}\right)\right]`,
|
|
|
muArg => String.raw`${mathArgBest("max", "P")}\left[\cos\left(\angle \left(\vec{q}, \vec{\mu}\left(${muArg}\right)\right)\right)\right]`,
|
|
|
- muArg => String.raw`${mathArgBest("min", "P")}\left[ ${state.includeScaleInDist ? String.raw`\frac{\left|P\right|}{\left|${muArg}\right|}` : ""} \left|\left| \vec{q} - \vec{\mu}\left(${muArg}\right) \right|\right|^2\right]`,
|
|
|
- muArg => String.raw`${mathArgBest("min", "P")} \left[\angle \left(\vec{q}_{\perp}, \vec{\mu}\left(${muArg}\right)_{\perp} \right)\right]`,
|
|
|
+ muArg => String.raw`${mathArgBest("min", "P")}\left[${state.meanArgument > 0 && state.includeScaleInDist ? String.raw`\frac{\left|P\right|}{\left|${muArg}\right|}` : ""} \left|\left| \vec{q} - \vec{\mu}\left(${muArg}\right) \right|\right|^2\right]`,
|
|
|
+ muArg => String.raw`${mathArgBest("min", "P")}\left[\angle \left(\vec{q}_{\perp}, \vec{\mu}\left(${muArg}\right)_{\perp} \right)\right]`,
|
|
|
].map(s => muArg => TeXZilla.toMathML(s(muArg)));
|
|
|
|
|
|
const muArgs = [
|