Пример #1
0
func ratingStdDev(teams []Team) (Score, []float64) {
	teamRatingsStdDev := make([]float64, numTeams)
	for i, team := range teams {
		if len(team.players) < 2 {
			teamRatingsStdDev[i] = 0
			continue
		}
		playerRatings := make([]float64, len(team.players))
		for j, player := range team.players {
			playerRatings[j] = float64(player.rating)
		}
		teamRatingsStdDev[i] = stats.StatsSampleStandardDeviation(playerRatings)
	}
	return Score(stats.StatsSampleStandardDeviation(teamRatingsStdDev)), teamRatingsStdDev
}
Пример #2
0
func ratingDifference(teams []Team) (Score, []float64) {
	teamAverageRatings := make([]float64, numTeams)
	for i, team := range teams {
		teamAverageRatings[i] = float64(AverageRating(team))
	}
	return Score(stats.StatsSampleStandardDeviation(teamAverageRatings)), teamAverageRatings
}
Пример #3
0
func StandardDeviationInt(inList []int) float64 {
	floatList := make([]float64, len(inList))
	for i, value := range inList {
		floatList[i] = float64(value)
	}
	stdDev := stats.StatsSampleStandardDeviation(floatList)
	return stdDev
}
Пример #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("")
	}

}
Пример #5
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
		}
	}
}
Пример #6
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
}
Пример #7
0
	i := 1
	for i < len(data) {
		data[i].Return = data[i].Logprice - data[i-1].Logprice
		i += 1
	}
	j := 29
	for j < len(data) {
		subset := data[j-29 : j]
		var returns []float64
		for _, point := range subset {
			if !math.IsNaN(point.Return) {
				returns = append(returns, point.Return)
			}
		}
		data[j].Volatility = stats.StatsSampleStandardDeviation(returns) * 100.0
		j += 1
	}
	k := 59
	for k < len(data) {
		subset := data[k-59 : k]
		var returns []float64
		for _, point := range subset {
			if !math.IsNaN(point.Return) {
				returns = append(returns, point.Return)
			}
		}
		data[k].Volatility60 = stats.StatsSampleStandardDeviation(returns) * 100.0
		k += 1
	}
	d := StoredDataSet{
// 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
}