In mathematics, the Fibonacci sequence is a sequence in which each number is the sum of the two preceding ones, starting with [0, 1]
.
Let's calculate the first ten values of the sequence with the init_fields
step factory function to initialize the accumulator variable, using the step
function to determine the next value in the sequence.
from mltraq import create_experiment, Run
from mltraq.steps.init_fields import init_fields
def step(run: Run):
run.fields.F.append(run.fields.F[-1] + run.fields.F[-2])
print(
create_experiment()
.execute(init_fields({"F": [0, 1]}))
.execute([step] * 8)
.runs.first()
.fields.F
)
# Output
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Learn more about the superpowers of MLtraq at https://mltraq.com/
Top comments (0)