Ejemplo n.º 1
0
        public void VStackNDArrays()
        {
            //1D
            var np = new NumPyGeneric <double>();
            var n1 = np.array(new double[] { 1, 2, 3 });
            var n2 = np.array(new double[] { 2, 3, 4 });

            var n = np.vstack(n1, n2);

            Assert.IsTrue(n.Size == (n1.Size + n2.Size));
            Assert.IsTrue(n[0, 0] == 1);
            Assert.IsTrue(n[1, 0] == 2);
            Assert.IsTrue(n[1, 2] == 4);

            //2D
            n1 = np.array(new double[][] { new double[] { 1 }, new double[] { 2 }, new double[] { 3 } });
            n2 = np.array(new double[][] { new double[] { 4 }, new double[] { 5 }, new double[] { 6 } });

            n = np.vstack(n1, n2);

            Assert.IsTrue(n.Size == (n1.Size + n2.Size));
            Assert.IsTrue(n[0, 0] == 1);
            Assert.IsTrue(n[1, 0] == 2);
            Assert.IsTrue(n[2, 0] == 3);
            Assert.IsTrue(n[3, 0] == 4);
            Assert.IsTrue(n[4, 0] == 5);
            Assert.IsTrue(n[5, 0] == 6);
        }
Ejemplo n.º 2
0
        public void LinearRegression()
        {
            var np = new NumPyGeneric <double>();

            // the time array
            var time = np.linspace(0, 10, 1000);

            // the values over t - linear dependence with noice
            var values = time * 3 + 5 + np.random.randn(time.Data.Length);

            var A     = np.vstack(np.ones(new Shape(1000)), time);
            var A_T   = A.transpose();
            var A_T_A = A_T.dot(A);

            var A_PseudoInv = A.transpose().dot(A).inv();

            var param = A_PseudoInv.dot(A.transpose());

            //param = param.dot(param);
        }