当前位置: 首页>>代码示例>>Golang>>正文


Golang Matrix.Matrix类代码示例

本文整理汇总了Golang中Matrix.Matrix的典型用法代码示例。如果您正苦于以下问题:Golang Matrix类的具体用法?Golang Matrix怎么用?Golang Matrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Matrix类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Variance_sum

func (this *TrainingSet) Variance_sum(i0, i1 int, mean *Matrix.Matrix, res **Matrix.Matrix, sustract *Matrix.Matrix, done chan<- bool) {
	di := i1 - i0

	if di >= THRESHOLD {
		mi := i0 + di/2
		done2 := make(chan bool, THRESHOLD)

		res1 := Matrix.NullMatrixP(1, this.Xs.GetNColumns())
		res2 := Matrix.NullMatrixP(1, this.Xs.GetNColumns())

		go this.Variance_sum(i0, mi, mean, &res1, sustract, done2)
		go this.Variance_sum(mi, i1, mean, &res1, sustract, done2)

		<-done2
		<-done2

		SP, _ := Matrix.Sum(res1, res2)
		*res = SP

	} else {
		for i := i0; i <= i1; i++ {
			xsi := this.Xs.GetRow(i)
			Sustract, _ := Matrix.Sustract(mean, xsi)
			Square := Matrix.DotMultiplication(Sustract, Sustract)

			sustract.SetRow(i, Sustract)

			SP, _ := Matrix.Sum(Square, *res)
			*res = SP
		}
	}
	done <- true
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:33,代码来源:TrainningSet.go

示例2: FFT_ct

func FFT_ct(this *Matrix.Matrix, N, skip int, tf *[]complex128) *Matrix.Matrix {

	Xr := Matrix.NullMatrixP(N, this.GetNColumns())
	RowTemp := Matrix.NullMatrixP(1, this.GetNColumns())

	FFT_aux(this, Xr, RowTemp, N, skip, tf)
	return Xr
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:8,代码来源:DFT.go

示例3: MakeTrainingSet

func MakeTrainingSet(xs *Matrix.Matrix, y *Matrix.Matrix) *TrainingSet {
	var out TrainingSet

	if xs.GetMRows() == y.GetMRows() {
		out.Xs = xs
		out.Y = y
		return &out
	}
	return nil
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:10,代码来源:TrainningSet.go

示例4: FFT

func FFT(this *Matrix.Matrix, N int) (*Matrix.Matrix, error) {
	if N > this.GetMRows() {
		return nil, errors.New(" The number of Rows of the matrix (this) must be greater or equal than N ")
	}
	if N&(N-1) == 0 {
		tf := TwiddleFactors(N, false)

		Xr := FFT_ct3(this, N, 1, &tf)

		return Xr, nil
	}
	return nil, errors.New(" The N parameter has to be power of 2")
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:13,代码来源:DFT.go

示例5: IFFT

func IFFT(this *Matrix.Matrix, N int) (*Matrix.Matrix, error) {
	if N > this.GetMRows() {
		return nil, errors.New(" The number of Rows of the matrix (this) must be greater or equal than N ")
	}
	if N&(N-1) == 0 {
		tf := TwiddleFactors(N, true)

		Xr := FFT_ct(this, N, 1, &tf)

		Xr = Xr.Scalar(complex(float64(1)/float64(N), 0))
		return Xr, nil
	}
	return nil, errors.New(" The N parameter has to be power of 2")
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:14,代码来源:DFT.go

示例6: DSoftmax

func DSoftmax(X *Matrix.Matrix) *Matrix.Matrix {
	Total := 1 / X.TaxicabNorm()
	Y := X.Scalar(complex(Total, 0))

	S, _ := Matrix.Sustract(Matrix.FixValueMatrix(X.GetNColumns(), X.GetNColumns(), 1.0), X)

	YD := Matrix.DotMultiplication(Y, S)
	return YD
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:9,代码来源:ActivationFunctions.go

示例7: part_DiffH1Ys

func (this *Hypothesis) part_DiffH1Ys(i0, i1 int, Ts *TrainingSet, Ret *Matrix.Matrix, RetT *Matrix.Matrix, done chan<- bool) {
	di := i1 - i0

	if di >= THRESHOLD && runtime.NumGoroutine() < maxGoRoutines {
		done2 := make(chan bool, THRESHOLD)

		mi := i0 + di/2
		go this.part_DiffH1Ys(i0, mi, Ts, Ret, RetT, done2)
		go this.part_DiffH1Ys(mi, i1, Ts, Ret, RetT, done2)
		<-done2
		<-done2
	} else {
		for i := i0; i <= i1; i++ {
			xi := Ts.Xs.GetRow(i)

			Thi := Matrix.Product(xi, this.ThetaParameters.Transpose())
			temp := this.H(Thi.GetValue(1, 1)) - Ts.Y.GetValue(1, i)
			Ret.SetValue(i, 1, temp)
			RetT.SetValue(1, i, temp)
		}
	}
	done <- true
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:23,代码来源:MachineLearning.go

示例8: ForwardPropagation

//TODO the activation function and his Derviate has to be more general.. to implemente soft-max for example
func (this *ANN) ForwardPropagation(In *Matrix.Matrix) (As, AsDerviate *([]*Matrix.Matrix), Output *Matrix.Matrix) {
	if In.GetMRows() == this.Inputs && In.GetNColumns() == 1 {
		As1 := make([]*Matrix.Matrix, len(this.Weights)+1, len(this.Weights)+1)
		AsDerviate1 := make([]*Matrix.Matrix, len(this.Weights)+1, len(this.Weights)+1)

		As := &As1
		AsDerviate = &AsDerviate1

		sTemp := In.Transpose()

		//Add  a new column for a Bias Weight
		sTemp = sTemp.AddColumn(Matrix.I(1))

		holeInput := sTemp.Copy()
		As1[0] = sTemp.Transpose()

		//Derivate
		//sutract, _ := Matrix.Sustract(Matrix.OnesMatrix(As1[0].GetMRows(), 1), As1[0])
		//derivate := Matrix.DotMultiplication(As1[0], sutract)

		//derivate := holeInput.Apply(this.Derivate)
		derivate := this.DarivateActivationLayer(holeInput)

		AsDerviate1[0] = derivate.Transpose()

		for i := 0; i < len(this.Weights); i++ {
			sTemp = Matrix.Product(sTemp, (this.Weights[i]))

			//apply the activation functions
			holeInput := sTemp.Copy()
			sTemp = this.ActivationLayer(sTemp)

			//sTemp = sTemp.Apply(this.Activation)

			//Add  a new column for a Bias Weight
			sTemp = sTemp.AddColumn(Matrix.I(1))
			(*As)[i+1] = sTemp.Transpose()

			//Derivate
			//sutract, _ := Matrix.Sustract(Matrix.OnesMatrix((*As)[i+1].GetMRows(), 1), (*As)[i+1])
			//derivate := Matrix.DotMultiplication((*As)[i+1], sutract)

			derivate := this.DarivateActivationLayer(holeInput)
			//derivate := holeInput.Apply(this.Derivate)

			(*AsDerviate)[i+1] = derivate.Transpose()

		}
		Asf := sTemp.Copy()

		//Asf = Asf.AddColumn(Matrix.I(1))
		(*As)[len(As1)-1] = Asf.Transpose()
		Output = sTemp.Transpose().MatrixWithoutLastRow()
		return As, AsDerviate, Output
	}
	return nil, nil, nil
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:58,代码来源:ANN.go

示例9: CorssEntorpy

func CorssEntorpy(T, O *Matrix.Matrix) *Matrix.Matrix {
	log := func(x complex128) complex128 { return cmplx.Log(x) }
	return Matrix.DotMultiplication(T, O.Apply(log))

}
开发者ID:eddytrex,项目名称:AIgo,代码行数:5,代码来源:CostFunctions.go

示例10: FFT_ct2

func FFT_ct2(this *Matrix.Matrix, N, skip int, tf *[]complex128) *Matrix.Matrix {

	Xr := Matrix.NullMatrixP(N, this.GetNColumns())
	Scratch := Matrix.NullMatrixP(N, this.GetNColumns())

	var E, D, Xp, Xstart *Matrix.Matrix
	var evenIteration bool

	if N%2 == 0 {
		evenIteration = true
	} else {
		evenIteration = false
	}

	if N == 1 {
		Xr.SetRow(1, this.GetReferenceRow(1))
	}

	E = this

	for n := 1; n < N; n *= 2 {

		if evenIteration {
			Xstart = Scratch
		} else {
			Xstart = Xr
		}

		skip := N / (2 * n)
		Xp = Xstart

		for k := 0; k != n; k++ {
			for m := 0; m != skip; m++ {
				D = E.MatrixWithoutFirstRows(skip)
				D.ScalarRow(1, (*tf)[skip*k])

				sr, rr, _ := Matrix.Sum_Sustract(E.GetReferenceRow(1), D.GetReferenceRow(1))

				Xp.SetRow(1, sr)
				Xp.SetRow(N/2+1, rr)

				Xp = Xp.MatrixWithoutFirstRows(1)
				E = E.MatrixWithoutFirstRows(1)
			}
			E = E.MatrixWithoutFirstRows(skip)
		}
		E = Xstart
		evenIteration = !evenIteration
	}
	return Scratch
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:51,代码来源:DFT.go

示例11: FFT_aux

func FFT_aux(this, xr, RowTemp *Matrix.Matrix, N, skip int, tf *[]complex128) {

	if N == 1 {
		xr.SetRow(1, this.GetReferenceRow(1))
		return
	}

	FFT_aux(this, xr, RowTemp, N/2, skip*2, tf)
	FFT_aux(this.MatrixWithoutFirstRows(skip), xr.MatrixWithoutFirstRows(N/2), RowTemp, N/2, skip*2, tf)

	for k := 0; k < N/2; k++ {

		xr.ScalarRowIntoRowMatrix(RowTemp, k+1+N/2, (*tf)[k*skip])

		sr, rr, _ := Matrix.Sum_Sustract(xr.GetReferenceRow(k+1), RowTemp)

		xr.SetRow(k+1, sr)
		xr.SetRow(k+1+N/2, rr)

	}
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:21,代码来源:DFT.go

示例12: FFT_ct3

func FFT_ct3(this *Matrix.Matrix, N, skip int, tf *[]complex128) *Matrix.Matrix {

	Xr := Matrix.NullMatrixP(N, this.GetNColumns())
	Scratch := Matrix.NullMatrixP(N, this.GetNColumns())

	var E, D, Xp, Xstart *Matrix.Matrix
	var evenIteration bool

	if N%2 == 0 {
		evenIteration = true
	} else {
		evenIteration = false
	}

	if N == 1 {
		Xr.SetRow(1, this.GetReferenceRow(1))
	}

	E = this

	for n := 1; n < N; n *= 2 {

		if evenIteration {
			Xstart = Scratch
		} else {
			Xstart = Xr
		}

		skip := N / (2 * n)
		Xp = Xstart

		for k := 0; k != n; k++ {

			var Aux = func(m0, m1 int, Xp, E, D *Matrix.Matrix) {

				println("-", m0)
				Xp = Xp.MatrixWithoutFirstRows(m0)
				E = E.MatrixWithoutFirstRows(m0)
				//D = E.MatrixWithoutFirstRows(skip)

				for m := m0; m < m1; m++ {
					D = E.MatrixWithoutFirstRows(skip)
					D.ScalarRow(1, (*tf)[skip*k])

					sr, rr, _ := Matrix.Sum_Sustract(E.GetReferenceRow(1), D.GetReferenceRow(1))

					Xp.SetRow(1, sr)
					Xp.SetRow(N/2+1, rr)

					Xp = Xp.MatrixWithoutFirstRows(1)

					println("E", E.ToString())
					E = E.MatrixWithoutFirstRows(1)

				}

			}

			mm := skip / 2
			m0 := 0
			//m1 := skip

			go Aux(m0, mm, Xp, E, D)
			//println("->E", E.ToString(), ">XP", Xp.ToString())
			//go Aux(mm, m1, Xp, E, D)

			//for m := 0; m != skip; m++ {
			//	D = E.MatrixWithoutFirstRows(skip)
			//	D.ScalarRow(1, (*tf)[skip*k])

			//	sr, rr, _ := Matrix.Sum_Sustract(E.GetReferenceRow(1), D.GetReferenceRow(1))

			//	Xp.SetRow(1, sr)
			//	Xp.SetRow(N/2+1, rr)

			//	Xp = Xp.MatrixWithoutFirstRows(1)
			//	E = E.MatrixWithoutFirstRows(1)
			//}
			E = E.MatrixWithoutFirstRows(skip)

		}
		E = Xstart
		evenIteration = !evenIteration
	}
	return Scratch
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:86,代码来源:DFT.go

示例13: Softmax

func Softmax(X *Matrix.Matrix) *Matrix.Matrix {
	Total := 1 / X.TaxicabNorm()
	Y := X.Scalar(complex(Total, 0))

	return Y
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:6,代码来源:ActivationFunctions.go

示例14: DSigmoidLayer

func DSigmoidLayer(X *Matrix.Matrix) *Matrix.Matrix {
	return X.Apply(DSigmoid)
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:3,代码来源:ActivationFunctions.go


注:本文中的Matrix.Matrix类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。