<commit_before># Executable path
executable="../glob_opt";
execLog="lastRun.log"
execPyRelGraph="python ../readGraphProperties.py"
execPyStats="python ../collectStatistics.py"
###############################################
doExecPy=true           # Set to true if generating graphs
dryRun=false            # Values: [true/false]. If "true", don't execute, just show calls
noVis=false             # Only show premerge and final output

# startAt=0: do segment
# startAt=1: don't do segment, do premerge
# startAt=2: don't do premerge, do iteration 0
startAt=0
nbExtraIter=40          # Values: [ 1..20 ] iteration count. Default: 2.
reprPwMult=3            # Values: [ 1, 5 ,10]. Multiplies pw with this number when doing lvl2 (representatives)
use90=24                # Values: [ 100 ] Will be re-set by runscript
extendedAngleGens="90"  # Values: [ "0", "90", ... ]

anglegens="0"           # Values: ["0", "60", "90", "60,90", ... ] Desired angle generators in degrees. Default: 90.
unary=100000            # Values: [1000, 1000000]
spatWeight=0            # Values: [ 10, 0 ] (Penalty that's added, if two primitives with different directions are closer than 2 x scale)
truncAngle=$anglelimit  # Values: [ 0, $anglelimit, 0.15 ] (Pairwise cost truncation angle in radians)
smallThreshDiv="2"      # Values: [ 2, 3, ... ] Stepsize of working scale.

# Parse runScripts
runFileName=`basename $0`;
runPath=$(dirname "`file $0 | awk '{print $5}' |cut -c 2-`");
echo "runPath:" $runPath
source "$runPath/runRepr.sh"; echo "loaded runRepr.sh"
source "$runPath/runFuncs.sh"; echo "loaded runFuncs.sh"

function print_usage() {
        echo "usage:\t run.sh scale anglelimit pairwisecost [pop-limit] [3D] [smallThreshStart]"
        echo "example:\t run.sh 0.03 0.2 1 25 3D 64"
        echo "showPearl: ../globOptVis --show --scale 0.05 --pop-limit 0 -p primitives.pearl.csv -a points_primitives.pearl.csv --title \"Pearl\" --use-tags --no-clusters --no-pop"
}

# parse scale
if [[ -z "$1" ]]; then print_usage; exit 1; else scale=$1; fi
# parse angle-limit
if [[ -z "$2" ]]; then print_usage; exit 1; else anglelimit=$2; fi
# parse pairwise cost
if [[ -z "$3" ]]; then print_usage; exit 1; else pw=$3; fi
# parse population limit
if [ -n "$4" ]; then poplimit=$4; else poplimit=5; fi
# parse 3D
if [ -n "$5" ]; then flag3D=$5; else flag3D=""; fi
# parse smallThresh (a size(spatialSignificance) threshold for primitives to work with)
if [ -n "$6" ]; then smallThresh=$6; else smallThresh="1"; fi

########################################
#### We usually don't change the following:
# Moved to argument 6
#smallThresh="256" # smallThresh * scale is the small threshold # 5 was good for most of the stuff, except big scenes (kinect, lanslevillard)
smallThreshlimit="0"    # last threshold

dirbias="0";	# Values: [ 0, *1* ] (Not-same-dir-id cost offset. Default: 0. Don't use, if freqweight is on.)
freqweight="0"; # Values: [ 0, *1000* ] (Dataterm = (freqweight / #instances) * datacost)
adopt="0";      # Values: [ *0*, 1] (Adopt points argument. Default: 0)
cmp=0           # Values: [0,1]
allowPromoted="--allow-promoted" # Will be turned off after 3 iterations at the end of loop
keepSingles="--keep-singles"     # Will be turned off after 1 iteration at the end of loop

