| compute_beta |
Ran ran; our contract draft was wrong, not the code |
QB3/sparse-ho/sparse_ho/algo/forward.py code served (permissive licence) · get_code("37842502f1c4807f") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 2, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import numpy as np
from scipy.sparse import csr_matrix
import torch
import torch.nn as nn
torch.manual_seed(0)
# Create a minimal model class that implements the required methods
class MinimalModel(nn.Module):
def __init__(self, n_features):
super().__init__()
self.n_features = n_features
self.dual_var = None
self.ddual_var = None
def get_L(self, X):
"""Return Lipschitz constant"""
return 1.0
def _init_beta_dual_var(self, X, y, mask0, dense0):
"""Initialize beta and dual_var"""
n_features = X.shape[1]
beta = np.zeros(n_features)
dual_var = np.zeros(X.shape[0])
return beta, dual_var
def _init_dbeta_ddual_var(self, X, y, mask0=None, dense0=None, jac0=None, compute_jac=True):
"""Initialize dbeta and ddual_var"""
n_features = X.shape[1]
dbeta = np.zeros(n_features)
ddual_var = np.zeros(X.shape[0])
return dbeta, ddual_var
def _get_pobj0(self, dual_var, beta_zeros, alphas, y):
"""Get initial primal objective"""
return 1.0
def _get_pobj(self, dual_var, X, beta, alphas, y):
"""Get primal objective"""
return 0.5 * np.sum((y - X @ beta) ** 2) + np.sum(alphas * np.abs(beta))
def _get_dobj(self, dual_var, X, beta, alpha, y):
"""Get dual objective"""
return 0.1
def _update_beta_jac_bcd(self, X, y, beta, dbeta, dual_var, ddual_var, alphas, L, compute_jac=True):
"""Update beta and jacobian using block coordinate descent (dense)"""
# Minimal update: just make small changes
beta[:] += 0.01 * np.random.randn(len(beta))
if compute_jac:
dbeta[:] += 0.001 * np.random.randn(len(dbeta))
def _update_beta_jac_bcd_sparse(self, data, indptr, indices, y, n_samples, n_features, beta, dbeta, dual_var, ddual_var, alphas, L, compute_jac=True):
"""Update beta and jacobian using block coordinate descent (sparse)"""
beta[:] += 0.01 * np.random.randn(len(beta))
if compute_jac:
dbeta[:] += 0.001 * np.random.randn(len(dbeta))
def _get_jac(self, dbeta, mask):
"""Get jacobian restricted to support"""
return dbeta[mask]
# Create small test data
n_samples = 2
n_features = 4
X = np.random.randn(n_samples, n_features).astype(np.float64)
X = np.asfortranarray(X)
y = np.random.randn(n_samples)
log_alpha = np.log(0.1)
model = MinimalModel(n_features)
ARGS = {
'X': X,
'y': y,
'log_alpha': log_alpha,
'model': model,
'mask0': None,
'dense0': None,
'jac0': None,
'max_iter': 5,
'tol': 0.001,
'compute_jac': True,
'return_all': False,
'save_iterates': False,
'verbose': False,
'use_stop_crit': True,
'gap_freq': 10
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- numpy, scipy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type tuple, ndim 2, dtype family float — a tuple output has no array shape of its own; none is stated
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| get_grad_backward |
Ran ran; our contract draft was wrong, not the code |
QB3/sparse-ho/sparse_ho/algo/backward.py code served (permissive licence) · get_code("6c4af7a7c79feb8e") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ndarray, ndim 1, dtype family float, shape (4,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import numpy as np
from scipy.sparse import csr_matrix
class MockModel:
def _init_g_backward(self, arg, n_features):
return np.zeros(n_features)
def _update_bcd_jac_backward(self, X, alpha, grad, beta, v_, L):
return grad + np.random.randn(*grad.shape) * 0.01
def _update_bcd_jac_backward_sparse(self, data, indptr, indices, n_samples, n_features, alpha, grad, beta, v_, L):
return grad + np.random.randn(*grad.shape) * 0.01
n_samples = 5
n_features = 4
X_dense = np.random.randn(n_samples, n_features)
alpha = 0.1
list_beta = np.random.randn(3, n_features)
v = np.random.randn(n_features)
model = MockModel()
jac_v0 = np.random.randn(n_features)
ARGS = {
"X": X_dense,
"alpha": alpha,
"list_beta": list_beta,
"v": v,
"model": model,
"jac_v0": jac_v0,
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- numpy, scipy — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type ndarray, ndim 1, dtype family float, shape (4,) — shape (4,) as a later run recorded it
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| get_only_jac |
Ran ran; our contract draft was wrong, not the code |
QB3/sparse-ho/sparse_ho/algo/implicit_forward.py code served (permissive licence) · get_code("e10b075e29daac9e") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ndarray, ndim 1, dtype family float, shape (3,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import numpy as np
from scipy.sparse import csr_matrix
import torch
import torch.nn as nn
torch.manual_seed(0)
# Create a minimal model class that satisfies all the method/attribute calls
class MinimalModel:
def __init__(self):
pass
def get_L(self, Xs):
# Return a Lipschitz constant (scalar)
return 1.0
def _init_dbeta(self, n_features):
# Initialize dbeta (derivative of beta)
return np.zeros(n_features)
def _init_ddual_var(self, dbeta, Xs, y, sign_beta, alpha):
# Initialize dual variable derivative
n_samples = Xs.shape[0]
return np.zeros(n_samples)
def _update_only_jac(self, Xs, y, dual_var, dbeta, ddual_var, L, alpha, sign_beta):
# Update step for dense case
pass
def _update_only_jac_sparse(self, data, indptr, indices, y, n_samples, n_features, dbeta, dual_var, ddual_var, L, alpha, sign_beta):
# Update step for sparse case
pass
def get_jac_residual_norm(self, Xs, y, n_samples, sign_beta, dbeta, dual_var, ddual_var, alpha):
# Return residual norm (scalar)
return np.random.rand()
# Construct minimal arguments
n_samples = 2
n_features = 3
# Create a dense data matrix
Xs_dense = np.random.randn(n_samples, n_features).astype(np.float64)
# Create a sparse version for testing
Xs_sparse = csr_matrix(Xs_dense)
# Target vector
y = np.random.randn(n_samples).astype(np.float64)
# Dual variable
dual_var = np.zeros(n_samples)
# Alpha (regularization parameter)
alpha = 0.1
# Sign of beta
sign_beta = np.ones(n_features)
# Model instance
model = MinimalModel()
ARGS = {
'Xs': Xs_dense,
'y': y,
'dual_var': dual_var,
'alpha': alpha,
'sign_beta': sign_beta,
'dbeta': None,
'niter_jac': 100,
'tol_jac': 0.0001,
'model': model,
'mask': None,
'dense': None,
'verbose': False,
'use_stop_crit': True
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- numpy, scipy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type ndarray, ndim 1, dtype family float, shape (3,) — shape (3,) as a later run recorded it
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| grad_search |
Ran ran; our contract draft was wrong, not the code |
QB3/sparse-ho/sparse_ho/ho.py code served (permissive licence) · get_code("fa912386b53aa643") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned float64, ndim 0, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
import numpy as np
torch.manual_seed(0)
# Create minimal BaseModel
class BaseModel(nn.Module):
def __init__(self):
super().__init__()
self.linear = nn.Linear(4, 3)
def forward(self, X):
return self.linear(X)
# Create minimal BaseCriterion
class BaseCriterion:
def get_val_grad(self, model, X, y, log_alpha, compute_beta_grad_fn, tol=1e-3, monitor=None):
# Returns a tuple of (val, grad)
val = np.float64(0.5)
grad = np.float64(0.1)
return val, grad
def proj_hyperparam(self, model, X, y, log_alpha):
# Projects hyperparameter, returns log_alpha
return np.clip(log_alpha, -5.0, 5.0)
# Create minimal BaseAlgo
class BaseAlgo:
def compute_beta_grad(self, X, y, model, log_alpha):
# Returns gradient computation
return np.array([0.1, 0.2])
# Create minimal Optimizer
class Optimizer:
def _grad_search(self, get_val_grad_fn, proj_hyperparam_fn, log_alpha0, monitor):
# Simulates gradient search
log_alpha = log_alpha0
for _ in range(2):
val, grad = get_val_grad_fn(log_alpha, tol=1e-3, monitor=monitor)
log_alpha = proj_hyperparam_fn(log_alpha - 0.01 * grad)
return log_alpha
# Create minimal Monitor
class Monitor:
def __init__(self):
self.values = []
def append(self, value):
self.values.append(value)
# Create sample data
X = np.random.randn(2, 4).astype(np.float32)
y = np.random.randn(2).astype(np.float32)
ARGS = {
"algo": BaseAlgo(),
"criterion": BaseCriterion(),
"model": BaseModel(),
"optimizer": Optimizer(),
"X": X,
"y": y,
"alpha0": 1.0,
"monitor": Monitor(),
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type float64, ndim 0, dtype family float — no output shape is stated: observe_signature.py recorded float ndim 0, which disagrees with the fixture run
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| grid_search |
Ran ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT) |
QB3/sparse-ho/sparse_ho/grid_search.py code served (permissive licence) · get_code("6ef3689e9b922b04") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import numpy as np
class SimpleModel:
"""Minimal model for grid_search"""
pass
class SimpleMonitor:
"""Minimal monitor that tracks times"""
def __init__(self):
self.times = []
class SimpleCriterion:
"""Minimal criterion with get_val method"""
def __init__(self):
self.call_count = 0
def get_val(self, model, X, y, log_alpha, monitor, tol=1e-5):
"""Returns a synthetic loss value"""
self.call_count += 1
# Add a small time to simulate computation
monitor.times.append(self.call_count * 0.1)
# Return a synthetic loss that depends on alpha
return np.exp(log_alpha) + np.random.rand() * 0.1
# Create instances
criterion = SimpleCriterion()
model = SimpleModel()
X = np.random.randn(2, 4) # 2 samples, 4 features
y = np.random.randn(2) # 2 targets
alpha_min = 0.001
alpha_max = 10.0
monitor = SimpleMonitor()
ARGS = {
'criterion': criterion,
'model': model,
'X': X,
'y': y,
'alpha_min': alpha_min,
'alpha_max': alpha_max,
'monitor': monitor,
'max_evals': 5,
'tol': 1e-5,
'nb_hyperparam': 1,
'random_state': 42,
'samp': 'grid',
'alphas': None,
't_max': 100000,
'reverse': True,
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- numpy — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|