From be5d3e834ed32fca635ca19a36d719027af4f570 Mon Sep 17 00:00:00 2001 From: Arnaud Poret Date: Sat, 17 Aug 2019 14:33:55 +0200 Subject: [PATCH] + quiet option --- kali/attractor.go | 6 ++++-- kali/bullet.go | 6 ++++-- kali/doattractorset.go | 8 ++++++-- kali/dotherapeuticbullets.go | 8 ++++++-- kali/doversus.go | 8 ++++++-- readme.md | 3 +++ 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/kali/attractor.go b/kali/attractor.go index 2f27b6b..c4cf305 100644 --- a/kali/attractor.go +++ b/kali/attractor.go @@ -212,7 +212,7 @@ func LoadAttractorSet(setting string) AttractorSet { } return A } -func (A AttractorSet) Report(nodes []string,setting string) { +func (A AttractorSet) Report(nodes []string,setting string,quiet bool) { var ( nPoint,nCycle,i,j int name,sep,report string @@ -252,11 +252,13 @@ func (A AttractorSet) Report(nodes []string,setting string) { lines=append(lines," points: "+strconv.FormatInt(int64(nPoint),10)) lines=append(lines," cycles: "+strconv.FormatInt(int64(nCycle),10)) report=strings.Join(lines,"\n") - fmt.Println(report) file,_=os.Create(name+".txt") _,_=file.WriteString(report+"\n") file.Close() A.Save(len(nodes),setting) + if !quiet { + fmt.Println(report) + } } func (A AttractorSet) Save(n int,setting string) { var ( diff --git a/kali/bullet.go b/kali/bullet.go index 0d49b02..db43546 100644 --- a/kali/bullet.go +++ b/kali/bullet.go @@ -99,7 +99,7 @@ func (b Bullet) IsTherapeutic(Atest,Aversus AttractorSet,th float64) bool { } return y } -func (B BulletSet) Report(nodes,physioNames,pathoNames []string) { +func (B BulletSet) Report(nodes,physioNames,pathoNames []string,quiet bool) { var ( i,j int sep,report string @@ -128,10 +128,12 @@ func (B BulletSet) Report(nodes,physioNames,pathoNames []string) { } lines=append(lines,"Found therapeutic bullets: "+strconv.FormatInt(int64(len(B)),10)) report=strings.Join(lines,"\n") - fmt.Println(report) file,_=os.Create("B_therap.txt") _,_=file.WriteString(report+"\n") file.Close() + if !quiet { + fmt.Println(report) + } } func (B BulletSet) Sort() BulletSet { var ( diff --git a/kali/doattractorset.go b/kali/doattractorset.go index eb2e76f..1c18d7e 100644 --- a/kali/doattractorset.go +++ b/kali/doattractorset.go @@ -12,7 +12,7 @@ import ( func DoAttractorSet(nodes []string,Physio,Patho func(Vector) Vector) { var ( err error - help,usage,success bool + help,usage,quiet,success bool nSteps,maxTry int fileName,upd string args []string @@ -27,6 +27,8 @@ func DoAttractorSet(nodes []string,Physio,Patho func(Vector) Vector) { flagSet.BoolVar(&help,"h",false,"") flagSet.BoolVar(&usage,"usage",false,"") flagSet.BoolVar(&usage,"u",false,"") + flagSet.BoolVar(&quiet,"quiet",false,"") + flagSet.BoolVar(&quiet,"q",false,"") flagSet.IntVar(&nSteps,"nstep",1000,"") flagSet.IntVar(&maxTry,"maxtry",10,"") flagSet.StringVar(&upd,"upd","async","") @@ -52,6 +54,7 @@ func DoAttractorSet(nodes []string,Physio,Patho func(Vector) Vector) { " * -maxtry: the maximum number of random walks performed when searching for", " an attractor (default: 10)", " * -upd: the updating method to use (default: async)", + " * -q/-quiet: do not print results (but still save them to files)", " * -u/-usage: print usage only", " * -h/-help: print this help", "", @@ -117,6 +120,7 @@ func DoAttractorSet(nodes []string,Physio,Patho func(Vector) Vector) { " * -maxtry: the maximum number of random walks performed when searching for", " an attractor (default: 10)", " * -upd: the updating method to use (default: async)", + " * -q/-quiet: do not print results (but still save them to files)", " * -u/-usage: print usage only", " * -h/-help: print help", "", @@ -147,7 +151,7 @@ func DoAttractorSet(nodes []string,Physio,Patho func(Vector) Vector) { } A,success=ComputeAttractorSet(LoadMat("S.csv"),f,Bullet{},nSteps,-1,maxTry,upd,args[0],refSet) if success { - A.Report(nodes,args[0]) + A.Report(nodes,args[0],quiet) } else { fmt.Println("Warning: "+fileName+": attractor: unable to find attractors, try increasing nstep and/or maxtry") } diff --git a/kali/dotherapeuticbullets.go b/kali/dotherapeuticbullets.go index 3e3a48c..0de4057 100644 --- a/kali/dotherapeuticbullets.go +++ b/kali/dotherapeuticbullets.go @@ -12,7 +12,7 @@ import ( func DoTherapeuticBullets(nodes []string,Patho func(Vector) Vector) { var ( err error - help,usage,success bool + help,usage,quiet,success bool nSteps,maxTry int th float64 fileName,upd string @@ -27,6 +27,8 @@ func DoTherapeuticBullets(nodes []string,Patho func(Vector) Vector) { flagSet.BoolVar(&help,"h",false,"") flagSet.BoolVar(&usage,"usage",false,"") flagSet.BoolVar(&usage,"u",false,"") + flagSet.BoolVar(&quiet,"quiet",false,"") + flagSet.BoolVar(&quiet,"q",false,"") flagSet.IntVar(&nSteps,"nstep",1000,"") flagSet.IntVar(&maxTry,"maxtry",10,"") flagSet.StringVar(&upd,"upd","async","") @@ -48,6 +50,7 @@ func DoTherapeuticBullets(nodes []string,Patho func(Vector) Vector) { " an attractor (default: 10)", " * -upd: the updating method to use (default: async)", " * -th: the threshold for a bullet to be considered therapeutic (default: 5)", + " * -q/-quiet: do not print results (but still save them to files)", " * -u/-usage: print usage only", " * -h/-help: print this help", "", @@ -131,6 +134,7 @@ func DoTherapeuticBullets(nodes []string,Patho func(Vector) Vector) { " an attractor (default: 10)", " * -upd: the updating method to use (default: async)", " * -th: the threshold for a bullet to be considered therapeutic (default: 5)", + " * -q/-quiet: do not print results (but still save them to files)", " * -u/-usage: print usage only", " * -h/-help: print help", "", @@ -167,7 +171,7 @@ func DoTherapeuticBullets(nodes []string,Patho func(Vector) Vector) { Apatho=LoadAttractorSet("patho") Btherap,success=ComputeTherapeuticBullets(LoadMat("S.csv"),LoadMat("Targ.csv"),LoadMat("Moda.csv"),Patho,nSteps,maxTry,th,Aphysio,Apatho,Aversus,upd) if success { - Btherap.Report(nodes,Align(Aphysio.GetNames()," "),Align(Aversus.GetNames()," ")) + Btherap.Report(nodes,Align(Aphysio.GetNames()," "),Align(Aversus.GetNames()," "),quiet) } else { fmt.Println("Warning: "+fileName+": target: unable to find therapeutic bullets, try increasing nstep and/or maxtry") } diff --git a/kali/doversus.go b/kali/doversus.go index b482c86..ca501c6 100644 --- a/kali/doversus.go +++ b/kali/doversus.go @@ -12,7 +12,7 @@ import ( func DoVersus(nodes []string) { var ( err error - help,usage bool + help,usage,quiet bool fileName string flagSet *flag.FlagSet ) @@ -23,6 +23,8 @@ func DoVersus(nodes []string) { flagSet.BoolVar(&help,"h",false,"") flagSet.BoolVar(&usage,"usage",false,"") flagSet.BoolVar(&usage,"u",false,"") + flagSet.BoolVar(&quiet,"quiet",false,"") + flagSet.BoolVar(&quiet,"q",false,"") err=flagSet.Parse(os.Args[2:]) if err!=nil { fmt.Println("Error: "+fileName+": versus: "+err.Error()) @@ -34,6 +36,7 @@ func DoVersus(nodes []string) { "Usage: "+fileName+" versus [options]", "", "Option:", + " * -q/-quiet: do not print results (but still save them to files)", " * -u/-usage: print usage only", " * -h/-help: print this help", "", @@ -62,6 +65,7 @@ func DoVersus(nodes []string) { "Usage: "+fileName+" versus [options]", "", "Option:", + " * -q/-quiet: do not print results (but still save them to files)", " * -u/-usage: print usage only", " * -h/-help: print help", "", @@ -72,7 +76,7 @@ func DoVersus(nodes []string) { if !Exist("A_patho.csv") { fmt.Println("Error: "+fileName+": versus: no pathological attractor set found (A_patho.csv)") } else { - LoadAttractorSet("patho").GetVersus().Report(nodes,"versus") + LoadAttractorSet("patho").GetVersus().Report(nodes,"versus",quiet) } } } diff --git a/readme.md b/readme.md index 936b4f8..e7a67aa 100644 --- a/readme.md +++ b/readme.md @@ -150,6 +150,7 @@ Options: * `-nstep`: the number of steps performed during a random walk when searching for an attractor (default: `1 000`) * `-maxtry`: the maximum number of random walks performed when searching for an attractor (default: `10`) * `-upd`: the updating method to use (default: `async`) +* `-q/-quiet`: do not print results (but still save them to files) * `-u/-usage`: print usage only * `-h/-help`: print this help @@ -200,6 +201,7 @@ Usage: `example versus [options]` Option: +* `-q/-quiet`: do not print results (but still save them to files) * `-u/-usage`: print usage only * `-h/-help`: print this help @@ -269,6 +271,7 @@ Options: * `-maxtry`: the maximum number of random walks performed when searching for an attractor (default: `10`) * `-upd`: the updating method to use (default: `async`) * `-th`: the threshold for a bullet to be considered therapeutic (default: `5`) +* `-q/-quiet`: do not print results (but still save them to files) * `-u/-usage`: print usage only * `-h/-help`: print this help