allow models to also be executables
This commit is contained in:
parent
ade8947734
commit
07f0fd1d3f
33
README.md
33
README.md
|
@ -1,6 +1,6 @@
|
||||||
# A minimalist calculator for fermi estimation
|
# A calculator for distributions, for Fermi estimation
|
||||||
|
|
||||||
This project is a minimalist, calculator-style DSL for fermi estimation. It can multiply, divide, add and substract scalars, lognormals and beta distributions.
|
This project is a minimalist, calculator-style DSL for fermi estimation. It can multiply, divide, add and substract scalars, lognormals and beta distributions, and supports variables.
|
||||||
|
|
||||||
## Motivation
|
## Motivation
|
||||||
|
|
||||||
|
@ -101,8 +101,31 @@ $ fermi -n 1_000_000
|
||||||
|
|
||||||
- It's conceptually clearer to have all the multiplications first and then all the divisions
|
- It's conceptually clearer to have all the multiplications first and then all the divisions
|
||||||
- For things between 0 and 1, consider using a beta distribution
|
- For things between 0 and 1, consider using a beta distribution
|
||||||
- Because the model reads from standard input, you can pipe a model to it. For instance, try cat more/piano-tuners.f | fermi
|
|
||||||
- You can also save a session to a logfile with tee. Try fermi | tee -a fermi.log
|
|
||||||
|
### Integrations with linux utilities
|
||||||
|
|
||||||
|
Because the model reads from standard input, you can pipe a model to it:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ cat more/piano-tuners.f | fermi
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also
|
||||||
|
|
||||||
|
...which means a model an executable file by adding the following at the top!
|
||||||
|
|
||||||
|
```
|
||||||
|
#!/bin/usr/fermi -f
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
You can save a session to a logfile with tee:
|
||||||
|
|
||||||
|
```
|
||||||
|
fermi | tee -a fermi.log
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## Different levels of complexity
|
## Different levels of complexity
|
||||||
|
|
||||||
|
@ -143,10 +166,10 @@ Done:
|
||||||
- [x] Allow input with K/M/T
|
- [x] Allow input with K/M/T
|
||||||
- [x] Document parenthesis syntax
|
- [x] Document parenthesis syntax
|
||||||
- [x] Specify number of samples as a command line option
|
- [x] Specify number of samples as a command line option
|
||||||
|
- [x] Figure out how to make models executable, by adding a #!/bin/bash-style command at the top?
|
||||||
|
|
||||||
To (possibly) do:
|
To (possibly) do:
|
||||||
|
|
||||||
- [ ] Figure out how to make models executable, by adding a #!/bin/bash-style command at the top?
|
|
||||||
- [ ] Add functions. Now easier to do with an explicit representation of the stakc
|
- [ ] Add functions. Now easier to do with an explicit representation of the stakc
|
||||||
- [ ] Think about how to draw a histogram from samples
|
- [ ] Think about how to draw a histogram from samples
|
||||||
- [ ] Dump samples to file
|
- [ ] Dump samples to file
|
||||||
|
|
17
fermi.go
17
fermi.go
|
@ -411,10 +411,23 @@ replForLoop:
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
num_samples_flag := flag.Int("n", N_SAMPLES, "Specifies the number of samples to draw when using samples")
|
num_samples_flag := flag.Int("n", N_SAMPLES, "Specifies the number of samples to draw when using samples")
|
||||||
flag.Parse()
|
|
||||||
N_SAMPLES = *num_samples_flag
|
N_SAMPLES = *num_samples_flag
|
||||||
|
filename := flag.String("f", "", "Specifies a file with a model to run")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
var reader *bufio.Reader = nil
|
||||||
|
if *filename != "" {
|
||||||
|
file, err := os.Open(*filename)
|
||||||
|
if err == nil {
|
||||||
|
reader = bufio.NewReader(file)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Error opening filename; reading from stdin instead\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if reader == nil {
|
||||||
|
reader = bufio.NewReader(os.Stdin)
|
||||||
|
}
|
||||||
stack := Stack{old_dist: INIT_DIST, vars: make(map[string]Dist)}
|
stack := Stack{old_dist: INIT_DIST, vars: make(map[string]Dist)}
|
||||||
runRepl(stack, reader)
|
runRepl(stack, reader)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
10
more/executable-model.fermi
Executable file
10
more/executable-model.fermi
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/fermi -f
|
||||||
|
5M 12M # number of people living in Chicago
|
||||||
|
beta 1 200 # fraction of people that have a piano
|
||||||
|
30 180 # minutes it takes to tune a piano, including travel time
|
||||||
|
/ 48 52 # weeks a year that piano tuners work for
|
||||||
|
/ 5 6 # days a week in which piano tuners work
|
||||||
|
/ 6 8 # hours a day in which piano tuners work
|
||||||
|
/ 60 # minutes to an hour
|
||||||
|
=: piano_tuners
|
||||||
|
exit
|
Loading…
Reference in New Issue
Block a user