From 59911359ecae406d8696388265a6a8c8a9f9a862 Mon Sep 17 00:00:00 2001 From: rakow Date: Thu, 27 Jun 2024 20:06:44 +0200 Subject: [PATCH] norm subgroups to 1 --- .../org/matsim/application/CommandRunner.java | 2 +- .../analysis/population/TripByGroupAnalysis.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/contribs/application/src/main/java/org/matsim/application/CommandRunner.java b/contribs/application/src/main/java/org/matsim/application/CommandRunner.java index b55fc548a56..ea0af2e6dd2 100644 --- a/contribs/application/src/main/java/org/matsim/application/CommandRunner.java +++ b/contribs/application/src/main/java/org/matsim/application/CommandRunner.java @@ -108,7 +108,7 @@ private void runCommand(Class clazz, Path input) thr MATSimAppCommand command = clazz.getDeclaredConstructor().newInstance(); String[] args = this.args.get(clazz); args = ArrayUtils.addAll(args, createArgs(clazz, args, input)); - log.info("Running {} with arguments: {}", clazz, Arrays.toString(args)); + log.info("Running {} with arguments: {}", clazz, String.join(" ", args)); command.execute(args); } diff --git a/contribs/application/src/main/java/org/matsim/application/analysis/population/TripByGroupAnalysis.java b/contribs/application/src/main/java/org/matsim/application/analysis/population/TripByGroupAnalysis.java index 47edfec0824..b63a58f5ed8 100644 --- a/contribs/application/src/main/java/org/matsim/application/analysis/population/TripByGroupAnalysis.java +++ b/contribs/application/src/main/java/org/matsim/application/analysis/population/TripByGroupAnalysis.java @@ -81,6 +81,22 @@ final class TripByGroupAnalysis { } } + // Norm shares per instance of each group to sum of 1 + for (Group group : this.groups) { + + String norm = group.columns.get(0); + if (group.columns.size() > 1) + throw new UnsupportedOperationException("Multiple columns not supported yet"); + + Table df = group.data; + for (String label : df.stringColumn(norm).asSet()) { + DoubleColumn dist_group = df.doubleColumn("share"); + Selection sel = df.stringColumn(norm).isEqualTo(label); + double total = dist_group.where(sel).sum(); + if (total > 0) + dist_group.set(sel, dist_group.divide(total)); + } + } } }