Mathematics for Computer Science

Chapter 15
Mathematical Modeling for Algorithms, AI and Responsible Decisions

Bachelors Program in Computer Science Engineering
Mathematics for Computer Science   •   Post Graduate

Mathematical Modeling for Algorithms, AI and Responsible Decisions

Introduction

Mathematical modeling is the disciplined process of representing a real phenomenon, decision problem, or computational task using variables, assumptions, relationships, and objectives. In computer science, models provide the bridge between an informal problem and an executable algorithm. They determine what is measured, what is optimized, which uncertainties are acknowledged, and which consequences are ignored.

A recommendation engine, fraud detector, medical classifier, route planner, or public-sector allocation system is therefore not merely software. It is the implementation of a mathematical model embedded in data, infrastructure, institutional rules, and human decisions. Responsible modeling requires both technical validity and critical judgment: a model may be statistically accurate while being unfair, unsafe, opaque, or inappropriate for the decision context.

This chapter develops a framework for modeling algorithms and artificial-intelligence systems, with particular attention to optimization, probability, uncertainty, evaluation, fairness, explainability, and governance.

Learning objectives

By the end of this chapter, the reader should be able to:

  1. Formulate a real-world problem as a mathematical model.
  2. Distinguish variables, parameters, objectives, constraints, assumptions, and uncertainty.
  3. Explain how optimization, probability, and statistical learning support algorithms.
  4. Evaluate models using technically and socially appropriate criteria.
  5. Analyze fairness, calibration, robustness, interpretability, and distribution shift.
  6. Design a responsible decision pipeline and identify its limitations.
  7. Apply these ideas to a realistic AI-assisted decision scenario.

1. From problem statement to mathematical model

A useful model begins with a precise decision question. “Predict risk” is incomplete until the model specifies whose risk, over what time interval, using which outcome definition, and for what action. A model should make the following elements explicit:

ElementMeaningExample in loan approval
UnitsObjects about which decisions are madeApplicants
FeaturesObserved explanatory variablesIncome, repayment history
TargetOutcome to predict or estimateDefault within 12 months
Decision variableAction selected by the systemApprove or reject
ParametersQuantities estimated or fixedModel weights, interest rate
ObjectiveQuantity to minimize or maximizeExpected financial loss
ConstraintsConditions that must be satisfiedCapital, legal, fairness limits
AssumptionsConditions under which the model is validStable data-generating process

Let x ∈ ℝᵈ denote a feature vector, y denote an outcome, and a denote an action. A predictive model is commonly written as

ŷ = fθ(x)

where θ is a vector of learned parameters and ŷ is the prediction. A decision rule maps information to an action:

a = π(ŷ, x)

The distinction matters. A prediction such as “probability of default = 0.12” does not itself determine whether a loan should be approved. The decision also depends on benefits, costs, constraints, and institutional policy.

Descriptive, predictive, and prescriptive models

A descriptive model summarizes observed relationships. A predictive model estimates an unknown or future quantity. A prescriptive model recommends an action. These purposes should not be conflated. Correlation can support prediction without establishing causation, and high predictive accuracy does not prove that an intervention will produce the predicted outcome.

For example, a hospital model may predict readmission risk. Using that prediction to assign additional care is a prescriptive use. If historical care was unequal, the prediction may reproduce that inequality unless the entire decision process is examined.

2. Optimization as a foundation for algorithms

Many algorithms solve an optimization problem. In its general form:

minimize J(θ)
subject to gᵢ(θ) ≤ 0, i = 1, …, m
hⱼ(θ) = 0, j = 1, …, r

Here J is the objective function, gᵢ are inequality constraints, hⱼ are equality constraints, and θ is the decision or parameter vector. The feasible set consists of all values satisfying the constraints. A solution is optimal only relative to the selected objective and feasible set.

For supervised learning, empirical risk minimization is commonly written as:

minimize (1/n) ∑ᵢ₌₁ⁿ L(fθ(xᵢ), yᵢ) + λΩ(θ)

where n is the number of training observations, L is a loss function, Ω is a regularization term, and λ ≥ 0 controls the trade-off between data fit and model complexity. The first term measures training error; regularization discourages unstable or overly complex solutions.

For squared-error regression, the loss is:

L(ŷ, y) = (ŷ − y)²

