# What is Reward Function? Definition & Technical Mechanics

> **Source:** [SPIDITS AI AI Glossary](https://spidits.com/ai-glossary)  
> **Category:** Model Training  
> **Canonical Citation:** [https://spidits.com/ai-glossary/reward-function](https://spidits.com/ai-glossary/reward-function)

## Definition
A Reward Function is a mathematical formula that defines the goal in reinforcement learning by assigning a numerical score to the states and actions of an agent based on their desirability.

## Architectural Mechanics & Deep Dive
A reward function is a mathematical formula in reinforcement learning that calculates the numerical feedback (reward or penalty) received by an agent after performing an action in a state. The design of the reward function is critical, as it defines the agent's objective, though poor design can lead to reward hacking.

## Industry Applications & Real-World Use Cases
Game-playing AI (e.g., Chess, Go), robotics control optimization, and tuning models through reinforcement learning with human feedback.

## Frequently Asked Questions

### Why is designing a reward function challenging (reward hacking)?
If a reward function is poorly specified, the agent might find loopholes to maximize reward without actually achieving the intended goal (e.g., getting stuck in a loop to collect small rewards instead of finishing a level).

### What is the difference between sparse and dense reward functions?
A sparse reward function only gives a reward when the final goal is met (e.g., winning the game), whereas a dense reward function gives frequent feedback after every small action to guide learning.

## Related Terminology
- [reinforcement-learning](https://spidits.com/ai-glossary/reinforcement-learning)
- [reward-model](https://spidits.com/ai-glossary/reward-model)
- [rlhf](https://spidits.com/ai-glossary/rlhf)

---
*From the SPIDITS AI Knowledge Base (336+ terms indexed). Explore full technical definitions: [https://spidits.com/ai-glossary](https://spidits.com/ai-glossary)*