noClusters="--no-clusters"  # Values: [ "", "--no-clusters" ] (Flag that turns spatial clustering extra variables off)
useAngleGen=""              # Values: [ "", "--use-angle-gen" ] (Flag which makes not same directioned primitives not to penalize eachother)
formParams="$noClusters $useAngleGen --spat-weight $spatWeight --trunc-angle $truncAngle"

# In candidate generation, divide angle limit with this to match copies. Default: 1. Set to 10, if too many candidates (variables).
cand_anglediv="1";          # for 3D: "2.5";
# Multiply scale by this number to get the segmentation (regionGrowing) spatial distance
segmentScaleMultiplier="1"; # for 3D: "2.5";
pwCostFunc="spatsqrt"       # Spatial cost function.

visdefparam="--angle-gens $anglegens --use-tags --no-clusters --statuses -1,1 --no-pop --dir-colours --no-rel --no-scale --bg-colour .9,.9,.9" #"--use-tags --no-clusters" #--ids
iterationConstrMode="patch" # what to add in the second iteration formulate. Default: 0 (everyPatchNeedsDirection), experimental: 2 (largePatchesNeedDirection).

safeMode="";                #"--safe-mode"; #"--safe-mode" # "--safe-mode" for new, or "" for old version
variableLimit=1100; # 1300; # Safe mode gets turned on, and generate rerun, if candidates exceed this number (1300)
premerge=1                  # Call merge after segmentation 0/1
algCode=0                   # 0==B_BB, OA, QG, 3==Hyb, ECP, IFP
#######################################
#######################################

echo "scale: $scale"
echo "pw: $pw"
echo "pop-limit: $poplimit"
echo "anglegens: $anglegens"
echo "angle-limit: $anglelimit"
echo "freq-weight: $freqweight"
echo "region-grow-scale-mult: $segmentScaleMultiplier"
echo "smallThresh: " $smallThresh
echo "pw cost: " $pwCostFunc

rm $execLog

# call it
save_args $0 $@ "--reprPwMult $reprPwMult --extendedAngleGens $extendedAngleGens $formParams --freqweight" $freqweight "--angle-limit" $anglelimit "--segment-scale-mult" $segmentScaleMultiplier "--adopt" $adopt "--dirbias" $dirbias "--cand-anglediv" ${cand_anglediv} "--angle-gens" $anglegens "--cost-fn" $pwCostFunc "--small-thresh" $smallThresh "--small-thresh-limit" $smallThreshLimit "--smallThreshDiv" $smallThreshDiv --unary $unary --cmp $cmp

#####
# Check if the gt folder exists, in that case compute the primitive comparisons
correspondance=false
correspondance_exe="../corresp"
correspondance_gtprim="./gt/primitives.csv"
correspondance_gtassing="./gt/points_primitives.csv"
if [ -e "$correspondance_gtprim" ]; then
  echo "Ground truth folder detected, compute primitive correspondances" 
  correspondance=true  
fi
####

# Backup energy.csv
mv energy.csv energy.csv.bak

# [0] Segmentation. OUTPUT: patches.csv, points_primitives.csv
if [ $startAt -eq 0 ]; then
    my_exec "$executable --segment$flag3D --angle-limit $anglelimit --scale $scale --dist-limit-mult $segmentScaleMultiplier --angle-gens $anglegens"
fi

input="patches.csv";
assoc="points_primitives.csv";

# PreMerge?
if [ $startAt -le 1 ]; then
    # merge before start
    if [ $premerge -ne 0 ]; then
        echo "performing premerge"
        my_exec "$executable --merge$flag3D --scale $scale --adopt $adopt --prims $input -a $assoc --angle-gens $anglegens --patch-pop-limit $poplimit"

        # save patches
        cp $input segments.csv
        cp $assoc points_segments.csv
        cp patches.csv_merged_it-1.csv $input
        cp points_primitives_it-1.csv $assoc<commit_msg>- changed run.sh to save segments.csv with or without preMerge<commit_after># Executable path
