Open the context
Choose the project folder and name the files or behavior involved.
Project 1–256 finite numbers bounded by ±10^6 onto the nonnegative unit simplex. Test ties and vertex solutions, reject Booleans and compare the floating result with a numerical tolerance without interpreting the weights as calibrated probabilities.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
import math
def simplex_projection(values):
if type(values) is not list or not 1 <= len(values) <= 256:
raise ValueError("simplex.input")
if any(type(x) not in (int, float) or not -10**6 <= x <= 10**6 or not math.isfinite(x) for x in values):
raise ValueError("simplex.value")
ranked = sorted(values, reverse=True)
total, theta = 0.0, 0.0
for count, value in enumerate(ranked, 1):
total += value
candidate = (total-1)/count
if value > candidate:
theta = candidate
return [max(0.0, value-theta) for value in values]
The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.