<commit_before>// GastricEmptying in Go, V 3.  (C) 2017 - 2018.  Originallly on GastricEmtpying2.mod code.

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io/ioutil"
	"math"
	"os"
	"path/filepath"
	"strconv"
	"strings"
	"time"
	//
	"filepicker"
	"getcommandline"
	"tknptr"
)

/*
  REVISION HISTORY
  ----------------
  24 Feb 06 -- Added logic to excluded lines w/o numbers.
  23 Feb 06 -- LR.mod Converted to SBM2 for Win.  And since it is not allowed for this module to
                 write errors, slope and intercept will be set zero in case of an error.
  25 Sep 07 -- Decided to write to std out for output only
   3 Oct 08 -- Added decay correction for Tc-99m
  12 Sep 11 -- Added my new FilePicker module.
  26 Dec 14 -- Will change to the FilePickerBase module as I now find it easier to use.
                 But these use terminal mode.
  27 Dec 14 -- Removing unused modules so can compile in ADW.
  21 Jun 15 -- Will write out to file, and close all files before program closes.
  10 Aug 17 -- Converting to Go
  12 Aug 17 -- Added "Numerical Recipies" code, and removed old iterative algorithm.
  15 Aug 17 -- Added ability to show timestamp of the executable file, as a way of showing last linking timestamp.
                 To be used in addition of the LastAltered string.  But I can recompile without altering, as when
		 a new version of the Go toolchain is released.
   9 Sep 17 -- Changing how bufio errors are checked, based on a posting from <NAME>.
  11 Sep 17 -- Made the stdev a % factor instead of a constant factor, and tweaked the output in other ways.
  12 Sep 17 -- Added heading to output file.
  13 Sep 17 -- Adding code from Numerical Recipies for errors in x and y.
  24 Sep 17 -- To make the new code work, I'll remove lny and use OrigY and y.
  27 Sep 17 -- It works after I fixed some typos.  And I changed the order of the output values.
   2 Oct 17 -- Discovered that in very normal patients, counts are low enough for stdev to be neg.  I can't allow that!
                 And error in X (time) will be same %-age as in Y.  And StDevY cannot be larger than y.
   3 Oct 17 -- Added separate StDevTime constant, and set a minimum of 2.  Output optimized for Windows since that
                 is where it will be used in "production."
  18 Oct 17 -- Added filepicker
  15 Jun 18 -- Now at version 3, and I'm revisiting the old iterative solution that I used for a long time.  Is there a bug here?
  18 Jun 18 -- Added some comments regarding my thoughts and observations, and decided to return FittedData3 so I can get R2.
                 And screen output will be shorter than file output.
*/

const LastAltered = "18 June 2018"

/*
  Normal values from source that I don't remember anymore.
  1 hr should have 90% of activity remaining in stomach = 6.6 hr halflife = 395 min halflife
  2 hr should have 60% of activity remaining in stomach = 2.7 hr halflife = 163 min halflife
  3 hr should have 30% of activity remaining in stomach = 1.7 hr halflife = 104 min halflife
  4 hr should have 10% of activity remaining in stomach = 1.2 hr halflife = 72 min halflife

*/

//----------------------------------------------------------------------------

const MaxN = 500
const MaxCol = 10
const StDevFac = 25 // treated as a percentage for weights used for GastricGo v1 code.
const StDevTime = 10
const POTN = 1.571000         // used for fitexy and related routines
const BIG = 1e30              // this too
const ACC = 1e-3              // this too
const ITERMAX = 100           // this too, and now also for the old ressurrected code.
const ToleranceFactor = 1.E-5 // used for old code that's been ressurrected.

// stdev relates to counts, or the ordinate.  This algorithm used to apply it to the abscissa also.
// Version 2 handles these separately in fitexy.
type Point struct {
	x, y, OrigY, stdev,
	sigx, sigy, xx, yy, sx, sy, ww, // added when I added fitexy in Sep 2017, v 2.
	weight, ax float64 // added when I added old code in June 2018, v 3.
}

type inputrow []float64<commit_msg>modified:   gastric3/gastric3.go -- updated comments<commit_after>// GastricEmptying in Go, V 3.  (C) 2017 - 2018.  Originallly on GastricEmtpying2.mod code.

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io/ioutil"
	"math"
	"os"
	"path/filepath"
	"strconv"
	"strings"
	"time"
	//
	"filepicker"
	"getcommandline"
	"tknptr"
)

