From 580d6b5438280aa941a8f256650e767a9c537c3c Mon Sep 17 00:00:00 2001 From: rlaplaza Date: Mon, 16 Sep 2024 17:50:37 +0200 Subject: [PATCH] Added the option to use negative wps to favor low activity points during weighting --- navicat_spock/helpers.py | 15 +++++++++++++-- pyproject.toml | 2 +- setup.py | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/navicat_spock/helpers.py b/navicat_spock/helpers.py index c13e941..220bd6c 100755 --- a/navicat_spock/helpers.py +++ b/navicat_spock/helpers.py @@ -247,6 +247,17 @@ def reweighter(target, wp=2): weights = np.round( np.array([py**wp for py in scaled]), decimals=6 ) # **2 at least, could be increased + elif wp < 0: + wp = np.abs(wp) + std = target.std() + norm = sum(target) # Not needed since robust regression will normalize + rescaled = [(py - min(target)) + std for py in target] + # print(rescaled) + scaled = [(py / max(abs(target))) for py in rescaled] + # print(scaled) + weights = np.round( + np.array([1 / (py**wp) for py in scaled]), decimals=6 + ) # **2 at least, could be increased weights = normalize(weights).reshape(-1) else: std = target.std() @@ -341,7 +352,7 @@ def processargs(arguments): epilog="Remember to cite the spock paper (when its out!) \n \n - and enjoy!", ) vbuilder.add_argument( - "-version", "--version", action="version", version="%(prog)s 0.0.2" + "-version", "--version", action="version", version="%(prog)s 0.0.3" ) vbuilder.add_argument( "-i", @@ -362,7 +373,7 @@ def processargs(arguments): dest="wp", type=int, default=1, - help="In the regression, integer power with which higher activity points are weighted. Higher means low activity points are given less priority in the fit (default: 1)", + help="In the regression, integer power with which higher activity points are weighted. Higher means low activity points are given less priority in the fit. Negative values will do the opposite and give more weight to low activity points. (default: 1)", ) vbuilder.add_argument( "-v", diff --git a/pyproject.toml b/pyproject.toml index fa36b7d..ff5924b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "navicat-spock" -version = "0.0.2" +version = "0.0.3" authors = [ { name="R. Laplaza", email="rlaplaza@duck.com" }, ] diff --git a/setup.py b/setup.py index 0c4b627..3e3e707 100755 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="spock", packages=["navicat_spock"], - version="0.0.2", + version="0.0.3", description="Volcano Plot fitting tool", long_description=long_description, long_description_content_type="text/markdown",