Trainable Bezier Curve Multiparameter Regressor
Bezier curves
Multiparameter regression
Trainable regressor
Curve creation
Skew adjustment
Input value evaluation
This text details the development of a trainable Bezier curve multiparameter regressor, which involves creating functions for generating curves, adjusting for skew, and evaluating input values. The creation and evaluation process are discussed in detail, providing insights into how this powerful tool can be used in various applications.
first, we need a bezier curve connects (0,0) and (1,1)
import numpy as np
import bezier
def bezierCurve(start=(0,0), end=(1,1), skew=0):
# skew: (-0.5,0.5) otherwise this shit will look ugly.
assert skew >=-0.5
assert skew <=0.5
= start
x_start, y_start = end
x_end, y_end = x_end - x_start
x_diff = y_end - y_start
y_diff = np.asfortranarray(
nodes1
[* (0.5 + skew), x_end],
[x_start, x_diff * (0.5 - skew), y_end],
[y_start, y_diff
]
)= bezier.Curve(nodes1, degree=2)
curve1 = {'x_start':x_start, 'x_diff':x_diff,'x_end':x_end}
curve_params return curve1, curve_params
def evaluateBezierCurve(input_value:float,curve, curve_params:dict)
= curve_params['x_start']
x_start = curve_params['x_end']
x_end assert x_start <= input_value
assert x_end >= input_value
= curve_params['x_diff']
x_diff = (input_value - x_start)/x_diff
s = curve.evaluate(s)
points # we only get the single point.
= points.T[0]
point = point
x,y = y
result return result
then, we define our very recursive or flexible regressor:
def multiParameterExponentialNetwork(*args, input_bias=0.05, curve_function=bezierCurve, curve_function_kwargs = {'start':(0,0),'end':(1,1)'skew':0}, evaluate_function=evaluateBezierCurve):
= curve_function(**curve_function_kwargs)
curve, curve_params = evaluate_function(input_bias, curve, curve_params)
value for index, input_value in enumerate(args):
= [input_value]*(index+1)
apply_list for apply_item in apply_list:
+= (1-value)*function(apply_item, **function_kwargs)
value return value