public LinearLeastSquares(Matrix a, Matrix b, Method method)
        {
            if (a == null || b == null)
                throw new ArgumentNullException();

            if (a.Rows != b.Rows)
                throw new ArgumentException();

            if (b.Columns != 1)
                throw new ArgumentException("b must be a vector!");

            this.n = a.Columns;
            if (method == Method.MGS)
                leastSquare = new MGS(a);
            else if (method == Method.Householder)
                leastSquare = new Householder(a);

            leastSquare.Orthogonalization();
            Console.WriteLine("Q");
            Console.WriteLine(leastSquare.GetQ().ToString(4));
            Console.WriteLine("R");
            Console.WriteLine(leastSquare.GetR().ToString(4));
            this.b = b;
            this.x = new Matrix(a.Columns, 1);
        }
Example #2
0
    public static void Main()
    {
        var    time        = new double[] { 1, 2, 3, 4, 6, 9, 10, 13, 15 };
        var    activity    = new double[] { 117, 100, 88, 72, 53, 29.5, 25.2, 15.2, 11.1 };
        vector timeVec     = new vector(time.Length);
        vector activityVec = new vector(activity.Length);
        vector dyVec       = new vector(activity.Length);
        var    fs          = new Func <double, double>[] { x => 1, x => x };

        for (int i = 0; i < activity.Length; i++)
        {
            timeVec[i]     = time[i];
            activityVec[i] = Math.Log(activity[i]);
            dyVec[i]       = activity[i] / 20;
        }
        var fitter = new LeastSquare();

        fitter.fit(fs, timeVec, activityVec, dyVec);
        var ExpData = new Data(time, activity);

        File.WriteAllLines("ExpData.txt", ExpData.X.Select((x, i) => $"{x} {ExpData.Y[i]} {dyVec[i]}"));
        File.WriteAllLines("Fit.txt", ExpData.X.Select((x, i) => $"{x} {func(x, Math.Exp(fitter.c[0]), fitter.c[1])}"));
        for (int i = 0; i < fitter.c.size; i++)
        {
            System.Console.WriteLine(fitter.c[i]);
        }
        fitter.S.print();
        System.Console.WriteLine("The half-life is : " + $"{-Math.Log(2)/fitter.c[1]}+-{Math.Abs(-Math.Log(2)/Math.Sqrt(fitter.S[1,1]))}");
    }
Example #3
0
    public void Start()
    {
        if (m_ResetHighscore)
        {
            PlayerPrefs.DeleteAll();
        }

        Helper.ResetRandomNumber(m_EvolutionaryRandomSeed);
        m_Population     = PopulationRandomInitialize();
        m_ResetCoroutine = ResetGame(false);
        StartCoroutine(m_ResetCoroutine);

        m_lSquare = new LeastSquare();
    }
Example #4
0
        private static void Main(string[] args)
        {
            var path2 = "/home/wyk/RiderProjects/HuberLossWithGrad/GradTest/hxjydq20200203.csv";
            //var b = new HuberLossSolver(args[0]);
            var b = new LeastSquare(args[0]);

            //var theta = b.VectorHuberLossSolver();
            b.LeastSquareSolver();

            //var r = Outliers.find(args[0], theta);

            /*foreach (var t in r)
             * {
             *  Console.WriteLine(t);
             * }*/

            //寻找离群点之后,可以将该点去除后进行再一次的回归
        }