bhxvxsh commited on
Commit
bf5cc92
·
verified ·
1 Parent(s): 6d303c7

Upload config.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. config.py +150 -0
config.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Configuration file for Recipe Generation RL System
3
+ Designed to be HRM-ready with hierarchical constraint support
4
+ """
5
+
6
+ # ====================
7
+ # Dataset Configuration
8
+ # ====================
9
+ DATA_DIR = "data/FoodData_Central_foundation_food_csv_2024-10-31/"
10
+ RAW_FOOD_FILE = "food.csv"
11
+ RAW_NUTRIENT_FILE = "food_nutrient.csv"
12
+ PROCESSED_INGREDIENT_FILE = "data/ingredients_processed.csv"
13
+
14
+ # Nutrients to track (aligned with USDA nutrient IDs)
15
+ # Foundation Foods uses Atwater Specific Factors for energy
16
+ NUTRIENT_IDS = {
17
+ 'calories': 2048, # Energy (Atwater Specific Factors) (kcal)
18
+ 'protein': 1003, # Protein (g)
19
+ 'sodium': 1093, # Sodium (mg)
20
+ 'carbs': 1005, # Carbohydrates (g)
21
+ 'fat': 1004, # Total fat (g)
22
+ }
23
+
24
+ # ====================
25
+ # Recipe Generation Configuration
26
+ # ====================
27
+ MAX_INGREDIENTS_PER_RECIPE = 10
28
+ MIN_INGREDIENTS_PER_RECIPE = 3
29
+ INGREDIENT_POOL_SIZE = 500 # Top N most common ingredients
30
+ INGREDIENT_SERVING_SIZE_G = 50 # Grams per ingredient (scaled from 100g USDA data)
31
+
32
+ # ====================
33
+ # Health Constraints (Daily targets)
34
+ # ====================
35
+ # These can be overridden by user profiles or HRM high-level policy
36
+ DEFAULT_CONSTRAINTS = {
37
+ 'calories': {'min': 400, 'max': 800, 'target': 600},
38
+ 'protein': {'min': 15, 'max': 50, 'target': 30},
39
+ 'sodium': {'min': 0, 'max': 800, 'target': 500},
40
+ 'carbs': {'min': 30, 'max': 100, 'target': 60},
41
+ 'fat': {'min': 10, 'max': 30, 'target': 20},
42
+ }
43
+
44
+ # User profile templates
45
+ USER_PROFILES = {
46
+ 'standard': DEFAULT_CONSTRAINTS,
47
+ 'low_sodium': {
48
+ 'calories': {'min': 400, 'max': 800, 'target': 600},
49
+ 'protein': {'min': 20, 'max': 50, 'target': 35},
50
+ 'sodium': {'min': 0, 'max': 400, 'target': 300},
51
+ 'carbs': {'min': 30, 'max': 100, 'target': 60},
52
+ 'fat': {'min': 10, 'max': 30, 'target': 20},
53
+ },
54
+ 'high_protein': {
55
+ 'calories': {'min': 500, 'max': 900, 'target': 700},
56
+ 'protein': {'min': 40, 'max': 70, 'target': 50},
57
+ 'sodium': {'min': 0, 'max': 800, 'target': 500},
58
+ 'carbs': {'min': 20, 'max': 80, 'target': 50},
59
+ 'fat': {'min': 15, 'max': 35, 'target': 25},
60
+ },
61
+ 'low_carb': {
62
+ 'calories': {'min': 400, 'max': 800, 'target': 600},
63
+ 'protein': {'min': 25, 'max': 50, 'target': 35},
64
+ 'sodium': {'min': 0, 'max': 800, 'target': 500},
65
+ 'carbs': {'min': 10, 'max': 40, 'target': 25},
66
+ 'fat': {'min': 20, 'max': 40, 'target': 30},
67
+ }
68
+ }
69
+
70
+ # ====================
71
+ # RL Configuration (Phase 1: Single Agent)
72
+ # ====================
73
+ RL_CONFIG = {
74
+ 'algorithm': 'PPO', # or 'DQN'
75
+ 'learning_rate': 3e-4,
76
+ 'gamma': 0.99,
77
+ 'batch_size': 64,
78
+ 'n_steps': 2048,
79
+ 'n_epochs': 10,
80
+ 'total_timesteps': 100000,
81
+ 'ent_coef': 0.01, # Entropy coefficient for exploration
82
+ }
83
+
84
+ # ====================
85
+ # Reward Configuration (HRM-Ready)
86
+ # ====================
87
+ REWARD_WEIGHTS = {
88
+ # Low-level rewards (immediate)
89
+ 'constraint_satisfaction': 20.0, # Increased reward for meeting all constraints
90
+ 'nutrient_balance': 2.0, # Increased for better balance
91
+ 'diversity_bonus': 5.0, # Increased to encourage variety
92
+ 'ingredient_repeat_penalty': -20.0, # Much stronger penalty for repetition
93
+ 'constraint_violation_penalty': -15.0, # Stronger penalty
94
+
95
+ # High-level rewards (HRM Phase 2)
96
+ 'weekly_target_bonus': 10.0, # Weekly aggregate constraint bonus
97
+ 'long_term_health_stability': 5.0, # Stability across week
98
+ }
99
+
100
+ # Lambda for hierarchical reward shaping
101
+ # Phase 1 (baseline): λ = 0
102
+ # Phase 2 (HRM): λ > 0
103
+ LAMBDA_HIERARCHICAL = 0.5 # PHASE 2 ACTIVATED
104
+
105
+ # ====================
106
+ # HRM Configuration (Phase 2 - ACTIVE)
107
+ # ====================
108
+ HRM_ENABLED = True # PHASE 2 ACTIVATED
109
+
110
+ HRM_CONFIG = {
111
+ 'planning_horizon': 7, # Weekly planning
112
+ 'high_level_update_freq': 7, # Update meta-policy every N recipes
113
+ 'weekly_targets': {
114
+ 'calories': 4200, # 600 * 7
115
+ 'protein': 210,
116
+ 'sodium': 3500,
117
+ 'carbs': 420,
118
+ 'fat': 140,
119
+ }
120
+ }
121
+
122
+ # ====================
123
+ # Environment Configuration
124
+ # ====================
125
+ ENV_CONFIG = {
126
+ 'normalize_observations': True,
127
+ 'normalize_rewards': False,
128
+ 'recipe_history_length': 10, # For diversity tracking
129
+ 'done_action': True, # Allow agent to terminate recipe early
130
+ }
131
+
132
+ # ====================
133
+ # Evaluation Metrics
134
+ # ====================
135
+ EVAL_METRICS = [
136
+ 'constraint_compliance_rate',
137
+ 'nutrient_balance_score',
138
+ 'recipe_diversity',
139
+ 'average_ingredients_per_recipe',
140
+ 'reward_per_episode',
141
+ ]
142
+
143
+ # ====================
144
+ # Paths
145
+ # ====================
146
+ import os
147
+ PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
148
+ MODEL_SAVE_DIR = os.path.join(PROJECT_ROOT, "models/saved/")
149
+ TENSORBOARD_LOG_DIR = os.path.join(PROJECT_ROOT, "logs/tensorboard/")
150
+ EVAL_RESULTS_DIR = os.path.join(PROJECT_ROOT, "eval/results/")