executable="../glob_opt";
execLog="lastRun.log"
execPyRelGraph="python ../readGraphProperties.py"
execPyStats="python ../collectStatistics.py"
###############################################
doExecPy=true           # Set to true if generating graphs
dryRun=false            # Values: [true/false]. If "true", don't execute, just show calls
noVis=false             # Only show premerge and final output

# startAt=0: do segment
# startAt=1: don't do segment, do premerge
# startAt=2: don't do premerge, do iteration 0
startAt=0
nbExtraIter=40          # Values: [ 1..20 ] iteration count. Default: 2.
reprPwMult=3            # Values: [ 1, 5 ,10]. Multiplies pw with this number when doing lvl2 (representatives)
use90=24                # Values: [ 100 ] Will be re-set by runscript
extendedAngleGens="90"  # Values: [ "0", "90", ... ]

anglegens="0"           # Values: ["0", "60", "90", "60,90", ... ] Desired angle generators in degrees. Default: 90.
unary=100000            # Values: [1000, 1000000]
spatWeight=0            # Values: [ 10, 0 ] (Penalty that's added, if two primitives with different directions are closer than 2 x scale)
truncAngle=$anglelimit  # Values: [ 0, $anglelimit, 0.15 ] (Pairwise cost truncation angle in radians)
smallThreshDiv="2"      # Values: [ 2, 3, ... ] Stepsize of working scale.

# Parse runScripts
runFileName=`basename $0`;
runPath=$(dirname "`file $0 | awk '{print $5}' |cut -c 2-`");
echo "runPath:" $runPath
source "$runPath/runRepr.sh"; echo "loaded runRepr.sh"
source "$runPath/runFuncs.sh"; echo "loaded runFuncs.sh"

function print_usage() {
        echo "usage:\t run.sh scale anglelimit pairwisecost [pop-limit] [3D] [smallThreshStart]"
        echo "example:\t run.sh 0.03 0.2 1 25 3D 64"
        echo "showPearl: ../globOptVis --show --scale 0.05 --pop-limit 0 -p primitives.pearl.csv -a points_primitives.pearl.csv --title \"Pearl\" --use-tags --no-clusters --no-pop"
}

# parse scale
if [[ -z "$1" ]]; then print_usage; exit 1; else scale=$1; fi
# parse angle-limit
if [[ -z "$2" ]]; then print_usage; exit 1; else anglelimit=$2; fi
# parse pairwise cost
if [[ -z "$3" ]]; then print_usage; exit 1; else pw=$3; fi
# parse population limit
if [ -n "$4" ]; then poplimit=$4; else poplimit=5; fi
# parse 3D
if [ -n "$5" ]; then flag3D=$5; else flag3D=""; fi
# parse smallThresh (a size(spatialSignificance) threshold for primitives to work with)
if [ -n "$6" ]; then smallThresh=$6; else smallThresh="1"; fi

########################################
#### We usually don't change the following:
# Moved to argument 6
#smallThresh="256" # smallThresh * scale is the small threshold # 5 was good for most of the stuff, except big scenes (kinect, lanslevillard)
smallThreshlimit="0"    # last threshold

dirbias="0";	# Values: [ 0, *1* ] (Not-same-dir-id cost offset. Default: 0. Don't use, if freqweight is on.)
freqweight="0"; # Values: [ 0, *1000* ] (Dataterm = (freqweight / #instances) * datacost)
adopt="0";      # Values: [ *0*, 1] (Adopt points argument. Default: 0)
cmp=0           # Values: [0,1]
allowPromoted="--allow-promoted" # Will be turned off after 3 iterations at the end of loop
keepSingles="--keep-singles"     # Will be turned off after 1 iteration at the end of loop

noClusters="--no-clusters"  # Values: [ "", "--no-clusters" ] (Flag that turns spatial clustering extra variables off)
useAngleGen=""              # Values: [ "", "--use-angle-gen" ] (Flag which makes not same directioned primitives not to penalize eachother)
formParams="$noClusters $useAngleGen --spat-weight $spatWeight --trunc-angle $truncAngle"

