返回题库

概率 由联合边际求协方差

Prob Covariance From Joint Marginals

专题
Probability / 概率
难度
L1
来源
MyntBit

题目详情

给定两个随机变量 X 和 Y 的信息:E[X] = 3,E[Y] = 5,E[XY] = 17。计算 X 和 Y 的协方差 Cov(X, Y)。

任务:使用协方差定义:Cov(X, Y) = E[XY] - E[X] × E[Y] = 17 - 3 × 5 = 17 - 15 = 2。

英文原题

Given two random variables, XX and YY, you are provided with the following information:
EX=3EX = 3
EY=5EY = 5
EXY=17EXY = 17
What is the covariance between XX and YY, denoted as Cov(X,Y)Cov(X, Y)?

解析

问题分析

Given two random variables, XX and YY, you are provided with the following information:
EX=3EX = 3
EY=5EY = 5
EXY=17EXY = 17
What is the covariance between XX and YY, denoted as Cov(X,Y)Cov(X, Y)?

解法

根据题目要求实现相应功能。核心逻辑需要:

// 核心数据结构和方法——根据题目 API 约定实现
// 1. 确定状态表示——选择支持所需操作的数据结构
// 2. 实现核心算法——确保 O(·) 时间复杂度和正确性
// 3. 处理边界条件——空输入、极值参数、并发访问

验证

用具体输入验证:构造已知输入的测试用例,确认输出匹配预期结果。

复杂度与边界

  • 时间复杂度:取决于选用的算法
  • 空间复杂度:取决于数据规模
  • 关键边界条件:空输入、极值参数、并发场景下的正确性保证

英文解析

Analysis

Given two random variables, X and Y, you are provided with: E[X] = 3, E[Y] = 5, E[XY] = 17. The covariance between X and Y is defined as Cov(X,Y) = E[XY] - E[X]*E[Y]. This is the fundamental covariance identity derived from the definition.

Solution

double covarianceFromExpectations(double EX, double EY, double EXY) {
    // Cov(X,Y) = E[XY] - E[X]*E[Y]
    return EXY - EX * EY;  // = 17 - 3*5 = 17 - 15 = 2
}

Complexity & Edge Cases

  • Time complexity: O(1)
  • Space complexity: O(1)
  • Edge cases: (1) Independent variables: Cov = 0 (E[XY] = E[X]*E[Y]) (2) Cov(X,X) = Var(X) (3) Covariance can be negative (inverse relationship)

Verification

Compute Cov(X,Y) = 17 - 15 = 2. Positive covariance indicates X and Y tend to move together. Verify with simulation: generate correlated samples, compute sample covariance, confirm convergence.

Key Considerations

The covariance identity Cov(X,Y) = E[XY] - E[X]*E[Y] is the most fundamental relationship in probability for quantifying linear dependence. In portfolio theory, covariance between asset returns determines diversification benefits. Two assets with positive covariance provide less diversification than assets with zero or negative covariance.