EZ LearnEZ Learn
Courses
EZ Board
Dashboard
All articles
python-for-cyber-securitymlcsrevisionself-study

Unit 4 Quick Reference, Self-Study and Lab

Every reinforcement learning idea from this unit in one table, followed by seven questions and a lab exercise: changing a single reward coefficient and watching, directly, how much the learned policy shifts.

Ashish Revar18 October 20266 min read1 views

Unit Summary and Quick Reference

TopicCore idea
State, action, reward, policyThe four pieces of every RL problem; the agent learns a policy that maximises cumulative reward
Q-learningLearns the expected future value of every state-action pair, updated after every observed transition
Exploration vs exploitationAn $\epsilon$-greedy policy balances trying new actions against using the best known one
Adaptive honeypotsTreat attacker engagement as a sequential decision problem, defeating the fingerprinting that static, scripted honeypots like Cowrie are vulnerable to
Beyond honeypotsThe same framing applies to firewall tuning, moving target defence, and patch scheduling
Reward design riskA badly shaped reward function produces an agent that maximises reward while doing something useless or harmful

Self-Study Questions

Q1. Define state, action, reward, and policy using a honeypot example different from the one in this unit.

For a web-application honeypot: the state could be how many distinct URL paths an attacker has probed so far; the actions could be serving a real-looking response, injecting an artificial delay, or redirecting to a dead end; the reward could be a positive score for each new technique observed minus a penalty proportional to how suspicious the attacker's behaviour suggests they have become; the policy is the learned rule mapping the probe count to the best action to take next.

Q2. Why does an RL agent need some degree of exploration even after it has found a policy that works reasonably well?

An agent that always exploits its current best-known action can get permanently stuck on a merely adequate policy, because it never tries the alternatives that might actually be better. Continued exploration, even at a small rate, lets the agent keep testing whether an action it currently undervalues might in fact be superior, which a purely greedy policy would never discover.

Q3. Explain, in your own words, why a static, scripted honeypot is eventually fingerprinted by a patient attacker, and how an adaptive honeypot addresses that specific weakness.

A static honeypot responds to every connection the same scripted way: identical response timing, identical fake file listings, identical behaviour after an unusual command. A patient attacker or automated reconnaissance tool can notice this pattern over repeated interactions. An adaptive honeypot instead decides session by session how to respond, based on what has kept past attackers engaged longest, so there is no single fixed script for an attacker to fingerprint.

Q4. Describe a concrete, plausible way a poorly designed reward function could cause the honeypot agent in this unit to behave uselessly despite technically maximising its reward.

If the detection-risk penalty for continued engagement were set too high relative to the small negative reward for terminating, the agent could learn that immediately terminating every session is the safest way to maximise reward, since termination's small fixed cost beats the accumulating risk of staying engaged. The agent would technically be maximising its reward function while gathering zero intelligence on any attacker, which is the opposite of what the honeypot exists to do.

Q5. Write out the five-element MDP tuple (S, A, P, R, gamma) for the rate-limiting agent in this unit, stating what each element concretely is in that problem.

S is the set of ten discretised traffic-rate bins, from low to extreme. A is the set of three actions: relax, hold, or tighten the rate limit. P is the transition probability that traffic moves from one rate bin to a neighbouring bin after an action, here modelled as a small random step. R is the traffic_reward function, which penalises blocking legitimate traffic when tightening is unnecessary and penalises failing to tighten when the rate bin is genuinely high. Gamma is the discount factor, set to 0.9, controlling how much the agent values future reward relative to the immediate reward of its next action.

Q6. Explain why a Deep Q-Network replaces Q-learning's table with a neural network, and what specifically about network traffic data makes this necessary rather than optional.

A table-based Q-learning agent needs one entry for every state-action pair, which only works because this unit deliberately kept every state space small, ten bins, ten steps. Real network telemetry has a far larger, often continuous state space built from packet rate, source diversity, and protocol mix, where an exhaustive table would need an impractically large number of entries. A Deep Q-Network replaces the table with a neural network that generalises across similar states it has never exactly seen before, the same way a classifier in Unit 2 generalises across feature vectors, making large or continuous state spaces tractable.

Q7. Compare the adaptive honeypot and the rate-limiting agent as two applications of the same algorithm: what state, action, and reward design choices differ between them, and why?

The honeypot agent's state is a simple discrete count of commands run so far, capped at nine, while the rate-limiting agent's state is a continuous traffic rate discretised into ten bins, reflecting that network traffic genuinely varies continuously rather than in discrete steps. Their actions differ in kind: the honeypot chooses how to respond to a single attacker session, while the rate-limiter chooses a defensive posture affecting all current traffic. Their reward functions reflect different trade-offs: the honeypot balances intelligence gathered against detection risk, while the rate-limiter balances blocking legitimate users against letting an attack through, each shaped by what that specific security problem actually needs to optimise for.

Lab: Change the Reward, Watch the Policy Change

  1. Reproduce the baseline. Run the honeypot Q-learning agent from this unit exactly as written and record the learned policy with np.argmax(Q, axis=1), one action per state.
  2. Raise the detection risk. Change the detection_risk coefficient from 0.04 to 0.12 and retrain from scratch. Record the new policy the same way.
  3. Compare the two policies. At which states did the agent's preferred action change between the two runs? Explain, in terms of the reward function, why a higher detection-risk coefficient pushes the agent toward terminating sessions earlier.
  4. Plot both reward curves. Using the same 15-episode moving average style as this unit's own chart, plot the reward curve for both runs on the same axes and describe, in two sentences, how the higher detection-risk run differs in both its final reward level and how quickly it converges.

Discussion

Loading comments…
More articlesTest your knowledge
EZ MentorAI · Free

Unit 4 Quick Reference, Self-Study and Lab

Hi! I'm EZ Mentor

Your AI tutor for
Unit 4 Quick Reference, Self-Study and Lab

Sign in to ask, it's free.

EZ Mentor is AI-powered · Answers may not be perfect · 10 free questions / day

EZ LearnEZ Learn

Structured learning across Reverse Engineering, Cloud Security, and Research Methodology, plus games and practice tools in EZ Arena. Free, and open to anyone.

EZ Learn

  • Courses
  • EZ Articles
  • EZ Watch
  • EZ Talks
  • EZ Bytes
  • Cyber Hygiene

EZ Library

  • All Resources
  • eBooks & PDFs
  • Question Banks
  • MCQ Banks
  • Cheatsheets

EZ Exams

  • All Exams
  • REMA
  • Cloud Security
  • Research Methodology
  • Python for Cyber Security
  • Cyber Law & IPR
  • Community
  • EZ Board

EZ Arena

  • EZ Games
  • Live Quiz
  • ML Challenges
  • दिशा - Hygiene
  • सजग - Awareness
  • अभ्यास - Practice

Platform

  • About
  • Contact
  • Terms of Use
  • Disclaimer
  • Verify Certificate
  • Events

© 2026 EZ Learn by EpochZero. Educational content for learning purposes.

Platform Lead: Ashish Revar