The units of squared error are the square of the target unit. Thus, if y is measured in dollars, mean squared error is measured in dollars², while root mean squared error returns to dollars:

RMSE = √[(1/n) ∑ᵢ₌₁ⁿ (ŷᵢ − yᵢ)²]

Optimization assumptions must be stated. A differentiable convex objective permits stronger guarantees than a non-convex objective. Gradient descent updates parameters according to:

θₜ₊₁ = θₜ − η∇J(θₜ)

where η > 0 is the learning rate and ∇J is the gradient. This update is appropriate when the gradient is available or estimated and the step size is suitably controlled. It does not guarantee a global optimum for arbitrary non-convex problems.

Multi-objective decisions

Real decisions rarely have one objective. A planner may balance cost, travel time, emissions, and equity. One approach is a weighted objective:

J(θ) = w₁J₁(θ) + w₂J₂(θ) + … + wkJk(θ)

where weights wᵢ express priorities. If objectives have different units, normalization is required before combining them. Weights are not neutral technical details: they encode values and should be documented, justified, and reviewed.

3. Probability, uncertainty, and statistical learning

A model should distinguish aleatoric uncertainty, arising from inherent variability, from epistemic uncertainty, arising from limited knowledge or data. Probability provides a language for both, although the interpretation depends on the modeling framework.

The conditional probability of an event Y given features X is:

P(Y = y | X = x)

Bayes’ rule relates posterior, likelihood, prior, and evidence:

P(A | B) = [P(B | A)P(A)] / P(B)

where P(A) and P(B) are probabilities, P(B | A) is the likelihood of B under A, and P(A | B) is the posterior probability. The formula applies when P(B) > 0.

A probabilistic classifier may output p(x) = P(Y = 1 | X = x). A threshold t converts this score into a binary action:

â = 1 if p(x) ≥ t; otherwise â = 0

Changing t changes false-positive and false-negative rates. The threshold should therefore reflect the consequences of errors, not merely a default such as 0.5.

If a false positive costs C_FP and a false negative costs C_FN, a simple expected-loss rule chooses the action with lower conditional expected cost. Under equal action benefits and calibrated probabilities, classify as positive when:

p(x) ≥ CFP / (CFP + CFN)

This threshold assumes only the two stated error costs matter and that p(x) is a valid conditional probability. Different populations, benefits, and resource constraints may require a more complete decision model.

Calibration and discrimination

A model is calibrated if, among cases assigned probability p, the event occurs approximately p proportion of the time. Calibration concerns reliability of probabilities. Discrimination concerns ranking, often summarized by area under the ROC curve. A model can discriminate well but be poorly calibrated, or be calibrated but have weak ranking ability. These are distinct properties.

4. Causal reasoning and the limits of prediction

A predictive association does not establish that changing a feature will change the outcome. A causal model asks what would happen under an intervention. Potential-outcome notation represents Y(1) and Y(0), the outcomes that would occur under treatment and control. The individual treatment effect is:

τ = Y(1) − Y(0)

For one person, both potential outcomes cannot generally be observed simultaneously; this is the fundamental problem of causal inference. Under assumptions such as consistency, exchangeability, and positivity, randomized experiments or carefully designed observational methods can estimate population effects.

Prediction and causal intervention should therefore be separated. A model that identifies people likely to experience poor outcomes may not identify people who would benefit from an intervention. Responsible deployment requires clarity about whether the system predicts, recommends, allocates, or causes a change.

5. Measuring performance responsibly

A confusion matrix for binary classification contains true positives (TP), false positives (FP), true negatives (TN), and false negatives (FN). Important metrics include:

Precision = TP / (TP + FP)
Recall = TP / (TP + FN)
Specificity = TN / (TN + FP)
Accuracy = (TP + TN) / (TP + TN + FP + FN)

These formulas require nonzero denominators. Accuracy can be misleading under class imbalance. For example, a system that labels every case negative achieves 99% accuracy when only 1% of cases are positive, but its recall for the positive class is zero.

Evaluation should use a held-out test set or an appropriate cross-validation design. Temporal prediction requires temporal splitting to avoid using future information. Grouped data require group-aware splitting so that records from the same person or organization do not leak across training and testing sets.

The test distribution should represent the deployment distribution. If P_train(X, Y) differs from P_deploy(X, Y), performance may deteriorate. Covariate shift changes P(X), while concept drift changes the relationship P(Y | X). Monitoring must therefore continue after deployment.

