Skip to content

Commit

Permalink
+ quiet option
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudporet committed Aug 17, 2019
1 parent f86154e commit be5d3e8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
6 changes: 4 additions & 2 deletions kali/attractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down
6 changes: 4 additions & 2 deletions kali/bullet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down
8 changes: 6 additions & 2 deletions kali/doattractorset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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","")
Expand All @@ -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",
"",
Expand Down Expand Up @@ -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",
"",
Expand Down Expand Up @@ -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")
}
Expand Down
8 changes: 6 additions & 2 deletions kali/dotherapeuticbullets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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","")
Expand All @@ -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",
"",
Expand Down Expand Up @@ -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",
"",
Expand Down Expand Up @@ -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")
}
Expand Down
8 changes: 6 additions & 2 deletions kali/doversus.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func DoVersus(nodes []string) {
var (
err error
help,usage bool
help,usage,quiet bool
fileName string
flagSet *flag.FlagSet
)
Expand All @@ -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())
Expand All @@ -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",
"",
Expand Down Expand Up @@ -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",
"",
Expand All @@ -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)
}
}
}
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit be5d3e8

Please sign in to comment.