import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, MinMaxScaler
from sklearn.metrics import mean_absolute_error, r2_score
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout
from tensorflow.keras.callbacks import EarlyStopping
import matplotlib.pyplot as plt
# -----------------------------
# Versão melhorada da função Collatz
# -----------------------------
def collatz_features(n, max_iterations=10000):
"""
Calcula características da sequência de Collatz com segurança.
Retorna: (passos até 1, valor máximo atingido, sequência)
"""
steps = 0
max_val = n
current = n
sequence = [n]
while current != 1 and steps < max_iterations:
steps += 1
if current % 2 == 0:
current = current // 2
else:
current = 3 * current + 1
sequence.append(current)
…