# In candidate generation, divide angle limit with this to match copies. Default: 1. Set to 10, if too many candidates (variables).
cand_anglediv="1";          # for 3D: "2.5";
# Multiply scale by this number to get the segmentation (regionGrowing) spatial distance
segmentScaleMultiplier="1"; # for 3D: "2.5";
pwCostFunc="spatsqrt"       # Spatial cost function.

visdefparam="--angle-gens $anglegens --use-tags --no-clusters --statuses -1,1 --no-pop --dir-colours --no-rel --no-scale --bg-colour .9,.9,.9" #"--use-tags --no-clusters" #--ids
iterationConstrMode="patch" # what to add in the second iteration formulate. Default: 0 (everyPatchNeedsDirection), experimental: 2 (largePatchesNeedDirection).

safeMode="";                #"--safe-mode"; #"--safe-mode" # "--safe-mode" for new, or "" for old version
variableLimit=1100; # 1300; # Safe mode gets turned on, and generate rerun, if candidates exceed this number (1300)
premerge=1                  # Call merge after segmentation 0/1
algCode=0                   # 0==B_BB, OA, QG, 3==Hyb, ECP, IFP
#######################################
#######################################

echo "scale: $scale"
echo "pw: $pw"
echo "pop-limit: $poplimit"
echo "anglegens: $anglegens"
echo "angle-limit: $anglelimit"
echo "freq-weight: $freqweight"
echo "region-grow-scale-mult: $segmentScaleMultiplier"
echo "smallThresh: " $smallThresh
echo "pw cost: " $pwCostFunc

rm $execLog

# call it
save_args $0 $@ "--reprPwMult $reprPwMult --extendedAngleGens $extendedAngleGens $formParams --freqweight" $freqweight "--angle-limit" $anglelimit "--segment-scale-mult" $segmentScaleMultiplier "--adopt" $adopt "--dirbias" $dirbias "--cand-anglediv" ${cand_anglediv} "--angle-gens" $anglegens "--cost-fn" $pwCostFunc "--small-thresh" $smallThresh "--small-thresh-limit" $smallThreshLimit "--smallThreshDiv" $smallThreshDiv --unary $unary --cmp $cmp

#####
# Check if the gt folder exists, in that case compute the primitive comparisons
correspondance=false
correspondance_exe="../corresp"
correspondance_gtprim="./gt/primitives.csv"
correspondance_gtassing="./gt/points_primitives.csv"
if [ -e "$correspondance_gtprim" ]; then
  echo "Ground truth folder detected, compute primitive correspondances" 
  correspondance=true  
fi
####

# Backup energy.csv
mv energy.csv energy.csv.bak

input="patches.csv";
assoc="points_primitives.csv";

# [0] Segmentation. OUTPUT: patches.csv, points_primitives.csv
if [ $startAt -eq 0 ]; then
    my_exec "$executable --segment$flag3D --angle-limit $anglelimit --scale $scale --dist-limit-mult $segmentScaleMultiplier --angle-gens $anglegens"
    # save output
    cp $input "segments.csv"
    cp $assoc "points_segments.csv"
fi

# PreMerge?
if [ $startAt -le 1 ]; then
    # merge before start
    if [ $premerge -ne 0 ]; then
        echo "performing premerge"
        my_exec "$executable --merge$flag3D --scale $scale --adopt $adopt --prims $input -a $assoc --angle-gens $anglegens --patch-pop-limit $poplimit"

        # save patches
        cp patches.csv_merged_it-1.csv $input
        cp points_primitives_it-1.csv $assoc
{'fraction_non_alphanumeric': 0.16351921795156632, 'fraction_numerical': 0.026660742057320594, 'mean_word_length': 3.7751060820367752, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3269611', 'n_tokens_mistral': 4653, 'n_tokens_neox': 4283, 'n_words': 1384}