示例#1
0
文件: theory.go 项目: qtse/go_solve
func FormSystem(P []poly.Polynomial, param Param) []poly.Polynomial {
	system := make([]poly.Polynomial, param.N, param.N)
	system[0] = poly.NewConstant(-1, true).Copy()
	for _, p := range param.Polys[1:] {
		system[0].AddPoly(p)
	}

	for i := 1; i < param.N; i++ {
		system[1] = poly.AddPoly(P[i], poly.MultConst(param.Polys[i], -1))
	}

	return system
}
示例#2
0
文件: theory.go 项目: qtse/go_solve
func FormCondProbabilities(param Param) [][]poly.Polynomial {
	U := make([]float64, param.CW+1, param.CW+1)
	M := make([]float64, param.CW+1, param.CW+1)
	for i, _ := range U {
		U[i] = calcU(i, param.CW)
		M[i] = calcU(i, param.CW)
	}

	T := make([][]poly.Polynomial, param.CW+1, param.CW+1)

	for k := 0; k <= param.CW; k++ {
		T[k] = make([]poly.Polynomial, param.N+1, param.N+1)
		for will_tx := 0; will_tx <= param.N; will_tx++ {
			T[k][will_tx] = poly.NewConstant(0, true)
			for did_tx := 1; did_tx <= param.N; did_tx++ {
				did_not_tx := param.N - did_tx
				coeff := 0.

				for will_and_did_tx := 0; will_and_did_tx <= did_tx; will_and_did_tx++ {
					will_not_but_did_tx := did_tx - will_and_did_tx
					will_but_did_not_tx := will_tx - will_and_did_tx
					will_not_and_did_not_tx := did_not_tx - will_but_did_not_tx

					if will_but_did_not_tx < 0 {
						break
					} else if will_not_and_did_not_tx < 0 {
						continue
					}

					coeff += nchoosek(did_tx, will_and_did_tx) *
						math.Pow(U[k], float64(will_and_did_tx)) *
						math.Pow((1-U[k]), float64(will_not_but_did_tx)) *
						nchoosek(did_not_tx, will_but_did_not_tx) *
						math.Pow(M[k], float64(will_but_did_not_tx)) *
						math.Pow((1-M[k]), float64(will_not_and_did_not_tx))
				}
				tmp := poly.MultConst(param.Polys[did_tx], coeff)
				T[k][will_tx] = poly.AddPoly(T[k][will_tx], tmp)
			}
		}
	}
	return T
}