Spaces:
Sleeping
Sleeping
Commit ·
911b780
1
Parent(s): b180b70
Oracle
Browse files356 unmodified lines357358359360360361362362363364364365366367368369366367368369370371372370371372373374375376377378376379380381382383384385386387388389356 unmodified lines plt.show()
def normalize_and_clip_weights(df,group_col="parent",weight_col ="final_weight"):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. Ensures weights are non-negative and sum to 1 per group. """ #Clip negative weights to zero 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 negatives df[weight_col] = df[weight_col].clip(lower=0)
#Normalize weights within each groupdef normalize_group(x): total = x.sum() if total>0: return x/total return np.ones_like(x)/ len(x) # Normalize within each group def normalize_group(x): total = x.sum() if total > 0: return x / total return np.ones_like(x) / len(x) df[weight_col] = df.groupby(group_col)[weight_col].transform(normalize_group) return df
def 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 df df = normalize_and_clip_weights(df) print("[INFO] Funding weights normalized successfully.", flush=True) return dfOracle/deepfundingoracle.py+16-11