6. Fairness and responsible decisions

Fairness is not a single mathematical property. Common group-based criteria include:

  • Demographic parity: the positive decision rate is similar across groups.
  • Equal opportunity: true-positive rates are similar across groups.
  • Equalized odds: both true-positive and false-positive rates are similar across groups.
  • Calibration within groups: predicted probabilities have similar empirical meaning across groups.

Let A denote a protected-group attribute, Ŷ a decision, and Y the outcome. Demographic parity requires approximately:

P(Ŷ = 1 | A = a) = P(Ŷ = 1 | A = b)

Equal opportunity requires:

P(Ŷ = 1 | Y = 1, A = a) = P(Ŷ = 1 | Y = 1, A = b)

These criteria can conflict, especially when groups have different base rates and predictions are imperfect. Consequently, “fairness” must be connected to the decision’s purpose, legal requirements, stakeholder values, and potential harms. Removing a protected attribute does not guarantee fairness because correlated variables may act as proxies.

Responsible design also includes accessibility, privacy, contestability, human oversight, security, and documentation. A person affected by a high-impact decision may need notice, an understandable explanation, an avenue for appeal, and correction of inaccurate data.

7. Explainability, robustness, and governance

Interpretability has several meanings. A globally interpretable model is understandable as a whole; a locally explainable model provides an explanation for one prediction. Feature importance is not automatically a causal explanation. Explanations should be faithful to the model, stable under small perturbations, understandable to the relevant audience, and useful for contesting or improving a decision.

Robustness concerns sensitivity to noise, adversarial manipulation, missing data, and distribution changes. A simple sensitivity analysis varies an input x by ∆x and observes the output change:

∆ŷ ≈ ∇f(x)ᵀ∆x

This first-order approximation assumes differentiability and sufficiently small perturbations. It can reveal locally influential features but does not establish global behavior.

Governance converts principles into operational controls. A model card or system document should record intended use, prohibited use, data sources, target definition, evaluation populations, limitations, known failure modes, fairness results, version, and monitoring plan. A data sheet should document how data were collected, labeled, transformed, and released.

A responsible lifecycle includes:

  1. Problem framing: identify stakeholders, affected groups, harms, and alternatives to automation.
  2. Data governance: establish provenance, consent, quality, minimization, and access controls.
  3. Model development: select an appropriate objective and validate assumptions.
  4. Pre-deployment testing: evaluate accuracy, subgroup performance, robustness, privacy, and security.
  5. Deployment controls: define human roles, escalation, logging, and rollback.
  6. Continuous monitoring: detect drift, disparate error rates, incidents, and unintended use.
  7. Review and retirement: revise or withdraw the system when assumptions no longer hold.

Worked example: threshold selection under unequal error costs

Suppose a calibrated screening model estimates that a patient has probability p = 0.20 of a condition. A false positive creates a cost of 1 unit, while a false negative creates a cost of 4 units. Using the simplified loss rule:

t = CFP / (CFP + CFN) = 1 / (1 + 4) = 0.20

The recommended positive action is selected when p ≥ 0.20. Since p equals the threshold, the patient is classified positive under the stated rule.

This conclusion is conditional. It assumes calibrated probabilities, only two actions, and costs that adequately represent clinical consequences. In practice, treatment side effects, capacity limits, uncertainty in the cost estimates, and human review must also be modeled.

Applied case: illustrative university scholarship-support system

Background

Consider a fictional university developing a system to identify students who may benefit from early academic support. The system uses attendance, assessment submissions, course activity, and prior academic records. It is intended to recommend outreach, not to deny enrollment or financial aid.

Problem

The initial proposal uses a binary label, “at risk,” and automatically sends intensive intervention to students above a score threshold. Historical data contain unequal participation in online learning, and some students have limited internet access. A model based on activity counts may therefore mistake lack of access for lack of commitment.

Analysis

The team first separates prediction from action. The target is defined as failure to complete a course within the semester, while the action is an invitation to voluntary support. This distinction prevents the prediction from becoming a punitive label.

The team examines missingness by demographic and access groups, tests temporal generalization, and evaluates recall, precision, calibration, and false-negative rates. It also interviews students and advisers. The interviews reveal that students prefer explanations framed as available support rather than judgments about ability.

