ITPEC FE Subject B April 2024 Question 14

Source exam: ITPEC FE Subject B April 2024Topic: Math & Data Science

ITPEC FE Subject B April 2024 — Question 14 of 20

Computing cosine similarity between two vectors.

The function calcSim computes cosine similarity:

sxy ÷ √(sxx × syy)

where sxx = Σ(v1[i]²), syy = Σ(v2[i]²), sxy = Σ(v1[i] × v2[i]).

For v1 = {2, 2, 1, 0, 4} and v2 = {3, 1, 1, 1, 2}:

  • sxx = 4 + 4 + 1 + 0 + 16 = 25
  • syy = 9 + 1 + 1 + 1 + 4 = 16
  • sxy = 6 + 2 + 1 + 0 + 8 = 17

Result = 17 ÷ √(25 × 16) = 17 ÷ √400 = 17 ÷ 20 = 0.85 → rounded to first decimal place = 0.9

Why not others:
- (a)–(h) — do not match the computed value of 0.85, which rounds to 0.9

- (j) 1.0 — would mean identical direction vectors; these vectors differ

Key rule: Cosine similarity = Σ(x·y) ÷ √(Σx² · Σy²), ranges from 0 (orthogonal) to 1 (identical direction) for non-negative vectors.

AI-generated — may contain errors

The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.