🎯 Custom Fitness
Inject arbitrary Python source code as your fitness metric, bypassing the pre-packaged defaults.
Prerequisites
-
VEOX Server: Start the local VEOX server (requires Docker):
See the Quick Start for detailed server setup, health checks, and Docker Compose instructions.docker run -d \ --name veox-enclave-server \ -p 8090:8090 \ 714044927654.dkr.ecr.us-east-2.amazonaws.com/doug/single_enclave/veox-enclave-server:latest -
Python SDK: Install the
veoxpackage via PyPI:
What It Does
Usually, the VEOX engine chooses metrics automatically (like AUC for binary, R² for regression). For domain-specific evaluation, you can write a raw Python function and pass it as a string to custom_fitness_code.
The engine compiles and executes your code securely within the VEOX Enclave sandbox, feeding it y_prob (or predictions) and y_true.
Note
Custom fitness compilation happens securely within the VEOX Enclave sandbox.
Pro Feature
This is a Pro feature requiring an active VEOX Pro license.
Full Example
import os
from sklearn.datasets import make_classification
import pandas as pd
from veox import VeoxEvolver
# This Python source is sent to the server and used to evaluate candidates
CUSTOM_F1_CODE = """
from sklearn.metrics import f1_score
import numpy as np
def compute_fitness(y_prob, y_true):
\"\"\"Custom fitness: F1-score (macro) instead of AUC.\"\"\"
y_pred = (np.asarray(y_prob) > 0.5).astype(int)
return f1_score(y_true, y_pred, average='macro', zero_division=0.0)
"""
api_url = os.environ.get("VEOX_API_URL", "http://127.0.0.1:8090")
# 1. Generate dataset
X, y = make_classification(n_samples=300, n_features=10, n_informative=6, random_state=42)
df = pd.DataFrame(X, columns=[f"f{i}" for i in range(10)])
df["target"] = y
# 2. Connect
evolver = VeoxEvolver("binary", api_url=api_url)
evolver.health_check()
# 3. Evolve with custom fitness metric
print("Injecting custom F1-score fitness function...")
evolver.fit(
data=df,
target_column="target",
max_generations=3,
population_size=15,
num_islands=1,
timeout_per_eval=30,
max_poll_time=120,
custom_fitness_code=CUSTOM_F1_CODE, # 💎 PRO FEATURE: Custom fitness
)
# 4. Results
print(f"Best F1: {evolver.best_fitness_:.4f}")
print(f"Best Pipeline: {evolver.best_pipeline_}")
Signature Requirements
Your injected code string must define a function exactly named compute_fitness(y_prob, y_true) that returns a numeric float.
You may safely import numpy, pandas, scipy, and scikit-learn inside the snippet.
💎 VEOX Pro Activation
To unlock Custom Fitness and other Pro features, you must authenticate your local node with a VEOX License Token.
from veox import VeoxEvolver
evolver = VeoxEvolver("binary", api_url="http://127.0.0.1:8090")
# 1. Fetch your unique Hardware Fingerprint
fingerprint = evolver.get_system_fingerprint()
print(f"My VEOX Node Fingerprint: {fingerprint}")
# 2. Provide this fingerprint to your VEOX Admin to receive a JWT Token
jwt_token = "eyJ0b2tlbiI6ICJVRExK...EXPIRES" # Replace with your token
# 3. Activate the Enclave
if evolver.activate_license(jwt_token):
print("VIP Features Unlocked!")
Tips
- Security: Your custom fitness code runs inside the encrypted sandbox — it never touches the host filesystem.
- Imports: Only
numpy,pandas,scipy, andscikit-learnare available inside the snippet. - Debugging: If your function raises an exception, the candidate receives a penalty fitness of
0.0.