43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
"""Fixed Gre24 model choices; no test-driven selection or node subsampling."""
|
|
import numpy as np
|
|
|
|
|
|
def xgb_model(seed,threads=8):
|
|
from xgboost import XGBRegressor
|
|
return XGBRegressor(n_estimators=100,max_depth=8,learning_rate=.1,
|
|
objective='reg:squarederror',random_state=seed,n_jobs=threads)
|
|
|
|
|
|
def fnn_model():
|
|
import torch
|
|
layers=[];width=19
|
|
for _ in range(4):
|
|
layers.extend([torch.nn.Linear(width,100),torch.nn.ReLU()]);width=100
|
|
layers.append(torch.nn.Linear(100,1))
|
|
return torch.nn.Sequential(*layers)
|
|
|
|
|
|
def eligible_roles(split,successful):
|
|
successful=set(successful)
|
|
roles={role:[c for c in split[role] if c in successful]
|
|
for role in ['train','test','fnn_learning','fnn_validation']}
|
|
if set(split['train'])&set(split['test']):raise ValueError('Train/test overlap')
|
|
if set(split['fnn_learning'])&set(split['fnn_validation']):raise ValueError('FNN role overlap')
|
|
if set(split['fnn_learning'])|set(split['fnn_validation'])!=set(split['train']):
|
|
raise ValueError('FNN learning/validation do not partition train')
|
|
missing={role:[c for c in split[role] if c not in successful] for role in roles}
|
|
return roles,missing
|
|
|
|
|
|
def require_training_role(case,split,role):
|
|
if role not in ['train','fnn_learning','fnn_validation']:
|
|
raise PermissionError('Only frozen training-side roles may read targets')
|
|
if case in split['test'] or case not in split[role]:
|
|
raise PermissionError('Case is not in the requested training role')
|
|
|
|
|
|
def early_stop_update(best,stale,score,patience=5):
|
|
if not np.isfinite(score):raise ValueError('Nonfinite validation MSE')
|
|
improved=score<best
|
|
return (score if improved else best),(0 if improved else stale+1),improved,(not improved and stale+1>=patience)
|