public TransformWhiteningOld(IAlgebraLinear <MatrixType> algebra, float [,] data) { AMatrix <MatrixType> data_matrix = algebra.Create(data); means = algebra.Create(ToolsMathStatistics.Means1(data)); AMatrix <MatrixType> covariance_matrix = data_matrix * data_matrix.Transpose(); matrix_backward = covariance_matrix.Algebra.ComputeRoot(covariance_matrix); matrix_forward = matrix_backward.Invert(); }
public static void TestMatrixMatrixProduct0 <MatrixType>(IAlgebraLinear <MatrixType> algebra) { AMatrix <MatrixType> A = algebra.Create(new double[, ] { { 1, 0 }, { 0, 1 } }); AMatrix <MatrixType> B = algebra.Create(new double[, ] { { 1, 2 }, { 3, 4 } }); AMatrix <MatrixType> C = A * B; Assert.AreEqual(1, C.GetElement(0, 0)); Assert.AreEqual(2, C.GetElement(0, 1)); Assert.AreEqual(3, C.GetElement(1, 0)); Assert.AreEqual(4, C.GetElement(1, 1)); }
public static void TestAddMany <MatrixType>(IAlgebraLinear <MatrixType> algebra) { AMatrix <MatrixType> A = algebra.Create(new double[, ] { { 1, 2 }, { 3, 4 } }); AMatrix <MatrixType> B = algebra.Create(new double[, ] { { 1, 2 }, { 3, 4 } }); AMatrix <MatrixType> C = A + B; Assert.AreEqual(2, C.GetElement(0, 0)); Assert.AreEqual(4, C.GetElement(0, 1)); Assert.AreEqual(6, C.GetElement(1, 0)); Assert.AreEqual(8, C.GetElement(1, 1)); }
public double[] TransformForward(double[] source) { AMatrix <MatrixType> vector = algebra.Create(source, false); AMatrix <MatrixType> result = vector * projection; return(result.ToArray1DFloat64()); }
public ITransform GenerateTransform(IDataSet <double> data_set) { AMatrix <MatrixType> data = algebra.Create(ToolsCollection.ConvertToArray2D(data_set.FeatureData)); SVD <MatrixType> svd = algebra.ComputeSVD(data); AMatrix <MatrixType> projection = svd.VT.Transpose().GetColumns(0, destination_dimension_count); return(new DimensionReductionPCA <MatrixType>(data_set.DataContext, projection)); }
public static void TestAddOne <MatrixType>(IAlgebraLinear <MatrixType> algebra) { AMatrix <MatrixType> A = algebra.Create(new double[, ] { { 1, 2 }, { 3, 4 } }); AMatrix <MatrixType> B = A + 1; Assert.AreEqual(2, B.GetElement(0, 0)); Assert.AreEqual(3, B.GetElement(0, 1)); Assert.AreEqual(4, B.GetElement(1, 0)); Assert.AreEqual(5, B.GetElement(1, 1)); }
public RendererPoints(IAlgebraLinear <MatrixType> algebra, int bitmap_size_x, int bitmap_size_y, AngleRadian pitch, AngleRadian yaw, double[] offset, double scale) { this.bitmap_size_x = bitmap_size_x; this.bitmap_size_y = bitmap_size_y; this.scale = scale; this.offset_matrix = algebra.Create(offset); //float [] vector_view = new float[3]; // unit vector in the direction we view, 0,0 is from the top the regular way, should produce [0 0 0] //(0,0 should procux x = [1 0 0], y = [0 1 0]) //isometric projection //http://www.wolframalpha.com/input/?i=%7B%7B1%2C+0+%2C0%7D%2C%7B0%2C+cos%28a%29%2C+sin%28a%29%7D%2C%7B0%2C+-sin%28a%29%2C+cos%28a%29%7D%7D.%7B%7Bcos%28b%29%2C+0%2C+-sin%28b%29%7D%2C%7B0%2C1%2C0%7D%2C%7Bsin%28b%29%2C+0+%2C+cos%28b%29%7D%7D double a = (double)pitch; double b = (double)yaw; double[,] projection_array = new double[, ] { { Math.Cos(b), Math.Sin(a) * Math.Sin(b), Math.Cos(a) * Math.Sin(b) }, { 0, Math.Cos(a), -Math.Sin(a) }, { -Math.Sin(b), Math.Sin(a) * Math.Cos(b), Math.Cos(a) * Math.Cos(b) } }; projection_matrix = algebra.Create(projection_array); }
//AMatrix<MatrixType> forward_matrix_flipped; public DeconvolutionRichardsonLucy(IAlgebraLinear <MatrixType> algebra, ITemplateBasisFunction template, IFunction <double, double> input_function, double[] signal_sample_times) { this.algebra = algebra; this.basis_function_list = new List <IFunction <double, double> >(); double[,] forward_array = new double[signal_sample_times.Length, signal_sample_times.Length]; for (int column_index = 0; column_index < signal_sample_times.Length; column_index++) { IFunction <double, double> basis_function = template.Generate(input_function, signal_sample_times, column_index); basis_function_list.Add(basis_function); for (int row_index = 0; row_index < signal_sample_times.Length; row_index++) { forward_array[row_index, column_index] = basis_function.Compute(signal_sample_times[row_index]); } } forward_matrix = algebra.Create(forward_array); }
private Tuple <AMatrix <MatrixDataType>, AMatrix <MatrixDataType> > Orthogonalise(AMatrix <MatrixDataType> V, AMatrix <MatrixDataType> w, List <int> REPEATED, double kappa = 0) { // w=[V, v]* h; with v such that v'*V=0; // // kappa=0: classical Gram-Schmidt // kappa>0: repeated Gram-Schmidt with DGKS stopping criterion // repeat if tan(angle)<kappa // kappa<0: modified Gram-Schmidt // // global REPEATED int n = V.RowCount; int k = V.ColumnCount; AMatrix <MatrixDataType> v = null; AMatrix <MatrixDataType> h = null; if (k >= V.RowCount) { kappa = 0.0; } if (k == 0) { h = algebra.Create(w.L2Norm()); v = this.simple_solver.Solve(w, h); REPEATED = new List <int>(); return(new Tuple <AMatrix <MatrixDataType>, AMatrix <MatrixDataType> >(v, h)); } double zero = k * k * n * w.L2Norm() * double.Epsilon; // numerical zero double rho = 0; double mu = 0; v = w; if (kappa < 0)//modified Gram-Schmidt { h = algebra.CreateZeros(k, 1); for (int j = 0; j < k; j++) { double value = (V.GetColumn(j).Transpose() * v).GetElement(); h.SetElement(j, 0, value); v = v - V.GetColumn(j) * value; } rho = v.L2Norm(); } else // repeated Gram-Schmidt { h = V.Transpose() * v; v = v - V * h; rho = v.L2Norm(); mu = h.L2Norm(); int t = 0; // Daniel Gragg Kaufman Stewart update criterion // if kappa==0, classical Gram-Schmidt while (rho <kappa *mu& rho> zero) { AMatrix <MatrixDataType> g = V.Transpose() * v; v = v - V * g; rho = v.L2Norm(); mu = g.L2Norm(); h = h + g; t = t + 1; } REPEATED[V.ColumnCount] = t; } if (rho < 2 * zero) { // if full dimension then no expansion if (k >= n) { v = this.algebra.CreateZeros(n, 0); return(new Tuple <AMatrix <MatrixDataType>, AMatrix <MatrixDataType> >(v, h)); } // if W in span(V) expand with random vector Tuple <AMatrix <MatrixDataType>, AMatrix <MatrixDataType> > tuple = Orthogonalise(V, this.algebra.CreateRandomUnit(n, 1), REPEATED, kappa); v = tuple.Item1; h = h.AppendRow(0); } else { h = h.AppendRow(rho); v = v / rho; } return(new Tuple <AMatrix <MatrixDataType>, AMatrix <MatrixDataType> >(v, h)); }
public IFunction <double, double> GetIRF(double[] signal) { AMatrix <MatrixType> weights = solver.Solve(forward_matrix, algebra.Create(signal, true)); return(new FunctionWeigthed <double, double>(new AlgebraRealFloat64(), basis_function_list, weights.ToArray1DFloat64())); }