Я реализую монотонное полиномиальное отображение 3-го порядка для прогнозов модели, как того требует стандарт ITU-T P.1401. Согласно стандарту это отображение определяется как:
y'' = a + by + cy^2 + dy^3
где Цель состоит в том, чтобы минимизировать RMSE(x, y'') и гарантировать, что функция f(y) остается монотонной в диапазоне [y_min, y_max].
Чтобы добиться этого, я' Я написал следующий код, который, по моему мнению, соответствует требованию обеспечить монотонность и минимизировать RMSE. Я был бы признателен за отзывы о том, кажется ли этот подход правильным для удовлетворения требований, и есть ли улучшения или оптимизации, которые сделают код более эффективным и точным.
Вот мой код:
import pandas as pd
import numpy as np
from scipy.optimize import minimize
from scipy.optimize import Bounds
def polynomial_map(y, a, b, c, d):
return a + b * y + c * y**2 + d * y**3
# Define the RMSE objective function to minimize
def objective(params, y, x):
a, b, c, d = params
y_mapped = polynomial_map(y, a, b, c, d)
rmse = np.sqrt(np.mean((x - y_mapped) ** 2))
return rmse
def monotonicity_constraint(params, y_min, y_max):
a, b, c, d = params
# Derivative of the polynomial: b + 2*c*y + 3*d*y^2
# Ensure that this derivative is non-negative over the interval [y_min, y_max]
y_values = np.linspace(y_min, y_max, 100) # Sample values in the range
derivative = b + 2 * c * y_values + 3 * d * y_values**2
return np.min(derivative) # Constraint that this must be >= 0
def apply_third_order_monotonic_map(x, y):
# Initial guess for parameters
initial_params = [0, 1, 0, 0] # Start with an approximate linear map
# Bounds for a, b, c, d (if needed)
bounds = Bounds([-np.inf, -np.inf, -np.inf, -np.inf], [np.inf, np.inf, np.inf, np.inf])
# Define constraints for monotonicity over the range [y_min, y_max]
y_min, y_max = np.min(y), np.max(y)
constraints = {
'type': 'ineq',
'fun': lambda params: monotonicity_constraint(params, y_min, y_max)
}
# Perform the minimization with constraints
result = minimize(objective, initial_params, args=(y, x), bounds=bounds, constraints=constraints)
# Get optimized parameters
a, b, c, d = result.x
# Apply the mapping with the optimized parameters
y_mapped = polynomial_map(y, a, b, c, d)
return y_mapped
Будем очень признательны за любые рекомендации и предложения! Заранее благодарю за помощь.
Я реализую монотонное полиномиальное отображение 3-го порядка для прогнозов модели, как того требует стандарт ITU-T P.1401. Согласно стандарту это отображение определяется как: y'' = a + by + cy^2 + dy^3 где Цель состоит в том, чтобы минимизировать RMSE(x, y'') и гарантировать, что функция f(y) остается монотонной в диапазоне [y_min, y_max]. Чтобы добиться этого, я' Я написал следующий код, который, по моему мнению, соответствует требованию обеспечить монотонность и минимизировать RMSE. Я был бы признателен за отзывы о том, кажется ли этот подход правильным для удовлетворения требований, и есть ли улучшения или оптимизации, которые сделают код более эффективным и точным. Вот мой код: [code]import pandas as pd import numpy as np from scipy.optimize import minimize from scipy.optimize import Bounds
def polynomial_map(y, a, b, c, d): return a + b * y + c * y**2 + d * y**3
# Define the RMSE objective function to minimize def objective(params, y, x): a, b, c, d = params y_mapped = polynomial_map(y, a, b, c, d) rmse = np.sqrt(np.mean((x - y_mapped) ** 2)) return rmse
def monotonicity_constraint(params, y_min, y_max): a, b, c, d = params # Derivative of the polynomial: b + 2*c*y + 3*d*y^2 # Ensure that this derivative is non-negative over the interval [y_min, y_max] y_values = np.linspace(y_min, y_max, 100) # Sample values in the range derivative = b + 2 * c * y_values + 3 * d * y_values**2 return np.min(derivative) # Constraint that this must be >= 0
def apply_third_order_monotonic_map(x, y): # Initial guess for parameters initial_params = [0, 1, 0, 0] # Start with an approximate linear map
# Bounds for a, b, c, d (if needed) bounds = Bounds([-np.inf, -np.inf, -np.inf, -np.inf], [np.inf, np.inf, np.inf, np.inf])
# Define constraints for monotonicity over the range [y_min, y_max] y_min, y_max = np.min(y), np.max(y) constraints = { 'type': 'ineq', 'fun': lambda params: monotonicity_constraint(params, y_min, y_max) }
# Perform the minimization with constraints result = minimize(objective, initial_params, args=(y, x), bounds=bounds, constraints=constraints)
# Get optimized parameters a, b, c, d = result.x
# Apply the mapping with the optimized parameters y_mapped = polynomial_map(y, a, b, c, d) return y_mapped [/code] Будем очень признательны за любые рекомендации и предложения! Заранее благодарю за помощь.