cnellington / Contextualized

An SKLearn-style toolbox for estimating and analyzing models, distributions, and functions with context-specific parameters.
http://contextualized.ml/
GNU General Public License v3.0
67 stars 12 forks source link

Duplicate functions and unclear link function #252

Open BaihengChen opened 2 months ago

BaihengChen commented 2 months ago

For contextualized/functions.py,

Qusetion 1:

def linear(x, slope, intercept): return x * slope + intercept

def linear_link(x, slope, intercept): return x * slope + intercept

def linear_link_constructor(slope=1, intercept=0): return make_fn(linear_link, slope=slope, intercept=intercept)

def linear_constructor(slope=1, intercept=0): return make_fn(linear, slope=slope, intercept=intercept)

It seems like "linear_link" and "linear" is the same function. I wonder do we need both of them in the project?

Question 2:

LINK_FUNCTIONS = { "identity": linear_link_constructor(), "logistic": logistic_constructor(), "softmax": softmax_link_constructor(), }

After defining all the necessary functions, I noticed that the key-value pair "identity": linear_link_constructor() is a little bit weird. From the defalt parameters, linear function with slope=1 and intercept=0, linear_link is exactly identity function. But if we provide different input parameters, linear_link will no longer equals to the identity function. I wonder if this is a typo and do we need to fix this.

cnellington commented 2 months ago

Hey @BaihengChen, I agree with both of these. This likely occurred as a result of a past refactor where we aggregated these various functions from different files into contextualized.functions. If you'd like to take a shot at making the fixes, I think this could be a great first contribution.

BaihengChen commented 2 months ago

Thanks for your reply! I will try to create a new fork and PR it later after I fix this!