Exemplo n.º 1
0
func NewStat(data []float64) Stat {
	return Stat{
		Min:    stats.StatsMin(data),
		Max:    stats.StatsMax(data),
		Mean:   stats.StatsMean(data),
		StdDev: stats.StatsPopulationStandardDeviation(data),
		Total:  stats.StatsSum(data),
	}
}
Exemplo n.º 2
0
func Stats(H []Estudiante) {
	in := make([]float64, len(H))

	for i := 0; i < len(H); i++ {
		in[i] = H[i].Renta + H[i].Beca
	}
	log.Println("StdDev", stats.StatsPopulationStandardDeviation(in))
	log.Println("Mean", stats.StatsMean(in))
}
Exemplo n.º 3
0
func (r *Report) DistributionScore() float64 {
	memoryCounts := []float64{}
	for _, instances := range r.InstancesByRep {
		memoryCount := 0.0
		for _, instance := range instances {
			memoryCount += float64(instance.MemoryMB)
		}
		memoryCounts = append(memoryCounts, memoryCount)
	}

	return stats.StatsPopulationStandardDeviation(memoryCounts) / stats.StatsMean(memoryCounts)
}
Exemplo n.º 4
0
func main() {

	var header bool

	flag.BoolVar(&header, "t", false, "Print text header")
	flag.Parse()

	file := ""
	if len(flag.Args()) > 0 {
		file = flag.Args()[0]
	}

	m, vars, err := ltspice.Raw(file, header)

	if err != nil {
		log.Println(err)
	}

	if m == nil {
		log.Println("null matrix")
	}

	col := len(m)
	row := len(m[0])

	if header {
		for j := 1; j < col; j++ {

			mean := stats.StatsMean(m[j])
			sdev := stats.StatsSampleStandardDeviation(m[j])

			fmt.Printf("%-20s %30g %30g %30g\n", "'"+vars[j]+"'", mean, sdev, sdev/mean)
		}
	}

	if header {
		return
	}

	for i := 0; i < row; i++ {
		for j := 0; j < col; j++ {
			fmt.Printf("%g", m[j][i])
			if j < col-1 {
				fmt.Print(", ")
			}
		}
		fmt.Println("")
	}

}
Exemplo n.º 5
0
func calculateTotalResults(results []*RunResults, totalTime time.Duration) *TotalResults {
	totals := new(TotalResults)
	totals.TotalRunTime = totalTime.Seconds()

	msgTimeMeans := make([]float64, len(results))
	msgsPerSecs := make([]float64, len(results))
	runTimes := make([]float64, len(results))
	bws := make([]float64, len(results))

	totals.MsgTimeMin = results[0].MsgTimeMin
	for i, res := range results {
		totals.Successes += res.Successes
		totals.Failures += res.Failures
		totals.TotalMsgsPerSec += res.MsgsPerSec

		if res.MsgTimeMin < totals.MsgTimeMin {
			totals.MsgTimeMin = res.MsgTimeMin
		}

		if res.MsgTimeMax > totals.MsgTimeMax {
			totals.MsgTimeMax = res.MsgTimeMax
		}

		msgTimeMeans[i] = res.MsgTimeMean
		msgsPerSecs[i] = res.MsgsPerSec
		runTimes[i] = res.RunTime
		bws[i] = res.MsgsPerSec
	}
	totals.Ratio = float64(totals.Successes) / float64(totals.Successes+totals.Failures)
	totals.AvgMsgsPerSec = stats.StatsMean(msgsPerSecs)
	totals.AvgRunTime = stats.StatsMean(runTimes)
	totals.MsgTimeMeanAvg = stats.StatsMean(msgTimeMeans)
	totals.MsgTimeMeanStd = stats.StatsSampleStandardDeviation(msgTimeMeans)

	return totals
}
Exemplo n.º 6
0
func (r *Report) InitialDistributionScore() float64 {
	memoryCounts := []float64{}
	for _, instances := range r.InstancesByRep {
		memoryCount := 0.0
		for _, instance := range instances {
			if !r.IsAuctionedInstance(instance) {
				memoryCount += float64(instance.MemoryMB)
			}
		}
		memoryCounts = append(memoryCounts, memoryCount)
	}

	if stats.StatsSum(memoryCounts) == 0 {
		return 0
	}

	return stats.StatsPopulationStandardDeviation(memoryCounts) / stats.StatsMean(memoryCounts)
}
Exemplo n.º 7
0
func (c *Client) Run(res chan *RunResults) {
	newMsgs := make(chan *Message)
	pubMsgs := make(chan *Message)
	doneGen := make(chan bool)
	donePub := make(chan bool)
	runResults := new(RunResults)

	started := time.Now()
	// start generator
	go c.genMessages(newMsgs, doneGen)
	// start publisher
	go c.pubMessages(newMsgs, pubMsgs, doneGen, donePub)

	runResults.ID = c.ID
	times := []float64{}
	for {
		select {
		case m := <-pubMsgs:
			if m.Error {
				log.Printf("CLIENT %v ERROR publishing message: %v: at %v\n", c.ID, m.Topic, m.Sent.Unix())
				runResults.Failures++
			} else {
				// log.Printf("Message published: %v: sent: %v delivered: %v flight time: %v\n", m.Topic, m.Sent, m.Delivered, m.Delivered.Sub(m.Sent))
				runResults.Successes++
				times = append(times, m.Delivered.Sub(m.Sent).Seconds()*1000) // in milliseconds
			}
		case <-donePub:
			// calculate results
			duration := time.Now().Sub(started)
			runResults.MsgTimeMin = stats.StatsMin(times)
			runResults.MsgTimeMax = stats.StatsMax(times)
			runResults.MsgTimeMean = stats.StatsMean(times)
			runResults.MsgTimeStd = stats.StatsSampleStandardDeviation(times)
			runResults.RunTime = duration.Seconds()
			runResults.MsgsPerSec = float64(runResults.Successes) / duration.Seconds()

			// report results and exit
			res <- runResults
			return
		}
	}
}
// summarizeResults Summarizes results / generates descriptive statistics so we
// don't have to send tens of thousands of trials down to the client.
// Receiver: None
// Params: detailedData -- [][]simulationTimeStep)
// Returns: []summarizedTimeStep
func summarizeResults(detailedData [][]simulationTimeStep) []summarizedTimeStep {
	numberOfTrials := len(detailedData)
	numberOfPeriods := len(detailedData[0])

	// Prep the slice
	summarizedResults := make([]summarizedTimeStep, numberOfPeriods)

	for period := 0; period < numberOfPeriods; period++ {

		outOfMoneyOccurences := 0.0                // initialize value
		dateInt := detailedData[0][period].dateInt // same in every trial

		/* 	Transpose the arrays so that we have a list of asset/income/expense
		results by period, instead of by trial. */

		periodAssetResults := make([]float64, numberOfTrials)
		periodIncomeResults := make([]float64, numberOfTrials)
		periodExpensesResults := make([]float64, numberOfTrials)

		for trialIndex, arrayOfTrialResults := range detailedData {
			periodAssetResults[trialIndex] = arrayOfTrialResults[period].assets
			periodIncomeResults[trialIndex] = arrayOfTrialResults[period].income
			periodExpensesResults[trialIndex] = arrayOfTrialResults[period].expenses

			if arrayOfTrialResults[period].assets < 0 {
				outOfMoneyOccurences++
			}
		}

		/* */

		/* Generate descriptive statistics for each period */

		outOfMoneyPercentage := outOfMoneyOccurences / float64(numberOfTrials)

		assetsMean := goStats.StatsMean(periodAssetResults)
		assetsStdDev := goStats.StatsSampleStandardDeviation(periodAssetResults)
		assetsCIFactor := 1.96 * assetsStdDev / math.Pow(float64(numberOfTrials), 0.5)

		incomeMean := goStats.StatsMean(periodIncomeResults)
		incomeStdDev := goStats.StatsSampleStandardDeviation(periodIncomeResults)
		incomeCIFactor := 1.96 * incomeStdDev / math.Pow(float64(numberOfTrials), 0.5)

		expensesMean := goStats.StatsMean(periodExpensesResults)
		expensesStdDev := goStats.StatsSampleStandardDeviation(periodExpensesResults)
		expensesCIFactor := 1.96 * expensesStdDev / math.Pow(float64(numberOfTrials), 0.5)

		/* */

		// // Remove asset results where all dead? Old code -- would need fixing
		// allDead := false
		// for index, entry := range meanIncome {
		// 	if entry == 0 || meanExpenses[index] == 0 {
		// 		allDead = true
		// 	}
		// 	if allDead {
		// 		meanAssets[index] = 0
		// 	}
		// }

		summarizedResults[period] = summarizedTimeStep{
			AssetsMean:   assetsMean,
			AssetsCILow:  assetsMean - assetsCIFactor,
			AssetsCIHigh: assetsMean + assetsCIFactor,

			IncomeMean:   incomeMean,
			IncomeCILow:  incomeMean - incomeCIFactor,
			IncomeCIHigh: incomeMean + incomeCIFactor,

			ExpensesMean:   expensesMean,
			ExpensesCILow:  expensesMean - expensesCIFactor,
			ExpensesCIHigh: expensesMean + expensesCIFactor,

			OutOfMoneyPercentage: outOfMoneyPercentage,
			DateInt:              dateInt,
		}
	}

	return summarizedResults
}