fixed other CNN references

This commit is contained in:
Dobromir Popov
2025-06-24 21:13:06 +03:00
parent 8685319989
commit e7ea17b626
3 changed files with 49 additions and 17 deletions

View File

@ -1404,19 +1404,8 @@ class EnhancedTradingOrchestrator(TradingOrchestrator):
predictions_array = np.array([float(predictions)], dtype=np.float32)
# Create final predictions array with confidence
# Ensure confidence is a scalar value - handle all array shapes safely
if isinstance(confidence, np.ndarray):
if confidence.ndim == 0:
# 0-dimensional array (scalar)
confidence_scalar = float(confidence.item())
elif confidence.size == 1:
# 1-element array
confidence_scalar = float(confidence.item())
else:
# Multi-element array - take first element or mean
confidence_scalar = float(confidence.flat[0]) # Use flat[0] to safely get first element
else:
confidence_scalar = float(confidence)
# Use safe tensor conversion to avoid scalar conversion errors
confidence_scalar = self._safe_tensor_to_scalar(confidence, default_value=0.7)
# Combine predictions and confidence as separate elements
predictions = np.concatenate([
@ -4736,4 +4725,38 @@ class EnhancedTradingOrchestrator(TradingOrchestrator):
'price_to_pivot_ratio': 1.0,
'volume_strength': 1.0,
'pivot_strength': 0.5
}
}
# Helper function to safely extract scalar values from tensors
def _safe_tensor_to_scalar(self, tensor_value, default_value: float = 0.7) -> float:
"""
Safely convert tensor/array values to Python scalar floats
Args:
tensor_value: Input tensor, array, or scalar value
default_value: Default value to return if conversion fails
Returns:
Python float scalar value
"""
try:
if hasattr(tensor_value, 'item'):
# PyTorch tensor - handle different shapes
if tensor_value.numel() == 1:
return float(tensor_value.item())
else:
return float(tensor_value.flatten()[0].item())
elif isinstance(tensor_value, np.ndarray):
# NumPy array - handle different shapes
if tensor_value.ndim == 0:
return float(tensor_value.item())
elif tensor_value.size == 1:
return float(tensor_value.flatten()[0])
else:
return float(tensor_value.flat[0])
else:
# Already a scalar value
return float(tensor_value)
except Exception as e:
logger.warning(f"Error converting tensor to scalar, using default {default_value}: {e}")
return default_value