# Instance-Based Learning Following Physician Reasoning for Assistance during Medical Consultation
## 5 Medical Consultation Flows
### Selecting an Already Defined Case Type
```
1:\(\text{{includedUTS}}\): \(\text{{includedUTS}}\):```
1:functionsimilarity(CT\({}_{current}\),CT\({}_{j}\))
2:similarity \(\leftarrow\) 0
3:involvedSecTypes \(\leftarrow\) sectionTypesOf(CT\({}_{current}\)) \(\bigcup\) sectionTypesOf(CT\({}_{i}\))
4:relativeWeight \(\leftarrow\) relativeWeightFactor(involvedSecTypes)
5:for sec in involvedSecTypes do
6:if sec.weight \(\
eq\) 0 then
7: cachedSimilarityCC \(\leftarrow\) getSimilarityCCValueFromCache(sec,CT\({}_{i}\))
8:if cachedSimilarityCC is hitted then
9:similarityCC \(\leftarrow\) cachedSimilarityCC
10:else
11:units\({}_{current}\)\(\leftarrow\) getUnitsBySectionType(sec,CT\({}_{current}\))
12:units\({}_{i}\)\(\leftarrow\) getUnitsBySectionType(sec,CT\({}_{i}\))
13:ifunits\({}_{current}\
eq\emptyset\)then
14:ifunits\({}_{i}\
eq\emptyset\)then
15:includedUTs \(\leftarrow\) 0
16:forunit\({}_{current}\) in units\({}_{current}\)do
17:belongs \(\leftarrow\)belongs(unit\({}_{current}\), units\({}_{i}\))
18:ifbelongs then
19:includedUTs \(\leftarrow\) includedUTs \(+\)\(\frac{1}{|\)units\({}_{i}|}\)
20:else
21:includedUTs \(\leftarrow\) includedUTs \(-\)\(\frac{1}{|\)units\({}_{i}|}\)
22:endif
23:endfor
24:similarityCC \(\leftarrow\) max[includedUTs, \(-\)1]
25:else
26:similarityCC \(\leftarrow\) -1
27:endif
28:else
29:similarityCC \(\leftarrow\) 0
30:endif
31:putSimilarityCCValueInCache(similarityCC,sec,CT\({}_{i}\))
32:endif
33:similarity \(\leftarrow\) similarity + (relativeWeight * similarityCC)
34:bestRemain \(\leftarrow\) upperBound(sec, involvedSecTypes)
35:ifsimilarity + bestRemain \(<\) worstSimilarity(_topBest_) then
36:invalidateSimilarityCCValuesOnCache(CT\({}_{i}\))
37:throw discard-low-similarity
38:endif
39:endif
40:endfor
41:return similarity
```

**Algorithm 10** Similarity metric For each identified section type, the similarity of components sharing the same section type must be calculated. A cache containing values of similarity between conceptual components is used to improve the performance of the proposed metric (lines 7-9). To calculate the similarity between conceptual components, the sets of units of thought included in each component are determined. Algorithm 10 implements the rules introduced by Equation (12) for calculating the similarity between two sets of units of thought, including the general scenario (lines 15-24) for non-empty sets, and exceptional scenarios (line 26 and line 29) to address singular situations of empty sets. Moreover, the calculated value of component similarity is cached, to be used in the future (line 31). The partial value of the similarity metric is updated after calculating the similarity between each pair of conceptual components. For each pair of components, the partial similarity is affected by the similarity of the components according to a relative weight factor (line 33). To detect low values of similarity, an upper bound is calculated in order to determine a maximum possible value of similarity (line 34). If the similarity between two case types is detected early as low, it is not required to calculate its exact value. All case types with low _similarity_ are discarded early, and their partial values of component similarity are removed from the cache as they are not fully calculated (lines 35-37). At last, a final value of similarity is returned after iterating over all involved section types (line 41). ### Implementation of Similarity Metric

The similarity metric is an essential feature of the proposed learning method. The metric must be able to accurately compare the similarity between clinical case types, and it also needs to execute as quickly as possible. The similarity metric is highly demanded in virtue of the lazy approach of the learning method. Therefore, several techniques of indexing and cache are applied for reducing the metric execution time. All optimizations implemented to reduce the execution time of the _similarity_ metric are presented in the following paragraphs. _Compare units by canonical form_.