Chapter 15: Safety, Standards, and Ethics
Lesson 5: Ethics: Bias, Accountability, and Job Displacement
This lesson develops a mathematically grounded view of ethical issues in robotics, focusing on how bias enters robot decision pipelines, how accountability can be encoded as constraints on system design and logging, and how job displacement can be modeled using simple dynamical and probabilistic tools familiar from linear control.
1. Ethical Questions in the Sense–Think–Act Loop
A robot is a closed-loop system interacting with the physical and social environment. We can abstract its dynamics as
\[ x_{k+1} = f(x_k, u_k, w_k), \quad y_k = h(x_k, v_k), \quad u_k = \pi_{\theta}(y_0,\dots,y_k) \]
where \( x_k \) is the state, \( u_k \) the control action, \( y_k \) sensor outputs, and \( \pi_{\theta} \) a policy with parameters \( \theta \). Ethical concerns appear whenever:
- Different humans or groups experience systematically different costs or benefits from the same policy \( \pi_{\theta} \) (bias and fairness).
- It is unclear who is responsible for a harmful outcome: designer, integrator, operator, or the organization (accountability).
- The introduction of robots changes the distribution of jobs across time and groups (job displacement).
At a high level, we can think of ethical constraints as restrictions on the set of admissible control policies:
\[ \mathcal{P}_{\text{admissible}} = \left\{ \pi_{\theta} : g_j(\pi_{\theta}) \leq 0,\; j=1,\dots,m \right\}, \]
where each constraint \( g_j(\pi_{\theta}) \) formalizes an ethical rule, such as an upper bound on collision risk or on disparity of outcomes between social groups.
flowchart TD
S["Sensors and data"] --> T["Decision policy pi_theta"]
T --> A["Robot action in world"]
A --> H["Human and societal impact"]
H --> F["Feedback: audits, regulation, norms"]
F --> T
2. Formalizing Bias in Robotic Decision-Making
Suppose the robot makes a discrete decision \( A \in \mathcal{A} \) (e.g., whether to allocate a task, dispatch a delivery robot, or accept a human into a shared workspace) based on an observed context \( Z = (X,G) \), where \( X \) encodes physical/operational variables and \( G \) is a sensitive attribute (e.g. a protected group label). A stochastic policy is
\[ \pi_{\theta}(a \mid z) = \mathbb{P}(A = a \mid Z = z;\theta), \quad \sum_{a \in \mathcal{A}} \pi_{\theta}(a \mid z) = 1. \]
Let \( Y \) denote an outcome indicator (e.g. a task successfully completed, a safe interaction, a job retained). From statistical learning, typical loss-based training minimizes
\[ R(\theta) = \mathbb{E}\bigl[ L(A, Y, Z) \bigr], \]
which aggregates performance across the entire population. Ethical analysis asks: how is this risk distributed across groups? Define the group-conditional risk:
\[ R_g(\theta) = \mathbb{E}\bigl[ L(A, Y, Z) \mid G = g \bigr], \quad g \in \{0,1\}. \]
A simple scalar measure of disparity is
\[ \Delta_R(\theta) = \bigl| R_1(\theta) - R_0(\theta) \bigr|. \]
We call a policy \( \varepsilon \)-fair (for this metric) if \( \Delta_R(\theta) \leq \varepsilon \). In practice we have a finite dataset \( \{(a_i,y_i,z_i)\}_{i=1}^N \). The empirical versions are
\[ \widehat{R}_g(\theta) = \frac{1}{N_g} \sum_{i : G_i = g} L(a_i, y_i, z_i), \quad \widehat{\Delta}_R(\theta) = \bigl| \widehat{R}_1(\theta) - \widehat{R}_0(\theta) \bigr|. \]
One principled way to train a policy with explicit fairness is to solve a constrained optimization problem:
\[ \begin{aligned} &\min_{\theta} & R(\theta) \\ &\text{s.t.} & \Delta_R(\theta) \leq \varepsilon. \end{aligned} \]
Alternatively, we can add a penalty:
\[ J_{\lambda}(\theta) = R(\theta) + \lambda \cdot \bigl( \Delta_R(\theta) \bigr)^2, \]
where the hyperparameter \( \lambda \) trades overall performance against fairness. Although this formulation comes from machine learning, it applies directly to robots whose decisions are produced by learned policies, schedulers, or dispatch algorithms.
Other widely discussed metrics include:
- Statistical parity: \( \mathbb{P}(A = a^\star \mid G = 1) \) should be close to \( \mathbb{P}(A = a^\star \mid G = 0) \) for desirable actions \( a^\star \).
- Equal opportunity: conditional on a ground-truth desirable outcome \( Y = 1 \), the probability of receiving the beneficial action \( A = a^\star \) should be similar across groups.
A key theoretical insight (from the fairness-in-ML literature) is that different metrics can be mutually incompatible except in special cases; hence, designers must explicitly choose which notion of fairness to prioritize in a robotic system.
3. Expected Harm and Risk-Bounded Control
Consider a finite-horizon cost functional that combines safety and utility:
\[ J(\pi_{\theta}) = \mathbb{E} \left[ \sum_{k=0}^{T} \gamma^k c(x_k, u_k) \right], \quad 0 < \gamma \leq 1, \]
where \( c(x_k,u_k) \) is large when the robot causes harm (e.g., near-collision, excessive force, violation of a human's preference). For a sensitive group \( G \), we can similarly define
\[ J_g(\pi_{\theta}) = \mathbb{E} \left[ \sum_{k=0}^{T} \gamma^k c(x_k, u_k) \;\middle|\; G = g \right]. \]
Safety standards are often formulated as risk bounds:
\[ \mathbb{P} \bigl( x_k \notin \mathcal{S} \text{ for some } k \in \{0,\dots,T\} \bigr) \leq \delta, \]
where \( \mathcal{S} \) is a safe set and \( \delta \) is a small allowed probability of leaving it. To connect expected harm and probabilistic safety, suppose we define a nonnegative random variable \( C = \sum_{k=0}^{T} c(x_k,u_k) \) that counts “units of harm”. By Markov's inequality, for any \( \alpha > 0 \):
\[ \mathbb{P}(C \geq \alpha) \leq \frac{\mathbb{E}[C]}{\alpha}. \]
Thus, if we can design a controller such that \( \mathbb{E}[C] \leq \bar{c} \), then we automatically have \( \mathbb{P}(C \geq \alpha) \leq \bar{c}/\alpha \). This provides a conservative but mathematically simple bridge from expected-cost design (common in control) to probabilistic safety claims appearing in ethical and regulatory discussions.
For fairness, we may wish to require the same chance-constraint for each group:
\[ \mathbb{P} \bigl( C_g \geq \alpha \bigr) \leq \delta \quad \text{for all } g, \]
which adds a vector of risk constraints, one per group, on top of classical control design objectives.
4. Accountability as a System-Level Property
Accountability asks: when something goes wrong, who can be held responsible, and on what evidence? For a robot, we can formalize its execution trace up to time \( T \) as a log
\[ \ell_{0:T} = \bigl( \ell_0,\dots,\ell_T \bigr), \quad \ell_k = (t_k, x_k, y_k, u_k, \theta, m_k), \]
where \( m_k \) stores metadata (software version, operator ID, environment conditions). An audit function is a (possibly randomized) map
\[ \mathcal{A} : \mathcal{L}^{T+1} \to \{0,1,\dots,M\}, \]
where output 0 means “no violation detected” and positive integers label different types of ethical or regulatory violations. From a mathematical standpoint, accountability is limited by identifiability: if two different design choices produce indistinguishable logs, then no auditor can separate them.
Formally, two design configurations \( (\pi_{\theta}, \text{organization}_1) \) and \( (\pi_{\theta'}, \text{organization}_2) \) are observationally equivalent if
\[ \mathbb{P}_{\theta}(\ell_{0:T}) = \mathbb{P}_{\theta'}(\ell_{0:T}) \quad \text{for all log sequences } \ell_{0:T}. \]
In that case, no log-based criterion can allocate blame uniquely. This motivates design practices such as rich logging, cryptographic signatures, and separation of duties.
flowchart TD
D["Robot designers"] --> M["Manufacturers"]
M --> I["System integrators"]
I --> O["Operators / supervisors"]
O --> L["Runtime logs and monitors"]
L --> R["Auditors / regulators"]
R --> P["Impacted public"]
From the perspective of robot software architecture (e.g. ROS/ROS2), accountability suggests requirements such as:
- Each safety-critical node must log its inputs and outputs with timestamps.
- Decisions must be traceable to a specific software version and configuration.
- Logs must include enough context (including group-related variables) to perform fairness analysis, subject to privacy constraints.
5. Job Displacement as a Simple Dynamical System
Robots change the structure of labor markets over time. While full economic modeling is far beyond this course, we can use tools from linear systems and Markov chains to obtain a conceptual model of job displacement.
Consider three employment states for a worker:
- \( s_1 \): employed in an automatable job,
- \( s_2 \): employed in a new (robot-complementary) job,
- \( s_3 \): unemployed or out of the labor force.
Let \( p_k \in \mathbb{R}^3 \) be the probability vector over states at discrete time \( k \) (e.g. years), so \( p_k(i) = \mathbb{P}(s_i \text{ at time } k) \) and \( \mathbf{1}^{\top}p_k = 1 \). A Markov model assumes
\[ p_{k+1} = P p_k, \quad P \in \mathbb{R}^{3 \times 3}, \quad \sum_{j=1}^{3} P_{ij} = 1,\; P_{ij} \geq 0. \]
The entries of \( P \) encode transition probabilities (e.g. the probability that a worker in an automatable job becomes unemployed after robots are introduced). If we consider two demographic groups \( G = 0,1 \), we might have two matrices \( P^{(0)} \) and \( P^{(1)} \). Their stationary distributions \( p^{\star,(g)} \) satisfy
\[ p^{\star,(g)} = P^{(g)} p^{\star,(g)}, \quad \mathbf{1}^{\top} p^{\star,(g)} = 1. \]
A simple long-run measure of displacement disparity is
\[ \Delta_{\text{unemp}} = \bigl| p^{\star,(1)}_3 - p^{\star,(0)}_3 \bigr|, \]
the absolute difference in equilibrium unemployment probabilities. Ethical and policy-oriented design of robotic systems may aim to keep this quantity below a tolerable threshold, or to adjust training and re-skilling programs so that transition probabilities leading to \( s_2 \) increase for vulnerable groups.
This model is of course highly simplified, but it shows how linear dynamical models and eigenstructure can be used to reason about macro-level effects of robotics in a mathematically transparent way.
6. Code Patterns for Fairness Checks and Accountability Logs
Although this course is primarily conceptual, it is useful to see how bias and accountability can be checked in software. Below are small, self-contained examples in Python, C++, Java, and MATLAB that operate on simple logs of robot decisions.
6.1 Python: Groupwise Risk and Disparity
Assume we have arrays of instantaneous costs and group labels collected from a robot's operation (e.g. one log record per human–robot interaction).
import numpy as np
def group_risk(costs, groups, g):
"""
costs : 1D numpy array of nonnegative costs for each interaction
groups: 1D numpy array of group labels (0 or 1)
g : group of interest (0 or 1)
"""
mask = (groups == g)
if not np.any(mask):
raise ValueError(f"No samples for group {g}")
return float(costs[mask].mean())
def disparity(costs, groups):
r0 = group_risk(costs, groups, 0)
r1 = group_risk(costs, groups, 1)
return abs(r1 - r0)
# Example usage with a simple threshold
eps = 0.05 # allowed disparity
costs = np.array([0.0, 1.0, 0.2, 0.1, 0.7, 0.3])
groups = np.array([0, 0, 1, 1, 1, 0])
d = disparity(costs, groups)
print("Estimated disparity:", d)
if d > eps:
print("Warning: fairness constraint violated.")
6.2 C++: Logging Costs and Computing Group Risk
A minimal C++ example (e.g. as part of a ROS2 node) might look like:
#include <vector>
#include <stdexcept>
#include <iostream>
struct LogEntry {
int group; // 0 or 1
double cost; // nonnegative cost for this interaction
};
double groupRisk(const std::vector<LogEntry> &log, int g) {
double sum = 0.0;
std::size_t count = 0;
for (const auto &e : log) {
if (e.group == g) {
sum += e.cost;
++count;
}
}
if (count == 0) {
throw std::runtime_error("No samples for requested group");
}
return sum / static_cast<double>(count);
}
int main() {
std::vector<LogEntry> log = {
{0, 0.0}, {0, 1.0}, {1, 0.2}, {1, 0.1}, {1, 0.7}, {0, 0.3}
};
double r0 = groupRisk(log, 0);
double r1 = groupRisk(log, 1);
double disparity = std::abs(r1 - r0);
std::cout << "r0 = " << r0 << ", r1 = " << r1
<< ", disparity = " << disparity << std::endl;
const double eps = 0.05;
if (disparity > eps) {
std::cout << "Warning: fairness constraint violated." << std::endl;
}
return 0;
}
6.3 Java: Simple Accountability Log and Audit Check
In Java, we can define a log entry with enough fields to support later audits.
import java.time.Instant;
import java.util.List;
class LogEntry {
public final Instant timestamp;
public final int group; // 0 or 1
public final double cost; // harm metric
public final String nodeId; // software component
public final String version;
public LogEntry(Instant ts, int group, double cost,
String nodeId, String version) {
this.timestamp = ts;
this.group = group;
this.cost = cost;
this.nodeId = nodeId;
this.version = version;
}
}
class Audit {
public static double groupRisk(List<LogEntry> log, int g) {
double sum = 0.0;
int count = 0;
for (LogEntry e : log) {
if (e.group == g) {
sum += e.cost;
count++;
}
}
if (count == 0) {
throw new IllegalArgumentException("No samples for group " + g);
}
return sum / (double) count;
}
public static boolean checkDisparity(List<LogEntry> log, double eps) {
double r0 = groupRisk(log, 0);
double r1 = groupRisk(log, 1);
double d = Math.abs(r1 - r0);
return d <= eps;
}
}
6.4 MATLAB/Simulink: Markov Model for Job States
The following MATLAB script constructs a simple three-state Markov chain for employment status and computes the stationary distribution as the eigenvector of \( P^{\top} \) associated with eigenvalue 1.
% Transition matrix P for [s1; s2; s3]
% Rows sum to 1. Example parameters (conceptual only):
alpha = 0.2; % prob. worker in s1 moves to s2 (retrained)
beta = 0.1; % prob. worker in s1 moves to s3 (unemployed)
gamma = 0.1; % prob. worker in s3 moves to s2 (re-employed)
P = [1 - alpha - beta, alpha, beta;
0.0, 0.9, 0.1;
0.0, gamma, 1 - gamma];
% Check row sums
rowSums = sum(P, 2);
% Compute eigenvalues and eigenvectors of P'
[V, D] = eig(P.');
% Find the eigenvector corresponding to eigenvalue 1
[~, idx] = min(abs(diag(D) - 1.0));
p_star = V(:, idx);
p_star = p_star / sum(p_star); % normalize to sum to 1
disp('Stationary distribution p_star:');
disp(p_star);
unemployment_rate = p_star(3);
fprintf('Long-run unemployment probability: %.3f\n', unemployment_rate);
In a Simulink model, the same Markov update \( p_{k+1} = P p_k \) can be represented by a discrete-time State-Space or Matrix Gain block updating at yearly or quarterly timesteps, with parameters \( \alpha,\beta,\gamma \) tuned to match different robot deployment scenarios.
7. Problems and Solutions
Problem 1 (Risk Disparity from Logs).
A collaborative robot keeps a log of 100 human–robot interactions. For
group
\( G = 0 \) there are 40 interactions with average cost
\( \bar{c}_0 = 0.2 \). For group
\( G = 1 \) there are 60 interactions with average cost
\( \bar{c}_1 = 0.35 \).
(a) Compute the empirical disparity
\( \widehat{\Delta}_R \).
(b) For an allowed threshold \( \varepsilon = 0.1 \),
decide whether the empirical fairness constraint is satisfied.
Solution. (a) By definition,
\[ \widehat{\Delta}_R = \bigl| \bar{c}_1 - \bar{c}_0 \bigr| = \bigl| 0.35 - 0.2 \bigr| = 0.15. \]
(b) Since \( \widehat{\Delta}_R = 0.15 > 0.1 = \varepsilon \), the empirical fairness constraint is violated. From an ethical standpoint, we should investigate the source of this disparity (sensor noise, environment, policy parameters, task allocation rules) and potentially adjust the controller or operating procedures.
Problem 2 (Effect of an Additive Bias Term). Consider a simple linear decision rule for allocating a robot's assistance effort \( u \) based on a scalar feature \( x \) (e.g. estimated workload) and group \( G \in \{0,1\} \):
\[ u = k x + b G, \]
where \( k \) and \( b \) are real parameters. Assume \( x \) has the same distribution in both groups and \( \mathbb{E}[x] = \mu_x \). Let the “benefit” to a human be equal to \( u \). Compute the difference in expected benefit between the two groups as a function of \( b \), and interpret the special case \( b = 0 \).
Solution. For \( G = 0 \) we have \( u_0 = k x \), so \( \mathbb{E}[u_0] = k \mathbb{E}[x] = k \mu_x \). For \( G = 1 \) we have \( u_1 = k x + b \), so \( \mathbb{E}[u_1] = k \mu_x + b \). The difference is
\[ \mathbb{E}[u_1] - \mathbb{E}[u_0] = (k \mu_x + b) - k \mu_x = b. \]
Thus \( b \) directly encodes an additive bias in expected benefit between the two groups. When \( b = 0 \), the decision rule is group-neutral in expectation (for this scalar model), although other forms of bias (e.g. through the distribution of \( x \)) may still exist.
Problem 3 (Markov Inequality for Safety). A mobile robot has a nonnegative random collision cost \( C \) over one mission. Suppose the controller is designed so that \( \mathbb{E}[C] \leq 0.01 \). Use Markov's inequality to upper-bound the probability that \( C \geq 1 \). Interpret the result.
Solution. Markov's inequality states that for \( C \geq 0 \) and \( \alpha > 0 \),
\[ \mathbb{P}(C \geq \alpha) \leq \frac{\mathbb{E}[C]}{\alpha}. \]
Taking \( \alpha = 1 \) and using the bound on the expectation, we obtain
\[ \mathbb{P}(C \geq 1) \leq \frac{0.01}{1} = 0.01. \]
So, the probability that the collision cost exceeds 1 unit is at most 1%. The bound may be loose, but it provides a mathematically certified guarantee connecting design-time expected cost to a worst-case failure probability.
Problem 4 (Job Displacement Markov Chain). Consider the three-state Markov chain from Section 5 with transition matrix
\[ P = \begin{bmatrix} 0.7 & 0.2 & 0.1 \\ 0.0 & 0.9 & 0.1 \\ 0.0 & 0.2 & 0.8 \end{bmatrix}. \]
(a) Starting from \( p_0 = (1,0,0)^{\top} \) (everyone
initially in an automatable job), compute \( p_1 \) and
\( p_2 \).
(b) Discuss qualitatively what happens to \( p_k \) as
\( k \to \infty \).
Solution. (a) We have
\[ p_1 = P p_0 = \begin{bmatrix} 0.7 \\ 0.0 \\ 0.0 \end{bmatrix} + \begin{bmatrix} 0.2 \\ 0.9 \\ 0.2 \end{bmatrix} \cdot 0 + \begin{bmatrix} 0.1 \\ 0.1 \\ 0.8 \end{bmatrix} \cdot 0 = \begin{bmatrix} 0.7 \\ 0.0 \\ 0.0 \end{bmatrix}. \]
After one step, 70% remain in automatable jobs, and 30% have moved (20% to new jobs and 10% to unemployment) according to the first row of \( P \). Applying \( P \) again gives
\[ p_2 = P p_1 = P \begin{bmatrix} 0.7 \\ 0.2 \\ 0.1 \end{bmatrix} = 0.7 \begin{bmatrix} 0.7 \\ 0.0 \\ 0.0 \end{bmatrix} + 0.2 \begin{bmatrix} 0.2 \\ 0.9 \\ 0.2 \end{bmatrix} + 0.1 \begin{bmatrix} 0.1 \\ 0.1 \\ 0.8 \end{bmatrix}, \]
which can be evaluated numerically. The key point is that the probability
mass gradually shifts from \( s_1 \) to
\( s_2 \) and \( s_3 \).
(b) As \( k \to \infty \), under mild conditions the
chain converges to a stationary distribution
\( p^{\star} \) satisfying
\( p^{\star} = P p^{\star} \). Because
\( P \) has positive probability of remaining unemployed,
the limiting distribution will contain a nonzero mass in
\( s_3 \), representing persistent unemployment after
automation.
Problem 5 (Identifiability and Accountability). Suppose two autonomous forklift models A and B produce identical logs \( \ell_{0:T} \) for all possible environments and operator commands. Can an external auditor, relying only on logs, ever determine whether an accident was caused by A or B? What design change would be required to make such attribution possible?
Solution. By definition, if the distributions of logs under A and B are identical for all conditions, then the two systems are observationally equivalent. No log-based auditor can reliably infer which model caused a particular accident; any decision rule will perform no better than guessing. To enable attribution, the system design must ensure that logs contain some identifying information (e.g. a signed model identifier, version number, or distinct statistical fingerprint) so that the probability laws for logs under A and B become distinguishable.
8. Summary
In this lesson we treated ethical concerns in robotics as constraints and structure on otherwise familiar mathematical objects: policies, cost functionals, probability distributions, and dynamical systems. We formalized several notions of bias via group-conditional risks and fairness constraints, connected expected harm to probabilistic safety bounds, and sketched how Markov-chain models can represent job displacement dynamics. We also saw how accountability can be conceptualized as an identifiability problem over execution logs, motivating concrete logging and software engineering practices. These tools will underpin more detailed standards and case studies in the next lesson of this chapter.
9. References
- Moor, J.H. (2006). The nature, importance, and difficulty of machine ethics. IEEE Intelligent Systems, 21(4), 18–21.
- Dwork, C., Hardt, M., Pitassi, T., Reingold, O., & Zemel, R. (2012). Fairness through awareness. Proceedings of the 3rd Innovations in Theoretical Computer Science Conference.
- Kleinberg, J., Mullainathan, S., & Raghavan, M. (2017). Inherent trade-offs in the fair determination of risk scores. Proceedings of the 8th Innovations in Theoretical Computer Science Conference.
- Winfield, A.F.T., & Jirotka, M. (2018). Ethical governance is essential to building trust in robotics and artificial intelligence systems. Philosophical Transactions of the Royal Society A, 376(2133), 20180085.
- Calo, R. (2015). Robotics and the lessons of cyberlaw. California Law Review, 103(3), 513–563.
- Brynjolfsson, E., & Mitchell, T. (2017). What can machine learning do? Workforce implications. Science, 358(6370), 1530–1534.
- Floridi, L., & Cowls, J. (2019). A unified framework of five principles for AI in society. Harvard Data Science Review, 1(1).
- Wallach, W., & Allen, C. (2009). Moral Machines: Teaching Robots Right from Wrong. Oxford University Press.
- Asaro, P.M. (2011). A body to kick, but still no soul to damn: Legal perspectives on robotics. In P. Lin, K. Abney, & G.A. Bekey (Eds.), Robot Ethics: The Ethical and Social Implications of Robotics.
- Lin, P., Abney, K., & Bekey, G.A. (2011). Robot Ethics: The Ethical and Social Implications of Robotics. MIT Press.