Exemplo n.º 1
0
func main() {
	flagModel := flag.String("model", "", "Model file in JSON")
	flagFigure := flag.String("figure", "", "Figure file in PDF")
	flagEdge := flag.Float64("edge", 0.0, "Edge prunning threshold")
	flagNode := flag.Float64("node", 0.0, "Node prunning threshold")
	flag.Parse()

	m, e := core.LoadModel(*flagModel)
	if e != nil {
		log.Fatalf("Canont load model from %s: %v", *flagModel, e)
	}

	e = core.NewVisualizer(m).Draw(*flagFigure, *flagEdge, *flagNode)
	if e != nil {
		log.Fatalf("Cannot visualzie model: %v", e)
	}
}
Exemplo n.º 2
0
func main() {
	flagModel := flag.String("model", "", "Model file in JSON format")
	flagInstances := flag.Int("instances", 10, "# synthesized instances")
	flagLength := flag.Int("length", 10, "Length of each instance")
	flagCardi := flag.Int("cardi", 4, "Cardinality of multinomial outputs")
	flagCorpus := flag.String("corpus", "", "Synthetic corpus file")
	flagSeed := flag.Int("seed", 0, "Random if negative, seed otherwise")
	flag.Parse()

	var m *core.Model
	var e error
	if m, e = core.LoadModel(*flagModel); e != nil {
		log.Printf("Cannot load %s: %v. Use default model.", *flagModel, e)
		m = new(core.Model)
		if e := json.NewDecoder(
			strings.NewReader(defaultModel)).Decode(m); e != nil {
			log.Fatalf("Cannot decode default model")
		}
	}

	f := core.CreateFileOrStdout(*flagCorpus)
	if f != os.Stdout {
		defer f.Close()
	} else {
		log.Printf("Cannot create file %s. Use stdout", *flagCorpus)
	}

	seed := time.Now().UTC().UnixNano()
	if *flagSeed >= 0 {
		seed = int64(*flagSeed)
	}

	for _, inst := range m.Sample(*flagInstances, *flagLength, *flagCardi,
		rand.New(rand.NewSource(seed))) {
		if e := json.NewEncoder(f).Encode(inst); e != nil {
			log.Fatalf("Cannot JSON-encode corpus, %v", e)
		}
	}
}