Ejemplo n.º 1
0
func main() {
	flag.Parse()
	flow.Ready()

	f.Run()

}
Ejemplo n.º 2
0
func main() {
	gob.Register(Centroid{})
	gob.Register(itemset.Centroid{})
	gob.Register(utils.Hash64Set{})
	flag.Parse()

	t1 := time.Now()
	records := utils.ReadCSV("./dataset.csv")

	Object := reader.NewStreamObject(len(records[0]), numClusters)
	Stream := stream.NewStream(Object)

	outChannel := make(chan Centroid)

	ch := make(chan []float64)

	source := f.Channel(ch)

	f1 := source.Map(func(record []float64) Centroid {
		return Centroid{C: Stream.AddVectorOnlineStep(record)}
	}).AddOutput(outChannel)

	flow.Ready()

	var wg sync.WaitGroup

	goStart(&wg, func() {
		f1.Run()
	})

	goStart(&wg, func() {
		for out := range outChannel {
			Stream.CentroidCounter.Add(out.C)
		}
	})

	for _, record := range records {
		ch <- record
	}

	close(ch)
	wg.Wait()

	normalizedResults := Stream.GetCentroids()
	ts := time.Since(t1)

	file, err := os.OpenFile("./results.txt", os.O_WRONLY|os.O_CREATE, 0644)
	if err != nil {
		panic(err)
	}
	defer file.Close()
	for _, result := range normalizedResults {
		for _, dimension := range result {
			file.WriteString(fmt.Sprintf("%f ", parse.DeNormalize(dimension)))
		}
		file.WriteString("\n")
	}
	file.WriteString("Time: " + ts.String())
}
Ejemplo n.º 3
0
func testInputOutputChannels() {
	ch := make(chan int)
	f1 := flow.New()
	source := f1.Channel(ch)
	left := source.Map(func(t int) (int, int) {
		return t, t * 2
	})
	right := source.Map(func(t int) (int, int) {
		return t, t * 3
	})

	outChannel := make(chan struct {
		X, Y, Z int
	})

	left.Join(right).AddOutput(outChannel)

	outInt := make(chan int)
	source.AddOutput(outInt)

	flow.Ready()

	var wg sync.WaitGroup
	goStart(&wg, func() {
		f1.Run()
	})

	goStart(&wg, func() {
		for out := range outInt {
			fmt.Printf("source %d \n", out)
		}
	})

	goStart(&wg, func() {
		for out := range outChannel {
			fmt.Printf("%d : %d\n", out.X, out.Y)
		}
	})

	limit := 5
	for i := 0; i < limit; i++ {
		ch <- i
		ch <- i
	}
	close(ch)

	wg.Wait()
}
Ejemplo n.º 4
0
func main() {
	flag.Parse()

	f.Source(func(out chan string) {
		for i := 1; i <= 1000; i++ {
			txt := createRandomString(toolkit.RandInt(23) + 10)
			fmt.Printf("Data %d is %s \n", i, txt)
			out <- txt
		}
	}, 3).Map(func(s string) (int, int) {
		return len(s), 1
	}).Partition(5).ReduceByKey(func(x, y int) int {
		return x + y
	}).Sort(nil).Map(func(k int, v int) {
		fmt.Printf("Number of data with %d chars are %d \n", k, v)
	})

	flow.Ready()
	f.Run()
}
Ejemplo n.º 5
0
func testUnrolledStaticLoop() {
	ch := make(chan int)
	f1 := flow.New()
	left := f1.Channel(ch).Partition(2).Map(func(t int) (int, int) {
		return t, t * 2
	})

	for i := 0; i < 7; i++ {
		left = left.Map(func(x, y int) (int, int) {
			return x + 1, y + 1
		})
	}

	outChannel := make(chan struct {
		X, Y int
	})

	left.AddOutput(outChannel)

	flow.Ready()

	var wg sync.WaitGroup
	goStart(&wg, func() {
		f1.Run()
	})

	goStart(&wg, func() {
		for out := range outChannel {
			fmt.Printf("%d : %d\n", out.X, out.Y)
		}
	})

	limit := 5
	for i := 0; i < limit; i++ {
		ch <- i
	}
	close(ch)

	wg.Wait()
}