import pandas as pd
def iterate(f_value: float,
number_of_nodes: int,
number_of_iterations:int,
weight_1: float = 0.5,
weight_2: float = 0.2) -> list:
"""Itearates the f_value according to provided rule and returns the resulting array
Args:
f_value: user input value that will be iterated
number_of_nodes: number of nodes that the iteration will run
number_of_iterations: number of iterations
weight_1: user provided weight, default is 0.5
weight_2: user provided weight, default is 0.2
Returns:
A list with length=number_of_iterations where each element is a list that represents
the corresponding row. Let's call returned list L. L[0][0] represents the value of
iteration1, node1. L[0][1] represents iteration1 node2 and so on.
Example:
>>> iterate(10,3,5)
[[7.0, 15.5, 17.75],
[6.6, 22.35, 28.925],
[7.7700000000000005, 32.02, 44.935],
[10.289000000000001, 46.151500000000006, 68.01075],
[14.374800000000002, 66.94105000000002, 101.48127500000001]]
>>> L = iterate(10,3,5)
>>> print(L[0][0])
7.0
>>> print(L[0][1])
15.5
"""
weight_1 = 0.5
weight_2 = 0.2
iterations = []
C = f_value + (f_value * weight_2)
for iteration_no in range(number_of_iterations):
nodes = []
for node_no in range(number_of_nodes):
if iteration_no == 0:
if node_no == 0:
# First node
value = f_value * (weight_1 + weight_2)
elif node_no < number_of_nodes-1:
# Nodes in between
value = (nodes[node_no-1] / 2) + C
else:
# Last node
value = (nodes[node_no-1] / 2) + f_value
nodes.append(value)
else:
if node_no == 0:
# First node
value = (iterations[iteration_no-1][0] * weight_1) + (iterations[iteration_no-1][1] * weight_2)
elif node_no < number_of_nodes-1:
# Nodes in between
# we need the latest iteration from [node_no -1]let
print
value = (iterations[iteration_no-1][node_no]) + (nodes[node_no-1] * weight_1) + (iterations[iteration_no-1][node_no+1] * weight_2)
else:
# Last node
value = iterations[iteration_no-1][node_no] + (nodes[node_no-1] * weight_1)
nodes.append(value)
iterations.append(nodes)
return iterations