fuse decision fusion

This commit is contained in:
Dobromir Popov
2025-07-29 09:09:11 +03:00
parent f4ac504963
commit e2ededcdf0
3 changed files with 243 additions and 33 deletions

View File

@ -657,6 +657,24 @@ class DQNAgent:
done: Whether episode is done
is_extrema: Whether this is a local extrema sample (for specialized learning)
"""
# Validate states before storing experience
if state is None or next_state is None:
logger.debug("Skipping experience storage: None state provided")
return
if isinstance(state, dict) and not state:
logger.debug("Skipping experience storage: empty state dictionary")
return
if isinstance(next_state, dict) and not next_state:
logger.debug("Skipping experience storage: empty next_state dictionary")
return
# Check if states are all zeros (invalid)
if hasattr(state, '__iter__') and all(f == 0 for f in np.array(state).flatten()):
logger.debug("Skipping experience storage: state is all zeros")
return
experience = (state, action, reward, next_state, done)
# Always add to main memory
@ -761,6 +779,15 @@ class DQNAgent:
int: Action (0=BUY, 1=SELL)
"""
try:
# Validate state first - return early if empty/invalid/None
if state is None:
logger.warning("None state provided to act(), returning SELL action")
return 1 # SELL action (safe default)
if isinstance(state, dict) and not state:
logger.warning("Empty state dictionary provided to act(), returning SELL action")
return 1 # SELL action (safe default)
# Use the DQNNetwork's act method for consistent behavior
action_idx, confidence, action_probs = self.policy_net.act(state, explore=explore)
@ -790,6 +817,14 @@ class DQNAgent:
def act_with_confidence(self, state: np.ndarray, market_regime: str = 'trending') -> Tuple[int, float, List[float]]:
"""Choose action with confidence score adapted to market regime"""
try:
# Validate state first - return early if empty/invalid/None
if state is None:
logger.warning("None state provided to act_with_confidence(), returning safe defaults")
return 1, 0.1, [0.0, 0.9, 0.1] # SELL action with low confidence
if isinstance(state, dict) and not state:
logger.warning("Empty state dictionary provided to act_with_confidence(), returning safe defaults")
return 1, 0.0, [0.0, 1.0] # SELL action with zero confidence
# Convert state to tensor if needed
if isinstance(state, np.ndarray):
state_tensor = torch.FloatTensor(state)