diff --git a/src/lib/analysis/types.ts b/src/lib/analysis/types.ts index 8636894..bd3ddae 100644 --- a/src/lib/analysis/types.ts +++ b/src/lib/analysis/types.ts @@ -162,3 +162,5 @@ export type CompoundsClusterizationSummary = { clusteredCount: number; notClusteredCount: number; } + +export type CompoundsClustersSummaryMetrics = [number, number, number, number, number]; diff --git a/src/lib/analysis/utils.ts b/src/lib/analysis/utils.ts index 44fded8..c3f6675 100644 --- a/src/lib/analysis/utils.ts +++ b/src/lib/analysis/utils.ts @@ -1,5 +1,10 @@ import { multi, reduce, single } from "itertools-ts"; -import type { CompoundsClusterGrade, Compound, CompoundsClusterizationSummary } from "./types"; +import type { + CompoundsClusterGrade, + Compound, + CompoundsClusterizationSummary, + CompoundsClustersSummaryMetrics +} from "./types"; import { clusterGraphs } from "../graph/clusterization"; import { calcGraphsClusterAverageDifference, @@ -57,10 +62,10 @@ export function scoreCompoundCluster(clusterGrade: CompoundsClusterGrade, weight / averageDifference ** weights.differenceWeight; } -export function scoreCompoundClustersSummary( +export function calcMetricsForCompoundClustersSummary( summary: CompoundsClusterizationSummary, weights: ClusterizationWeightsConfig, -): number { +): CompoundsClustersSummaryMetrics { const clustersSizes = summary.clusters.map((c) => c.size); const clusterSize = reduce.toAverage(clustersSizes) ?? 0; const clustersRelativeSizes = summary.clusters.map((c) => c.size / summary.clusteredCount); @@ -74,6 +79,14 @@ export function scoreCompoundClustersSummary( const relativeClustered = summary.filteredCount ? summary.clusteredCount / summary.filteredCount : 0; const relativeFiltered = summary.inputCount ? summary.filteredCount / summary.inputCount : 0; + return [clustersScore, clusterSize, clustersCount, relativeClustered, relativeFiltered]; +} + +export function weighCompoundClustersSummaryMetrics( + metrics: CompoundsClustersSummaryMetrics, + weights: ClusterizationWeightsConfig, +): number { + const [clustersScore, clusterSize, clustersCount, relativeClustered, relativeFiltered] = metrics; return clustersScore * clusterSize ** weights.clusterSizeWeight * clustersCount ** weights.clustersCountWeight diff --git a/src/lib/genetic/grade.ts b/src/lib/genetic/grade.ts index 0db1b04..ddff63a 100644 --- a/src/lib/genetic/grade.ts +++ b/src/lib/genetic/grade.ts @@ -2,7 +2,7 @@ import type { TypesConfig, WorldConfig } from '../config/types'; import { createDefaultClusterizationWeightsConfig, gradeCompoundClusters, - scoreCompoundClustersSummary, + calcMetricsForCompoundClustersSummary, weighCompoundClustersSummaryMetrics, } from '../analysis/utils'; import { CompoundsAnalyzer } from '../analysis/compounds'; import type { TotalSummary } from '../analysis/types'; @@ -26,7 +26,8 @@ export function runSimulationForReferenceGrade(worldConfig: WorldConfig, typesCo typesConfig.FREQUENCIES.length, clusterizationWeights.minCompoundSize, ); - const clustersScore = scoreCompoundClustersSummary(clustersSummary, clusterizationWeights); + const clustersMetrics = calcMetricsForCompoundClustersSummary(clustersSummary, clusterizationWeights); + const clustersScore = weighCompoundClustersSummaryMetrics(clustersMetrics, clusterizationWeights); const compoundsAnalyzer = new CompoundsAnalyzer(compounds, sim.atoms, typesConfig.FREQUENCIES.length); const totalSummary: TotalSummary = { @@ -75,7 +76,8 @@ export async function runSimulationForClustersGrade( typesConfig.FREQUENCIES.length, weights.minCompoundSize, ); - const clustersScore = scoreCompoundClustersSummary(clustersSummary, weights); + const clustersMetrics = calcMetricsForCompoundClustersSummary(clustersSummary, weights); + const clustersScore = weighCompoundClustersSummaryMetrics(clustersMetrics, weights); const rawMatrix = [ clustersScore, relativeCompoundedAtomsCount ** weights.relativeCompoundedAtomsCountWeight, diff --git a/src/lib/simulation/simulation.ts b/src/lib/simulation/simulation.ts index 64eff8d..81310af 100644 --- a/src/lib/simulation/simulation.ts +++ b/src/lib/simulation/simulation.ts @@ -21,7 +21,7 @@ import { scoreBilateralSymmetry, scoreSymmetryAxisByQuartering } from "../analys import { createDefaultClusterizationWeightsConfig, gradeCompoundClusters, - scoreCompoundClustersSummary + calcMetricsForCompoundClustersSummary, weighCompoundClustersSummaryMetrics } from "../analysis/utils"; export class Simulation implements SimulationInterface { @@ -265,7 +265,8 @@ export class Simulation implements SimulationInterface { this.config.typesConfig.FREQUENCIES.length, weights.minCompoundSize, ); - const score = scoreCompoundClustersSummary(clustersSummary, weights); + const metrics = calcMetricsForCompoundClustersSummary(clustersSummary, weights); + const score = weighCompoundClustersSummaryMetrics(metrics, weights); console.log('CLUSTERIZATION GRADE', clustersSummary); console.log('CLUSTERIZATION SCORE', score); }