A constrained decision model is adopted. The system may recommend at most 200 outreach cases per week, and no student is automatically sanctioned. A human adviser reviews recommendations, checks contextual information, and records whether the outreach was appropriate. Students can correct inaccurate records.

Approach and outcome

The university deploys a pilot with monitoring rather than immediate full automation. The model is recalibrated each term, and performance is reported separately for relevant groups. A drift alert is triggered when the distribution of activity features changes substantially. The system is suspended if error rates or adverse effects exceed predefined limits.

The outcome is not simply a higher predictive score. The university obtains a more defensible support process: students receive a transparent opportunity for assistance, advisers retain judgment, and model performance is connected to educational benefit rather than only classification accuracy.

Learning points

  1. The action and its consequences must be modeled explicitly.
  2. Data missingness can represent structural disadvantage rather than random noise.
  3. Fairness analysis requires subgroup evaluation and stakeholder participation.
  4. Human review is meaningful only when reviewers have authority, time, and relevant information.
  5. Monitoring and withdrawal criteria are part of the model’s design, not post-deployment decoration.

Challenges and limitations

Mathematical models simplify reality. Important limitations include:

  • Specification error: the objective or target does not represent the actual social goal.
  • Measurement error: observed variables are imperfect proxies for concepts such as ability, risk, or need.
  • Selection bias: training data exclude relevant populations.
  • Label bias: historical outcomes reflect earlier institutional decisions.
  • Feedback loops: decisions change future data; for example, increased surveillance creates more recorded incidents.
  • Goodhart’s law: when a measure becomes a target, it may cease to be a useful measure.
  • Proxy discrimination: apparently neutral variables encode protected characteristics.
  • Automation bias: users over-trust system recommendations.
  • Privacy and security risk: sensitive data may be exposed or exploited.
  • Objective conflict: improving one metric can worsen another.

No single fairness metric, explanation method, or accuracy score resolves these issues. Technical analysis must be combined with domain expertise, legal review, participatory design, and institutional accountability.

Contemporary developments and best practices

Modern foundation models and generative systems increase the importance of evaluation beyond static test accuracy. Systems may produce plausible but false outputs, reveal sensitive information, amplify stereotypes, or behave unpredictably under prompt variation. Retrieval, tool use, and agentic planning add new failure modes because the system can act on external environments.

Best practice is to define intended use narrowly, maintain traceable data and model versions, test representative scenarios, red-team foreseeable misuse, apply least-privilege access, protect personal data, and provide effective human override. Quantitative uncertainty should be communicated honestly; unsupported precision is not evidence of reliability.

At organizational level, model-risk management should assign ownership, require independent validation for high-impact systems, maintain incident registers, and align controls with applicable privacy, anti-discrimination, safety, and AI governance requirements. Regulation varies by jurisdiction, so legal compliance must be assessed in context rather than inferred from a technical metric.

Chapter Summary

Mathematical modeling converts real problems into structured representations involving variables, parameters, objectives, constraints, assumptions, and uncertainty. Optimization explains how many algorithms learn parameters or choose actions, while probability supports prediction and expected-loss decisions. Performance evaluation requires more than accuracy: calibration, discrimination, error costs, subgroup outcomes, robustness, and distribution shift are also important.

Responsible AI requires distinguishing prediction from causation and recommendation from decision. Fairness criteria may conflict, so their selection must reflect context, law, values, and stakeholder harms. Explainability, privacy, security, human oversight, documentation, monitoring, and appeal mechanisms are essential parts of a deployed system. The central principle is that a model is not responsible merely because its mathematics is sophisticated; responsibility depends on the entire sociotechnical decision process.

Key Terms

Mathematical model: A formal representation of a system, phenomenon, or decision problem.

Feature: An observed input variable used by a model.

Target: The outcome a predictive model is designed to estimate.

Parameter: A quantity learned or fixed within a model.

Objective function: A function minimized or maximized during optimization.

Constraint: A condition restricting feasible solutions.

Empirical risk minimization: Learning by minimizing average loss on observed data.

Regularization: A method that penalizes model complexity.

Calibration: Agreement between predicted probabilities and observed frequencies.

Discrimination: A model’s ability to distinguish cases with different outcomes.

Distribution shift: Change between training and deployment data-generating conditions.

Causal inference: Estimation of effects produced by interventions.

