File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
src/active_inference_forager Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -154,10 +154,19 @@ def learn(
154
154
self .decay_exploration ()
155
155
156
156
def update_belief (self , observation : np .ndarray ) -> None :
157
+ # Validate that observation is numeric
158
+ if not np .issubdtype (observation .dtype , np .number ):
159
+ raise ValueError ("Observation must be a numeric array." )
160
+
157
161
self ._update_belief_recursive (self .root_belief , observation )
158
162
self ._regularize_beliefs ()
159
163
160
164
def _update_belief_recursive (self , node : BeliefNode , observation : np .ndarray ):
165
+ # Ensure observation is a numpy array of floats
166
+ observation = np .asarray (observation )
167
+ if observation .dtype != node .mean .dtype :
168
+ observation = observation .astype (node .mean .dtype )
169
+
161
170
prediction_error = observation - node .mean
162
171
node .precision += (
163
172
np .outer (prediction_error , prediction_error ) * self .learning_rate
@@ -297,6 +306,9 @@ def process_user_input(self, user_input: str) -> np.ndarray:
297
306
words
298
307
) # Politeness ratio
299
308
309
+ # Ensure features are of type float
310
+ features = features .astype (float )
311
+
300
312
# Debug print statements
301
313
print (f"Debug: Input string: '{ user_input } '" )
302
314
print (f"Debug: Word count: { len (words )} " )
Original file line number Diff line number Diff line change @@ -149,7 +149,13 @@ def simulate_conversation(
149
149
150
150
next_state , reward , done = env .step (action )
151
151
152
- agent .update_belief (user_input )
152
+ # Process user input into numerical features
153
+ # create a variable with a np.array with three random values between 0.0 and 1.0
154
+ placeholder_user_input = np .random .rand (10 )
155
+
156
+ processed_input = agent .process_user_input (placeholder_user_input ) # user_input
157
+ agent .update_belief (processed_input )
158
+
153
159
state = next_state
154
160
turn += 1
155
161
You can’t perform that action at this time.
0 commit comments