Exemple #1
0
func main() {
	if len(os.Args) != 2 {
		panic("You must give exactly one argument.")
	}
	outDir := os.Args[1]
	tempTable := table.NewOutTable(tempColNames...)
	yTable := table.NewOutTable(yColNames...)
	fGasTable := table.NewOutTable(fGasColNames...)

	minMassLog, maxMassLog := math.Log10(1e13), math.Log10(1e15)
	logWidth := (maxMassLog - minMassLog) / steps

	for massLog := minMassLog; massLog <= maxMassLog; massLog += logWidth {
		bMass := math.Pow(10, massLog)

		h := halo.New(fTh, ppt, cFunc, halo.Biased, bMass, z)

		bTemp := h.EWTemperature(halo.Biased, bpbt, ppt, h.R500cBias)
		cTemp := h.EWTemperature(halo.Corrected, cpbt, ppt, h.C500.R)
		tempTable.AddRow(bMass, h.C500.M, bTemp, cTemp, cTemp/bTemp)

		bY := h.ThompsonY(bpbt, ppt, h.R500cBias)
		cY := h.ThompsonY(cpbt, ppt, h.C500.R)
		yTable.AddRow(bMass, h.C500.M, bY, cY, cY/bY)

		bFGas := fGas(h, halo.Biased)
		cFGas := fGas(h, halo.Corrected)
		fGasTable.AddRow(bMass, h.C500.M, bFGas, cFGas, cFGas/bFGas)
	}

	tempTable.Write(table.KeepHeader, path.Join(outDir, "mass-temp.table"))
	yTable.Write(table.KeepHeader, path.Join(outDir, "mass-y.table"))
	fGasTable.Write(table.KeepHeader, path.Join(outDir, "mass-fgas.table"))
}
Exemple #2
0
func test(mod int, fn string) {
	input := []float64{}
	output := []float64{}
	for i := 0.1; i < 50; i = i + 0.05 {
		errCnt := 0
		for j := 0; j < 10; j++ {
			dc := hammingcode.NewDecoder(mod)
			in := genCode(i)
			dc.Accept(in)
			res := dc.ProcessMess()
			if chkErr([]int{0, 0, 0, 0, 0, 0, 0}, res) {
				errCnt += 1
			}
		}
		input = append(input, i)
		output = append(output, float64(errCnt+1)/(7*10))
	}

	f, err := os.Create(fn)

	if err != nil {
		panic(err)
	}
	defer f.Close()
	for i, _ := range input {
		fmt.Fprintf(f, "%f \t %f\n", math.Log10(input[i]), math.Log10(output[i]))
	}
}
Exemple #3
0
func DBtoMIDI(db float64) uint8 {
	db = db - 6.0
	p := math.Pow(10.0, (db / 20.0))
	plog := math.Log10(p*14.5+1.0) / math.Log10(15.5)
	plog *= 127.0
	return uint8(round(plog))
}
Exemple #4
0
// MMI calculates the maximum Modificed Mercalli Intensity for the quake.
func (q *Quake) MMI() float64 {
	if q.err != nil {
		return -1. - 0
	}

	var w, m float64
	d := math.Abs(q.Depth)
	rupture := d

	if d < 100 {
		w = math.Min(0.5*math.Pow(10, q.Magnitude-5.39), 30.0)
		rupture = math.Max(d-0.5*w*0.85, 0.0)
	}

	if d < 70.0 {
		m = 4.40 + 1.26*q.Magnitude - 3.67*math.Log10(rupture*rupture*rupture+1634.691752)/3.0 + 0.012*d + 0.409
	} else {
		m = 3.76 + 1.48*q.Magnitude - 3.50*math.Log10(rupture*rupture*rupture)/3.0 + 0.0031*d
	}

	if m < 3.0 {
		m = -1.0
	}

	return m
}
Exemple #5
0
func main() {
	if len(os.Args) != 2 {
		panic("You must give exactly one argument.")
	}
	outDir := os.Args[1]
	outTable := table.NewOutTable(colNames...)

	fGas := func(h *halo.Halo, bt halo.BiasType, pbt halo.PressureBiasType) float64 {
		if bt != halo.Biased {
			return h.GasEnclosed(bt, pbt, valPpt, h.C500.R) /
				h.MassEnclosed(bt, h.C500.R)
		} else {
			return h.GasEnclosed(bt, pbt, valPpt, h.R500cBias) /
				h.MassEnclosed(bt, h.R500cBias)
		}
	}

	minMassLog, maxMassLog := math.Log10(1e13), math.Log10(1e15)
	logWidth := (maxMassLog - minMassLog) / steps

	for massLog := minMassLog; massLog <= maxMassLog; massLog += logWidth {
		mass := math.Pow(10, massLog)

		h := halo.New(fTh, simPpt, cFunc0, halo.Corrected, mass, 0.0)

		fGasCorrected := fGas(h, halo.Corrected, halo.EffectivePressure)
		fGasNaive := fGas(h, halo.Corrected, halo.NaiveThermalPressure)
		outTable.AddRow(mass, h.M500cBias, fGasCorrected, fGasNaive,
			fGasCorrected*mass, fGasNaive*h.M500cBias)
	}

	outTable.Write(table.KeepHeader, path.Join(outDir, "mass-fgas.table"))
}
func main() {
	if len(os.Args) != 2 {
		panic("You must give exactly one argument.")
	}
	outDir := os.Args[1]
	outTable := table.NewOutTable(colNames...)

	minMassLog, maxMassLog := math.Log10(1e13), math.Log10(1e15)
	logWidth := (maxMassLog - minMassLog) / steps

	for massLog := minMassLog; massLog <= maxMassLog; massLog += logWidth {
		mass := math.Pow(10, massLog)
		
		h := halo.New(fTh, simPpt, cFunc0, halo.Corrected, mass, 0.0)

		mGas500Corrected := h.GasEnclosed(halo.Biased,
			halo.EffectivePressure, valPpt, h.C500.R)
		mGas500ThCorrected := h.GasEnclosed(halo.Biased,
			halo.EffectivePressure, valPpt, h.R500cBias)
		mGas500ThNaive := h.GasEnclosed(halo.Biased,
			halo.ThermalPressure, valPpt, h.R500cBias)

		outTable.AddRow(mass, h.M500cBias, mGas500Corrected,
			mGas500ThCorrected, mGas500ThNaive)
	}

	outTable.Write(table.KeepHeader, path.Join(outDir, "plot-type-comp.table"))
}
Exemple #7
0
func buildbodyword(candword string, fproba mfloat, tproba mmfloat, score float64, n int) (string, bool) {
	/* This function calls the word building sequence. */
	var ll byte
	if score < 0.0 {
		/* The word is not probable enough, let's abort */
		return "", false
	}
	if n == 0 {
		/* No more letters, let's check if the end transition is plausible */
		ll = candword[len(candword)-1]
		if score+10*math.Log10(fproba[ll]) > 0.0 {
			/* Yes, the candidate is plausible */
			return candword, true
		} else {
			/* Unfortunately, no */
			return "", false
		}
	}
	/* We are in the middle of the word */
	ll = candword[len(candword)-1]
	for l, p := range tproba[ll] {
		/* For each possible letter in the transition, let's try the transition until
		   we find something that works.
		*/
		nextcandword := candword + string(l)
		trycandword, worked := buildbodyword(nextcandword, fproba, tproba, score+10*math.Log10(p),
			n-1)
		if worked {
			/* This word works */
			return trycandword, true
		}
	}
	/* If we are here, no transition worked correctly. */
	return "", false
}
Exemple #8
0
// CountDigits return number of digits in integer
func CountDigits(i int) int {
	if i < 0 {
		return int(math.Log10(math.Abs(float64(i)))) + 2
	}

	return int(math.Log10(float64(i))) + 1
}
func main() {
	if len(os.Args) != 2 {
		panic("Must provite a target directory.")
	}

	outDir := os.Args[1]
	outTable := table.NewOutTable(colNames...)

	minMassLog, maxMassLog := math.Log10(1e13), math.Log10(1e15)
	logWidth := (maxMassLog - minMassLog) / steps

	for massLog := minMassLog; massLog <= maxMassLog; massLog += logWidth {
		mass := math.Pow(10, massLog)
		h := halo.New(fTh, simPpt, cFunc, halo.Biased, mass, 0.0)

		outTable.AddRow(mass,
			h.C500.M/h.M500cBias,
			1.0/h.FThermal(h.C500.R),
			1.0/h.FThermal(h.R500cBias),
			h.BFrac(h.C500.R),
			h.BFrac(h.R500cBias))
	}

	outTable.Write(table.KeepHeader, path.Join(outDir, "mass-false-bias.table"))
}
Exemple #10
0
func main() {
	br := bufio.NewReader(os.Stdin)

	line, err := br.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	dna := strings.TrimSpace(line)

	line, err = br.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	for _, f := range strings.Fields(line) {
		gc, _ := strconv.ParseFloat(f, 64)
		lgc := math.Log10(gc / 2)
		lat := math.Log10((1 - gc) / 2)
		lp := float64(0)
		for i := 0; i < len(dna); i++ {
			switch dna[i] {
			case 'A', 'T':
				lp += lat
			case 'G', 'C':
				lp += lgc
			}
		}
		fmt.Print(lp, " ")
	}
	fmt.Println()
}
Exemple #11
0
func main() {
	if len(os.Args) != 2 {
		panic("Must provite a target directory.")
	}

	outDir := os.Args[1]
	outTable := table.NewOutTable(colNames...)

	minMassLog, maxMassLog := math.Log10(1e13), math.Log10(1e15)
	logWidth := (maxMassLog - minMassLog) / steps

	for massLog := minMassLog; massLog <= maxMassLog; massLog += logWidth {
		mass := math.Pow(10, massLog)

		h0 := halo.New(fTh, simPpt, cFunc0, halo.Biased, mass, 0.0)
		h0p := halo.New(fThP, simPpt, cFunc0, halo.Biased, mass, 0.0)
		h0m := halo.New(fThM, simPpt, cFunc0, halo.Biased, mass, 0.0)

		h2 := halo.New(fTh, simPpt, cFunc2, halo.Biased, mass, 0.2)
		h2p := halo.New(fThP, simPpt, cFunc2, halo.Biased, mass, 0.2)
		h2m := halo.New(fThM, simPpt, cFunc2, halo.Biased, mass, 0.2)

		outTable.AddRow(mass,
			h0.C500.M/h0.M500cBias,
			h0p.C500.M/h0p.M500cBias,
			h0m.C500.M/h0m.M500cBias,
			h2.C500.M/h2.M500cBias,
			h2p.C500.M/h2p.M500cBias,
			h2m.C500.M/h2m.M500cBias)
	}

	outTable.Write(table.KeepHeader, path.Join(outDir, "mass-bias.table"))
}
Exemple #12
0
// apply logarithmic transformation to amounts and number of transactions to normalize
// will more closely resemble a normal distribution so we can take z-scores
// aggregate a sum, then divide by total count to find means
// return as a struct of means
func getMeans(id mongoDBConfig.BrandId) (mean ZscoreData) {
	collections := mongoDBConfig.NewDBConn()
	visitorsCollection := collections.C("visitors")
	result := visitorsCollection.
		Find(bson.M{
			"brandid":       id,               // for which brand in our db are we computing z-scores
			"summaries.amt": bson.M{"$gt": 0}, // don't include $0 transactions
		}).
		Select(bson.M{
			"summaries.amt": 1,
			"summaries.trn": 1}).
		//Limit(100).
		Iter()

	visitor := Visitor{}
	count := 0
	// mgo next() will iterate through the dataset and unmarshal into vistor struct
	for result.Next(&visitor) {
		count += 1

		amt := visitor.Summaries.Amount
		amt = math.Log10(amt)
		mean.Amt += amt

		trn := float64(visitor.Summaries.NumberOfTransactions)
		trn = math.Log10(trn)
		mean.Trn += trn
	}

	mean.Amt = mean.Amt / float64(count)
	mean.Trn = mean.Trn / float64(count)
	return
}
Exemple #13
0
func main() {
	if len(os.Args) != 2 {
		panic("You must give exactly one argument.")
	}
	outDir := os.Args[1]
	outTable := table.NewOutTable(colNames...)

	minMassLog, maxMassLog := math.Log10(1e13), math.Log10(1e15)
	logWidth := (maxMassLog - minMassLog) / steps

	for massLog := minMassLog; massLog <= maxMassLog; massLog += logWidth {
		mass := math.Pow(10, massLog)

		h0 := halo.New(fTh, simPpt, cFunc0, halo.Biased, mass, 0.0)
		h0p := halo.New(fThP, simPpt, cFunc0, halo.Biased, mass, 0.0)
		h0m := halo.New(fThM, simPpt, cFunc0, halo.Biased, mass, 0.0)

		h5 := halo.New(fTh, simPpt, cFunc5, halo.Biased, mass, 0.5)
		h5p := halo.New(fThP, simPpt, cFunc5, halo.Biased, mass, 0.5)
		h5m := halo.New(fThM, simPpt, cFunc5, halo.Biased, mass, 0.5)

		outTable.AddRow(mass,
			h0.EWTemperature(tempBt, valPpt, h5p.C500.R),
			h0p.EWTemperature(tempBt, valPpt, h0p.C500.R),
			h0m.EWTemperature(tempBt, valPpt, h0m.C500.R),
			h5.EWTemperature(tempBt, valPpt, h5p.C500.R),
			h5p.EWTemperature(tempBt, valPpt, h5p.C500.R),
			h5m.EWTemperature(tempBt, valPpt, h5m.C500.R))
	}

	outTable.Write(table.KeepHeader, path.Join(outDir, "mass-temp.table"))
}
Exemple #14
0
/*
Translate pixel coordinates to actual coordinates
Needed: reference points for lower left conor and upper right conor
*/
func TranslatePixelCoordinate(linear bool, startEndValues []float64, startEndPixels []float64, pixelsIn []float64) (actualCoordinates []float64) {

	actualCoordinates = make([]float64, 0)
	transCoordinate := 0.0

	for _, pixelValue := range pixelsIn {

		if linear {

			transCoordinate = (pixelValue-startEndPixels[0])*(startEndValues[1]-startEndValues[0])/
				(startEndPixels[1]-startEndPixels[0]) + startEndValues[0]

		} else { //logrithmic

			//their powers are linear
			coordinateRatio := (pixelValue-startEndPixels[0])*(math.Log10(startEndValues[1])-math.Log10(startEndValues[0]))/
				(startEndPixels[1]-startEndPixels[0]) + math.Log10(startEndValues[0])

			transCoordinate = math.Pow(10, coordinateRatio)

		}

		actualCoordinates = append(actualCoordinates, transCoordinate)
	}

	return
}
Exemple #15
0
// if halfSize, m1 has to be 2*m2
func compareImages(m1, m2 image.Image, halfSize bool) results {
	b := m2.Bounds()
	s := b.Size()
	res := results{}
	mse := uint32(0)
	for y := b.Min.Y; y < b.Max.Y; y++ {
		for x := b.Min.X; x < b.Max.X; x++ {
			var r1, g1, b1, a1 uint32
			if halfSize {
				r1, g1, b1, a1 = m1.At(x*2, y*2).RGBA()
			} else {
				r1, g1, b1, a1 = m1.At(x, y).RGBA()
			}
			r2, g2, b2, a2 := m2.At(x, y).RGBA()
			mse += ((r1-r2)*(r1-r2) + (g1-g2)*(g1-g2) + (b1-b2)*(b1-b2)) / 3
			if r1 != r2 || g1 != g2 || b1 != b2 || a1 != a2 {
				if res.diffIm == nil {
					res.diffIm = image.NewGray(m1.Bounds())
				}
				res.diffCnt++
				res.diffIm.Set(x, y, color.White)
			}
		}
	}
	mse = mse / uint32(s.X*s.Y)
	res.psnr = 20*math.Log10(1<<16) - 10*math.Log10(float64(mse))
	return res
}
Exemple #16
0
// divide one prefix by another
// take care: there are no checks for going out of bounds
// e.g. Z/z will give an error!
func PrefixDiv(x string, y string) string {
	// divide x by y, what do you get?

	l1 := RoundInt(math.Log10(prefices[x].Value))
	l2 := RoundInt(math.Log10(prefices[y].Value))
	return ReverseLookupPrefix(l1 - l2)
}
Exemple #17
0
func tryN(maxN uint64) (total, sum uint64) {
	//maxF := math.Pow10(n)
	ls := NewLs()
	total = 0
	sum = 0

	maxF := float64(maxN)
	ln := int(math.Log10(maxF)) + 1
	rec := make([]bool, ln)
	for i, _ := range rec {
		rec[i] = false
	}

	marked := uint64(0)
	markStep := uint64(2000000000)
	ten := uint64(10)

	for i := uint64(11); i <= maxN; i += 2 {
		if i >= marked {
			marked += markStep
			ls.Mark(marked)
		}
		if ls.Get(i) {
			continue
		}

		ln := int(math.Log10(float64(i)))
		if ln > 1 && !rec[ln-1] {
			fmt.Println("strange ", ln)
			break
		}
		if ln > 0 {
			isOk := true

			for tmp := i / ten; tmp > uint64(0); tmp /= ten {
				if ls.Get(tmp) {
					isOk = false
					break
				}
			}
			if isOk {
				for base := uint64(math.Pow10(ln)); base >= ten; base /= ten {
					if ls.Get(i % base) {
						isOk = false
						break
					}
				}
			}
			rec[ln] = true
			if isOk {
				total++
				fmt.Println("got one ", i)
				sum += i
			}
		}

	}
	return total, sum
}
Exemple #18
0
//-------------------------------------------------------------------------------------------------
// AlignCostVarLoci calculates cost of alignment between a read and the reference at known loci.
//-------------------------------------------------------------------------------------------------
func AlignCostVarLoci(read, ref, qual []byte, prob float64) float64 {
	//do not consider qual at this time
	if string(read) == string(ref) {
		return -0.1 * math.Log10(prob)
	} else {
		return -float64(len(ref)) * math.Log10(INDEL_ERR_RATE)
	}
}
func addNormalisedAndOverall(parent *ShareAccountEntry, child *ShareAccountEntry) {
	//	fmt.Printf("addNormalisedAndOverall: child %v parent %v\n", child.UserGroupName, parent.UserGroupName)
	child.NormalisedShares = float64(child.Shares) / float64(parent.ChildrenSharesSum)
	child.OverallNormalisedShares = float64(child.NormalisedShares) * parent.OverallNormalisedShares
	child.OverallPriority = float64(child.Priority) * parent.OverallPriority
	child.OverallPriorityLog = math.Log10(float64(child.Priority)) + parent.OverallPriorityLog
	child.PriorityLog = math.Log10(float64(child.Priority))
}
Exemple #20
0
// multiply two prefix values
// take care: there are no checks for going out of bounds
// e.g. Z*Z will generate an error!
func PrefixMul(x string, y string) string {
	//multiply x by y, what do you get?

	l1 := RoundInt(math.Log10(prefices[x].Value))
	l2 := RoundInt(math.Log10(prefices[y].Value))

	return ReverseLookupPrefix(l1 + l2)
}
Exemple #21
0
func main() {
	if len(os.Args) != 2 {
		panic("You must give exactly one argument.")
	}
	outDir := os.Args[1]

	alphaTable := table.NewOutTable(alphaNames...)
	betaTable := table.NewOutTable(betaNames...)
	fthTable := table.NewOutTable(fthNames...)
	biasTable := table.NewOutTable(biasNames...)

	cFunc0 := halo.ConcentrationFunc(halo.Bhattacharya2013, 0)
	cFunc5 := halo.ConcentrationFunc(halo.Bhattacharya2013, 0.5)

	h014 := halo.New(fTh, simPpt, cFunc0, halo.Corrected, 1e14, 0)
	h015 := halo.New(fTh, simPpt, cFunc0, halo.Corrected, 5e14, 0)
	h214 := halo.New(fTh, simPpt, cFunc5, halo.Corrected, 1e14, 0.2)
	h215 := halo.New(fTh, simPpt, cFunc5, halo.Corrected, 5e14, 0.2)

	minFracLog, maxFracLog := math.Log10(0.01), math.Log10(10)
	logWidth := (maxFracLog - minFracLog) / steps
	for fracLog := minFracLog; fracLog <= maxFracLog; fracLog += logWidth {
		frac := math.Pow(10, fracLog)
		r014 := h014.C500.R * frac
		r015 := h015.C500.R * frac
		r214 := h214.C500.R * frac
		r215 := h215.C500.R * frac

		alphaTable.AddRow(frac,
			h014.AlphaBias(r014),
			h015.AlphaBias(r015),
			h214.AlphaBias(r214),
			h215.AlphaBias(r215))

		betaTable.AddRow(frac,
			h014.BetaBias(r014),
			h015.BetaBias(r015),
			h214.BetaBias(r214),
			h215.BetaBias(r215))

		fthTable.AddRow(frac,
			h014.FThermal(r014),
			h015.FThermal(r015),
			h214.FThermal(r214),
			h215.FThermal(r215))

		biasTable.AddRow(frac,
			h014.BFrac(r014),
			h015.BFrac(r015),
			h214.BFrac(r214),
			h215.BFrac(r215))
	}

	alphaTable.Write(table.KeepHeader, path.Join(outDir, "radial-alpha.table"))
	betaTable.Write(table.KeepHeader, path.Join(outDir, "radial-beta.table"))
	fthTable.Write(table.KeepHeader, path.Join(outDir, "radial-fth.table"))
	biasTable.Write(table.KeepHeader, path.Join(outDir, "radial-bias.table"))
}
Exemple #22
0
func calc_fan_speed(temp float64) float64 {
	switch g_opt_mode {
	case mode_Default:
		return math.Log10(temp/40.0) / 0.3 * g_max_fan_speed //quiet but not so cool
	case mode_Aggressive:
		return math.Log10(temp/30.0) / 0.35 * g_max_fan_speed //cooler but also louder
	}
	return g_min_fan_speed
}
Exemple #23
0
// IntegralArray is equivelent to Integral, but returns an array of the
// the x values of the intermediate steps and the value of the integral
// at those points.
func IntegralArray(f Func1D, xStart, scale float64, st ScaleType, dt DomainType) Func1DArray {
	var g Func1D
	switch dt {
	case Spherical:
		g = func(x float64) float64 { return f(x) * x * x * 4.0 * math.Pi }
	case Flat:
		g = func(x float64) float64 { return f(x) }
	}

	if st == Log {
		xStart = math.Log10(xStart)
	}
	dx := scale / 100.0

	return func(xEnd float64) (xs, ys []float64) {
		var width, signedDx float64
		if st == Log {
			xEnd = math.Log10(xEnd)
		}

		if xStart == xEnd {
			return []float64{0.0}, []float64{0.0}
		} else if xStart < xEnd {
			width = xEnd - xStart
			signedDx = dx
		} else {
			width = xStart - xEnd
			signedDx = -dx
		}

		fullSteps := int(math.Floor(width / dx))

		xs = make([]float64, fullSteps+2)
		ys = make([]float64, fullSteps+2)

		xs[0] = xStart
		ys[0] = 0.0

		xs[1] = xStart + (signedDx / 2.0)
		ys[1] = integrateBlock(g, xs[1], signedDx, st)

		for i := 1; i < fullSteps; i++ {
			xs[i+1] = xs[i] + signedDx
			ys[i+1] += ys[i] + integrateBlock(g, xs[i+1], signedDx, st)
		}

		x := xs[fullSteps]
		xs[fullSteps+1] = xEnd
		ys[fullSteps+1] = (ys[fullSteps] +
			integrateBlock(g, x+(xEnd-x)/2.0, xEnd-x, st))

		return xs, ys
	}
}
Exemple #24
0
func humanBytes(bytes uint64) string {
	// Using SI units (1000 not 1024)
	if bytes < 1000 {
		return fmt.Sprintf("%v B", bytes)
	}
	size := float64(bytes)
	exp := int(math.Log10(size) / math.Log10(1000))
	prefix := "kMGTPE"[exp-1]
	result := size / math.Pow(1000, float64(exp))
	return fmt.Sprintf("%.2f %cB", result, prefix)
}
Exemple #25
0
func (h *Halo) EWTemperature(xct XRayCorrectionType, ppt PressureProfileType, rMax float64) float64 {
	rMin := h.MinR()
	scale := math.Log10(rMin) - math.Log10(rMin)

	numFunc := createNumFunc(h, xct, ppt)
	numInt := num.Integral(numFunc, rMin, scale, num.Log, num.Spherical)

	denFunc := createDenFunc(h, xct, ppt)
	denInt := num.Integral(denFunc, rMin, scale, num.Log, num.Spherical)

	return numInt(rMax) / denInt(rMax)
}
func writeFairShare(jsonout io.Writer, queue *string) error {
	//	fmt.Println("Getting queue info...")
	qi, err := LsbQueueInfo(queue)
	if err != nil {
		return err
	}

	timestamp := time.Now().Format(time.RFC3339)

	fairshareQueueStr := C.GoString(qi.info_entry.fairshareQueues)
	noqueues, matcherr := regexp.MatchString("^[[:space:]]*$", fairshareQueueStr)
	if matcherr != nil {
		return matcherr
	}
	if noqueues {
		fairshareQueueStr = fmt.Sprintf("%s", *queue)
	}

	fairshareQueues := strings.Split(fairshareQueueStr, " ")

	//	shareAccountCount := qi.info_entry.numOfSAccts

	shareAccounts, err := LsbShareAccounts(qi)
	if err != nil {
		return err
	}
	//	fmt.Printf("Have share account info: %+v\n", shareAccounts)

	// set root node normalised shares and overall shares
	shareAccounts.NormalisedShares = 1.0
	shareAccounts.OverallNormalisedShares = 1.0
	shareAccounts.OverallPriority = 1.0
	shareAccounts.OverallPriorityLog = math.Log10(1.0)
	shareAccounts.PriorityLog = math.Log10(1.0)

	// descend through the tree and calculate normalised shares
	// and overall shares and priority
	traverseAccountChildren(shareAccounts, addNormalisedAndOverall)

	var output = make(map[string]interface{})
	output["queues"] = fairshareQueues
	output["shares"] = shareAccounts
	output["timestamp"] = timestamp

	enc := json.NewEncoder(jsonout)
	err = enc.Encode(output)
	if err != nil {
		fmt.Println(err)
		return err
	}

	return err
}
Exemple #27
0
/* Takes a list of qury terms and scores the document for this query. */
func (index *Index) score(query []string, docs DocList) float64 {
	for doc, _ := range docs {
		score := 0.0
		for _, term := range query {
			fmt.Println(term)
			invDocFreq := float64(index.stat.numDocs) / float64(len(index.reverseIndex[term]))
			termFreq := float64(len(index.reverseIndex[term][doc]))
			score += (1 + math.Log10(termFreq)) * math.Log10(invDocFreq)
		}
	}

	return 0.0
}
Exemple #28
0
func main() {
	fmt.Println("Running...")
	start := time.Now()

	ev = make([]float64, 0)

	for n := nmin; n <= nmax; n *= 2 {
		sum := 0.0
		dx := (xmax - xmin) / float64(n)
		dy := (ymax - ymin) / float64(n)
		y = make([]float64, n)
		x = make([]float64, n)
		for k := 0; k < n; k++ {
			x[k] = float64(k)*dx + 0.5*dx + xmin
			y[k] = (float64(k)*dy + 0.5*dy + ymin)
		}
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				sum += math.Exp(x[i]*y[j]) * dx * dy
			}
		}
		ev = append(ev, EXACT_VALUE-sum)
	}

	var pt plotter.XYs
	pt = make(plotter.XYs, len(ev))
	for i := range pt {
		pt[i].X = math.Log10(float64(nmin) * math.Pow(2, float64(i)))
		pt[i].Y = math.Log10(math.Abs(ev[i]))
	}

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

	p.Title.Text = fmt.Sprintf("Error of Midpoint Integral")
	p.X.Label.Text = "n"
	p.Y.Label.Text = "Log(|err|)"

	plotutil.AddLinePoints(p, pt)

	// Save the plot to a PNG file.
	if err := p.Save(6, 4, "error_hw12.png"); err != nil {
		panic(err)
	}

	fmt.Println(time.Since(start))
	fmt.Println("...program terminated successfully!")
}
Exemple #29
0
//-5.737 -5.217 -5.263 -5.360 -5.958 -6.628 -7.009
func randomStrings(s string, gcContent []float64) (probs []float64) {
	probs = make([]float64, len(gcContent))
	for i, gc := range gcContent {
		for _, l := range s {
			if l == 'C' || l == 'G' {
				probs[i] += math.Log10(gc / 2)
			} else {
				probs[i] += math.Log10((1 - gc) / 2)
			}
		}
		probs[i] = util.Round(probs[i], 3)
	}
	return probs
}
Exemple #30
0
func prob1(dna string, cg_ratio float64) float64 {
	res := 0.0
	lcg, lat := math.Log10(cg_ratio/2), math.Log10((1.0-cg_ratio)/2)

	for i := range dna {
		if dna[i] == 'C' || dna[i] == 'G' {
			res += lcg
		} else {
			res += lat
		}
	}

	return res
}