Demographic parity: Similar positive decision rates across groups.

Equal opportunity: Similar true-positive rates across groups.

Robustness: Resistance to noise, perturbation, or changing conditions.

Explainability: The degree to which model behavior can be understood and communicated.

Model drift: Degradation or change in model behavior over time.

Proxy variable: A variable correlated with a sensitive attribute or protected characteristic.

Contestability: The ability of affected people to question or appeal a decision.

Model governance: Organizational controls for development, deployment, monitoring, and retirement.

Review Questions

Short Answer Questions

  1. Distinguish a prediction from a decision rule.
  2. What roles do the objective function and constraints play in an optimization model?
  3. Define calibration and explain why it differs from discrimination.
  4. Why can removing a protected attribute fail to eliminate discrimination?
  5. What is distribution shift, and why should deployed models be monitored?

Long Answer Questions

  1. Explain the complete process of converting an informal real-world problem into a mathematical model.
  2. Discuss empirical risk minimization, regularization, and the assumptions behind gradient descent.
  3. Compare demographic parity, equal opportunity, equalized odds, and calibration.
  4. Explain why predictive association does not establish causation, using a computing or policy example.
  5. Describe a responsible lifecycle for a high-impact AI system, from problem framing to retirement.

Analytical / Application Questions

  1. A classifier is used when false negatives cost three times as much as false positives. Derive the simplified probability threshold and state the assumptions required for using it.
  2. Design an evaluation plan for a model predicting student course failure when records are repeated for the same student and conditions change each semester.
  3. Analyze the scholarship-support case and propose two technical controls and two governance controls that reduce the risk of unfair or harmful decisions.

Multiple Choice Questions with Answers

Question 1

Which component specifies the quantity that an optimization procedure minimizes or maximizes?

A. Feature vector

B. Objective function

C. Protected attribute

D. Test set

Correct Answer: B. Objective function

Question 2

In empirical risk minimization, what is the purpose of the regularization term λΩ(θ)?

A. To increase the number of training observations

B. To convert classification into regression

C. To discourage excessive model complexity

D. To guarantee a global optimum

Correct Answer: C. To discourage excessive model complexity

Question 3

A calibrated model assigns a probability of 0.7 to a large group of cases. What should approximately occur for that group?

A. The model must have 70% accuracy on every individual case

B. Approximately 70% of the cases should experience the event

C. The model must have an ROC area of 0.7

D. Exactly 70% of cases must be classified positive

Correct Answer: B. Approximately 70% of the cases should experience the event

Question 4

If false-positive cost is 1 and false-negative cost is 4, the simplified threshold C_FP ÷ (C_FP + C_FN) is:

A. 0.10

B. 0.20

C. 0.40

D. 0.80

Correct Answer: B. 0.20

Question 5

Which metric is defined as TP ÷ (TP + FN)?

A. Precision

B. Specificity

C. Recall

D. Accuracy

Correct Answer: C. Recall

Question 6

What does demographic parity compare across groups?

A. Positive decision rates

B. False-negative costs only

C. Feature means only

D. Training-set sizes only

Correct Answer: A. Positive decision rates

Question 7

Why is temporal splitting important for many forecasting applications?

A. It guarantees fairness

B. It prevents use of future information when evaluating the past

C. It removes all measurement error

D. It makes every model linear

Correct Answer: B. It prevents use of future information when evaluating the past

Question 8

Which statement best distinguishes causal inference from prediction?

A. Causal inference studies intervention effects, whereas prediction estimates outcomes or risks

B. Prediction always requires randomized trials

C. Causal inference never uses probability

D. Prediction automatically proves that an input causes an outcome

Correct Answer: A. Causal inference studies intervention effects, whereas prediction estimates outcomes or risks

Question 9

Which is an example of a governance control?

A. Increasing the learning rate

B. Adding a hidden layer

C. Defining an appeal and correction process

D. Reducing numerical precision

Correct Answer: C. Defining an appeal and correction process

Question 10

What is a feedback loop in an algorithmic decision system?

A. A fixed parameter that never changes

B. A situation in which decisions alter future data or outcomes used by the system

C. A method for sorting features alphabetically

D. A guarantee that predictions are causal

Correct Answer: B. A situation in which decisions alter future data or outcomes used by the system

Mathematics for Computer Science
Chapter 15 of 15