Skip to content

Commit

Permalink
Updated Flexophore similarity calculations for synthon similarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
korffmo committed Sep 30, 2024
1 parent 52b9bab commit ef65f43
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,27 @@
*
* HistogramMatchCalculator
* @author Modest von Korff
* @version 1.0
* Oct 2, 2012 MvK: Start implementation
* May 15 2013 MvK: Heavy bug detected. Wrong similarity results. reset() added.
* Mar 01 2016 MvK sliding filter added.
* 2020 March, re-written
*/
public class HistogramMatchCalculator {

/**
*
* @param dh1
* @param indexDistHist1At1
* @param indexDistHist1At2
* @param dh2
* @param indexDistHist2At1
* @param indexDistHist2At2
* @return integral of overlap
*/
public static double getSimilarity(DistHist dh1, int indexDistHist1At1, int indexDistHist1At2, DistHist dh2, int indexDistHist2At1, int indexDistHist2At2){

int indexPostStartDistHist1 = dh1.getIndexPosStartForDistHist(indexDistHist1At1, indexDistHist1At2);
int indexPostStartDistHist2 = dh2.getIndexPosStartForDistHist(indexDistHist2At1, indexDistHist2At2);

int n = ConstantsFlexophoreGenerator.BINS_HISTOGRAM;

double sumMin = 0;
double sumMax = 0;

Expand All @@ -64,24 +70,17 @@ public static double getSimilarity(DistHist dh1, int indexDistHist1At1, int inde
sumMin += Math.min(v1, v2);
sumMax += Math.max(v1, v2);
}

double score = sumMin / sumMax;

return score;

}

public static double getPercentageOverlap(DistHist dh1, int indexDistHist1At1, int indexDistHist1At2, DistHist dh2, int indexDistHist2At1, int indexDistHist2At2){

int indexPostStartDistHist1 = dh1.getIndexPosStartForDistHist(indexDistHist1At1, indexDistHist1At2);
int indexPostStartDistHist2 = dh2.getIndexPosStartForDistHist(indexDistHist2At1, indexDistHist2At2);

int n = ConstantsFlexophoreGenerator.BINS_HISTOGRAM;

double sumMin = 0;
double sum1 = 0;
double sum2 = 0;

for (int i = 0; i < n; i++) {
int v1 = dh1.getValueAtAbsolutePosition(indexPostStartDistHist1+i);
int v2 = dh2.getValueAtAbsolutePosition(indexPostStartDistHist2+i);
Expand All @@ -90,11 +89,8 @@ public static double getPercentageOverlap(DistHist dh1, int indexDistHist1At1, i
sum1 += v1;
sum2 += v2;
}

double score = sumMin / Math.max(sum1, sum2);;

return score;

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ObjectiveBlurFlexophoreHardMatchUncovered implements IObjectiveComp

// Changed to 0.9 21.08.2024 MvK
final static double THRESH_NODE_SIMILARITY_START = 0.9;
final static double OPTIMISTIC_HISTOGRAM_THRESH = 0.0;

private static final float INIT_VAL = -1;

Expand Down Expand Up @@ -1128,50 +1129,35 @@ private double getScorePairwiseMapping(int indexNode1Query, int indexNode2Query,
double simHists = getSimilarityHistogram(indexNode1Query, indexNode2Query, indexNode1Base, indexNode2Base);

if(optimisticHistogramSimilarity) {
if (simHists > 0) {
if (simHists >= OPTIMISTIC_HISTOGRAM_THRESH) {
simHists = 1.0;
}
}

if(verbose){
System.out.println("simHists " + Formatter.format2(simHists));
}

// score = simNodePair1 * simNodePair1 * simNodePair2 * simNodePair2 * simHists * simHists * simHists;

score = simNodePair1 * simNodePair1 * simNodePair2 * simNodePair2 * simHists * simHists;


return score;
}

public double getSimilarityNodes(int indexNodeQuery, int indexNodeBase) {

if(arrSimilarityNodes[indexNodeQuery][indexNodeBase] < 0 || verbose){

float similarity = (float)nodeSimilarity.getSimilarity(mdhvQueryBlurredHist.getNode(indexNodeQuery), mdhvBaseBlurredHist.getNode(indexNodeBase));

arrSimilarityNodes[indexNodeQuery][indexNodeBase]=similarity;
}

return arrSimilarityNodes[indexNodeQuery][indexNodeBase];
}

public float getSimilarityHistogram(int indexNode1Query, int indexNode2Query, int indexNode1Base, int indexNode2Base) {

int indexHistogramQuery = DistHist.getIndex(indexNode1Query, indexNode2Query, nodesQuery);

int indexHistogramBase = DistHist.getIndex(indexNode1Base, indexNode2Base, nodesBase);

if(arrSimilarityHistograms[indexHistogramQuery][indexHistogramBase] < 0){

float similarityHistogram = 0;

similarityHistogram =
(float)HistogramMatchCalculator.getSimilarity(
mdhvQueryBlurredHist, indexNode1Query, indexNode2Query, mdhvBaseBlurredHist, indexNode1Base, indexNode2Base);


arrSimilarityHistograms[indexHistogramQuery][indexHistogramBase]=similarityHistogram;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ConstantsFlexophoreGenerator {
*/
// public static final double [] FILTER = FILTER05;
public static final double [] FILTER07_ = {0.125, 0.125, 0.125,0.25,0.125, 0.125, 0.125};
public static final double [] FILTER05_ = {0.125, 0.25,0.25,0.25, 0.125};

public static final double [] FILTER = FILTER07_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class SolutionCompleteGraph extends AMemorizedObject implements Comparabl
private byte maxIndexNodeQuery;

/**
* The index is the index of the node in the query molecule.
* The index is the index of the node in the query molecule. Not matched query nodes contain a -1.
* The value at 'index' is the index of the node in the base molecule.
* Contains the same information as heapIndexBase and heapIndexQuery. Used for fast lookup.
*/
Expand Down

0 comments on commit ef65f43

Please sign in to comment.