Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed Dec 17, 2024
1 parent 6aca07a commit 21f511f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/lib/analysis/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,5 @@ export type CompoundsClusterizationSummary = {
clusteredCount: number;
notClusteredCount: number;
}

export type CompoundsClustersSummaryMetrics = [number, number, number, number, number];
19 changes: 16 additions & 3 deletions src/lib/analysis/utils.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/lib/genetic/grade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/lib/simulation/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { scoreBilateralSymmetry, scoreSymmetryAxisByQuartering } from "../analys
import {
createDefaultClusterizationWeightsConfig,
gradeCompoundClusters,
scoreCompoundClustersSummary
calcMetricsForCompoundClustersSummary, weighCompoundClustersSummaryMetrics
} from "../analysis/utils";

export class Simulation implements SimulationInterface {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 21f511f

Please sign in to comment.