コード例 #1
0
ファイル: utils.go プロジェクト: skiesel/expsys
func Group(ds *rdb.Dataset, key string) map[string]*rdb.Dataset {
	values := ds.GetDatasetStringValues(key)
	valueSet := map[string]string{}
	for _, value := range values {
		_, exists := valueSet[value]
		if !exists {
			valueSet[value] = value
		}
	}

	grouped := map[string]*rdb.Dataset{}

	for value, _ := range valueSet {
		filter := func(str string) bool {
			return str == value
		}
		grouped[value] = ds.FilterDataset(filter, key).RenameDataset(ds.GetName() + " " + value)
	}
	return grouped
}
コード例 #2
0
ファイル: standard-plots.go プロジェクト: skiesel/expsys
func PlotXvsYGroupedByXs(title, directory string, groupeddss map[string][]*rdb.Dataset, yValuesKey, yValuesLabel, xValuesLabel string) {
	var plottingPointArgs []interface{}
	var plottingErrorArgs []interface{}

	names := map[string]bool{}
	xKeys := []float64{}
	for xKey, dssGroup := range groupeddss {
		xKeys = append(xKeys, datautils.ParseFloatOrFail(xKey))
		for _, d := range dssGroup {
			names[d.GetName()] = true
		}
	}

	sort.Float64s(xKeys)
	xKeyStrings := []string{}
	for _, floatVal := range xKeys {
		xKeyStrings = append(xKeyStrings, strconv.FormatFloat(floatVal, 'f', 1, 64))
	}

	for name, _ := range names {

		datasetPointsAcrossGroups := []plotter.XYer{}

		for _, groupKey := range xKeyStrings {

			dssGroup := groupeddss[groupKey]

			var ds *rdb.Dataset

			for _, d := range dssGroup {
				if d.GetName() == name {
					ds = d
					break
				}
			}

			if ds == nil {
				str := fmt.Sprintf("Couldn't find ds (%s) in dss group (%s)", name, groupKey)
				panic(str)
			}

			values := ds.GetDatasetFloatValues(yValuesKey)
			if len(values) == 0 {
				continue
			}
			xys := make(plotter.XYs, len(values))
			datasetPointsAcrossGroups = append(datasetPointsAcrossGroups, xys)

			for i, val := range values {
				xys[i].X = datautils.ParseFloatOrFail(groupKey)
				xys[i].Y = val
			}
		}

		mean95, err := plotutil.NewErrorPoints(plotutil.MeanAndConf95, datasetPointsAcrossGroups...)

		if err != nil {
			fmt.Println(mean95)
			panic(err)
		}
		plottingPointArgs = append(plottingPointArgs, name, mean95)
		plottingErrorArgs = append(plottingErrorArgs, mean95)
	}

	p, err := plot.New()
	if err != nil {
		panic(err)
	}

	p.Title.Text = title
	p.X.Label.Text = xValuesLabel
	p.Y.Label.Text = yValuesLabel

	plotutil.AddLinePoints(p, plottingPointArgs...)
	plotutil.AddErrorBars(p, plottingErrorArgs...)

	savePlot(title, directory, p)
}