/*
  REVISION HISTORY
  ----------------
  24 Feb 06 -- Added logic to excluded lines w/o numbers.
  23 Feb 06 -- LR.mod Converted to SBM2 for Win.  And since it is not allowed for this module to
                 write errors, slope and intercept will be set zero in case of an error.
  25 Sep 07 -- Decided to write to std out for output only
   3 Oct 08 -- Added decay correction for Tc-99m
  12 Sep 11 -- Added my new FilePicker module.
  26 Dec 14 -- Will change to the FilePickerBase module as I now find it easier to use.
                 But these use terminal mode.
  27 Dec 14 -- Removing unused modules so can compile in ADW.
  21 Jun 15 -- Will write out to file, and close all files before program closes.
  10 Aug 17 -- Converting to Go
  12 Aug 17 -- Added "Numerical Recipies" code, and removed old iterative algorithm.
  15 Aug 17 -- Added ability to show timestamp of the executable file, as a way of showing last linking timestamp.
                 To be used in addition of the LastAltered string.  But I can recompile without altering, as when
		 a new version of the Go toolchain is released.
   9 Sep 17 -- Changing how bufio errors are checked, based on a posting from <NAME>.
  11 Sep 17 -- Made the stdev a % factor instead of a constant factor, and tweaked the output in other ways.
  12 Sep 17 -- Added heading to output file.
  13 Sep 17 -- Adding code from Numerical Recipies for errors in x and y.
  24 Sep 17 -- To make the new code work, I'll remove lny and use OrigY and y.
  27 Sep 17 -- It works after I fixed some typos.  And I changed the order of the output values.
   2 Oct 17 -- Discovered that in very normal patients, counts are low enough for stdev to be neg.  I can't allow that!
                 And error in X (time) will be same %-age as in Y.  And StDevY cannot be larger than y.
   3 Oct 17 -- Added separate StDevTime constant, and set a minimum of 2.  Output optimized for Windows since that
                 is where it will be used in "production."
  18 Oct 17 -- Added filepicker
  15 Jun 18 -- Now at version 3, and I'm revisiting the old iterative solution that I used for a long time.  Is there a bug here?
  18 Jun 18 -- Added some comments regarding my thoughts and observations, and decided to return FittedData3 so I can get R2.
                 And screen output will be shorter than file output.
  20 Jun 18 -- Added comments regarding reference normal.
*/

const LastAltered = "20 June 2018"

/*
  Normal values from source that I don't remember anymore.
  1 hr should have 90% of activity remaining in stomach = 6.6 hr halflife = 395 min halflife
  2 hr should have 60% of activity remaining in stomach = 2.7 hr halflife = 163 min halflife
  3 hr should have 30% of activity remaining in stomach = 1.7 hr halflife = 104 min halflife
  4 hr should have 10% of activity remaining in stomach = 1.2 hr halflife = 72 min halflife
  Using these 4 points as data for gastric3, I get T-1/2 of Orig std unweighted = 72.91,
  fit weighted= 60.65, fitexy weighted= 60.76, and iterated weighted= 75.73
*/

//----------------------------------------------------------------------------

const MaxN = 500
const MaxCol = 10
const StDevFac = 25 // treated as a percentage for weights used for GastricGo v1 code.
const StDevTime = 10
const POTN = 1.571000         // used for fitexy and related routines
const BIG = 1e30              // this too
const ACC = 1e-3              // this too
const ITERMAX = 100           // this too, and now also for the old ressurrected code.
const ToleranceFactor = 1.E-5 // used for old code that's been ressurrected.

// stdev relates to counts, or the ordinate.  This algorithm used to apply it to the abscissa also.
// Version 2 handles these separately in fitexy.
type Point struct {
	x, y, OrigY, stdev,
	sigx, sigy, xx, yy, sx, sy, ww, // added when I added fitexy in Sep 2017, v 2.
	weight, ax float64 // added when I added old code in June 2018, v 3.
}

type inputrow []float64
{'fraction_non_alphanumeric': 0.08232329293171727, 'fraction_numerical': 0.046321852874114965, 'mean_word_length': 2.456656988801327, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3472740', 'n_tokens_mistral': 2745, 'n_tokens_neox': 2362, 'n_words': 1326}