Ejemplo n.º 1
0
Archivo: DFT.go Proyecto: eddytrex/AIgo
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
}
Ejemplo n.º 2
0
Archivo: ANN.go Proyecto: eddytrex/AIgo
//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
}
Ejemplo n.º 3
0
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
}
Ejemplo n.º 4
0
Archivo: DFT.go Proyecto: eddytrex/AIgo
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
}
Ejemplo n.º 5
0
Archivo: DFT.go Proyecto: eddytrex/AIgo
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
}