Spaces:
Sleeping
Sleeping
Commit ·
911b780
1
Parent(s): b180b70
Oracle
Browse files356 unmodified lines357358359360361362363364365366367368369370371372373374375376377378379380381382383384356 unmodified linesplt.show()def normalize_and_clip_weights(df,group_col="parent",weight_col ="final_weight"):"""Ensures all weights are non-negative and sum to 1 within each group."""#Clip negative weights to zerodf[weight_col] = df[weight_col].clip(lower=0)#Normalize weights within each groupdef normalize_group(x):total = x.sum()if total>0:return x/totalreturn np.ones_like(x)/ len(x)df[weight_col] = df.groupby(group_col)[weight_col].transform(normalize_group)return dfdef normalize_funding(df):"""Normalize funding weights for child repositories grouped by parent."""print("[INFO] Normalizing funding weights...", flush=True)df = normalize_and_clip_weights(df)print("[INFO] Funding weights normalized successfully.", flush=True)return df356 unmodified lines357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389356 unmodified linesplt.show()def normalize_and_clip_weights(df, group_col="parent", weight_col="final_weight"):"""Ensures weights are non-negative and sum to 1 per group."""if df is None:raise ValueError("DataFrame is None, cannot normalize weights.")if weight_col not in df.columns:raise KeyError(f"`{weight_col}` column not found in DataFrame.")# Clip negativesdf[weight_col] = df[weight_col].clip(lower=0)# Normalize within each groupdef normalize_group(x):total = x.sum()if total > 0:return x / totalreturn np.ones_like(x) / len(x)df[weight_col] = df.groupby(group_col)[weight_col].transform(normalize_group)return dfdef normalize_funding(df):"""Normalize funding weights for child repositories grouped by parent."""print("[INFO] Normalizing funding weights...", flush=True)if df is None or df.empty:print("[WARN] Skipping normalization: DataFrame is None or empty.", flush=True)return dfdf = normalize_and_clip_weights(df)print("[INFO] Funding weights normalized successfully.", flush=True)return df
Oracle/deepfundingoracle.py+16-11