Exemplo n.º 1
0
func (this *Scatter) Insert(x *matrix.DenseMatrix) {
	/*
		count++;
		Matrix delta = x.minus(mean);
		if (useSampleMean)
			mean = mean.plus(delta.times(1.0/count));
		scatter = scatter.plus(delta.times(x.minus(mean).transpose()));
	*/
	this.Count++
	delta, _ := x.MinusDense(this.Mean)
	deltaOverC := delta.Copy()
	deltaOverC.Scale(1 / float64(this.Count))
	this.Mean.Add(deltaOverC)
	xMinusMean, _ := x.MinusDense(this.Mean)
	xMinusMeanT := xMinusMean.Transpose()
	deltaTimesXMinusMeanT, _ := delta.TimesDense(xMinusMeanT)
	this.S.Add(deltaTimesXMinusMeanT)
}
Exemplo n.º 2
0
func (this *Scatter) Remove(x *matrix.DenseMatrix) {
	/*
	   int new_count = count-1;
	   Matrix new_mu = mean;
	   if (useSampleMean)
	   	new_mu = mean.plus(mean.minus(x).times(1.0/new_count));
	   scatter = scatter.minus((x.minus(new_mu)).times(x.minus(mean).transpose()));
	   count = new_count;
	   mean = new_mu;
	   if (count == 0) {
	   	if (useSampleMean)
	   		mean = new Matrix(p, 1, 0);
	       scatter = new Matrix(p, p, 0);
	   }
	*/
	newCount := this.Count - 1
	if newCount == 0 {
		p := this.S.Rows()
		this.S = matrix.Zeros(p, p)
		this.Mean = matrix.Zeros(p, 1)
		this.Count = newCount
		return
	}

	newMean, _ := this.Mean.MinusDense(x)
	newMean.Scale(1 / float64(newCount))
	newMean.Add(this.Mean)

	xMinusNewMean, _ := x.MinusDense(newMean)
	xMinusMean, _ := x.MinusDense(this.Mean)
	xMinusMeanT := xMinusMean.Transpose()
	xCross, _ := xMinusNewMean.TimesDense(xMinusMeanT)

	this.S.Subtract(xCross)

	this.Count = newCount
	this.Mean = newMean
}