Exemple #1
0
func (w *Walker) SelectionProbability(Q_, R_, u_ *Sparse) (float64, error) {
	Q := Q_.Dense()
	R := R_.Dense()
	u := u_.Dense()
	I := matrix.Eye(Q.Rows())
	IQ, err := I.Minus(Q)
	if err != nil {
		return 0, err
	}
	N := matrix.Inverse(IQ)
	B, err := N.Times(R)
	if err != nil {
		return 0, err
	}
	P, err := u.Times(B)
	if err != nil {
		return 0, err
	}
	if P.Rows() != P.Cols() && P.Rows() != 1 {
		return 0, errors.Errorf("Unexpected P shape %v %v", P.Rows(), P.Cols())
	}
	x := P.Get(0, 0)
	if x > 1.0 || x != x {
		return 0, errors.Errorf("could not accurately compute p")
	}
	return x, nil
}
Exemple #2
0
func (sg *SubGraph) Walks(labels map[int]int) (W matrix.Matrix) {
	var err error
	L, E := sg.LE(labels)
	LT := matrix.Transpose(L)
	var En matrix.Matrix = matrix.Eye(E.Rows())
	var SEn matrix.Matrix = matrix.Zeros(E.Rows(), E.Cols())
	for i := 0; i < len(sg.V); i++ {
		En, err = En.Times(E)
		if err != nil {
			log.Fatal(err)
		}
		r, c := SEn.GetSize()
		for x := 0; x < r; x++ {
			for y := 0; y < c; y++ {
				if En.Get(x, y) != 0 {
					SEn.Set(x, y, 1)
				}
			}
		}
		// err = SEn.Add(En)
		// if err != nil {
		// 	log.Fatal(err)
		// }
	}
	LE, err := L.Times(SEn)
	if err != nil {
		log.Fatal(err)
	}
	LELT, err := LE.Times(LT)
	if err != nil {
		log.Fatal(err)
	}
	return LELT
}