Example #1
0
        // *** IDisposable interface implementation ***

        public void Dispose()
        {
            if (mId >= 0)
            {
                LSqrDll.DeleteMatrix(mId);
                mId = -1;
            }
        }
Example #2
0
        public void Train(ILabeledExampleCollection <double, SparseVector <double> > dataset)
        {
            Utils.ThrowException(dataset == null ? new ArgumentNullException("dataset") : null);
            Utils.ThrowException(dataset.Count == 0 ? new ArgumentValueException("dataset") : null);
            LSqrSparseMatrix mat = new LSqrSparseMatrix(dataset.Count);

            double[] rhs     = new double[dataset.Count];
            int      solSize = -1;
            int      i       = 0;

            foreach (LabeledExample <double, SparseVector <double> > labeledExample in dataset)
            {
                if (labeledExample.Example.LastNonEmptyIndex + 1 > solSize)
                {
                    solSize = labeledExample.Example.LastNonEmptyIndex + 1;
                }
                foreach (IdxDat <double> item in labeledExample.Example)
                {
                    mat.InsertValue(i, item.Idx, item.Dat);
                }
                rhs[i++] = labeledExample.Label;
            }
            Utils.ThrowException((mInitSol != null && mInitSol.Length != solSize) ? new ArgumentValueException("InitialSolution") : null);
            LSqrSparseMatrix matT = new LSqrSparseMatrix(solSize);

            i = 0;
            foreach (LabeledExample <double, SparseVector <double> > labeledExample in dataset)
            {
                foreach (IdxDat <double> item in labeledExample.Example)
                {
                    matT.InsertValue(item.Idx, i, item.Dat);
                }
                i++;
            }
            int numIter = mNumIter < 0 ? solSize + dataset.Count + 50 : mNumIter;

            mSol = new ArrayList <double>(LSqrDll.DoLSqr(solSize, mat, matT, mInitSol, rhs, numIter));
            mat.Dispose();
            matT.Dispose();
        }
Example #3
0
        public void Train(IExampleCollection <double, SparseVector <double> .ReadOnly> dataset)
        {
            Utils.ThrowException(dataset == null ? new ArgumentNullException("dataset") : null);
            Utils.ThrowException(dataset.Count == 0 ? new ArgumentValueException("dataset") : null);
            LSqrSparseMatrix mat = new LSqrSparseMatrix(dataset.Count);

            double[] rhs      = new double[dataset.Count];
            int      sol_size = -1;
            int      i        = 0;

            foreach (LabeledExample <double, SparseVector <double> .ReadOnly> labeled_example in dataset)
            {
                if (labeled_example.Example.LastNonEmptyIndex + 1 > sol_size)
                {
                    sol_size = labeled_example.Example.LastNonEmptyIndex + 1;
                }
                foreach (IdxDat <double> item in labeled_example.Example)
                {
                    mat.InsertValue(i, item.Idx, item.Dat);
                }
                rhs[i++] = labeled_example.Label;
            }
            LSqrSparseMatrix mat_t = new LSqrSparseMatrix(sol_size);

            i = 0;
            foreach (LabeledExample <double, SparseVector <double> .ReadOnly> labeled_example in dataset)
            {
                foreach (IdxDat <double> item in labeled_example.Example)
                {
                    mat_t.InsertValue(item.Idx, i, item.Dat);
                }
                i++;
            }
            int num_iter = m_num_iter < 0 ? sol_size + dataset.Count + 50 : m_num_iter;

            m_sol = new ArrayList <double>(LSqrDll.DoLSqr(sol_size, mat, mat_t, rhs, num_iter));
            mat.Dispose();
            mat_t.Dispose();
        }
Example #4
0
 public void InsertValue(int rowIdx, int colIdx, double val)
 {
     LSqrDll.InsertValue(mId, rowIdx, colIdx, val);
 }
Example #5
0
 public LSqrSparseMatrix(int rowCount)
 {
     mId = LSqrDll.NewMatrix(rowCount);
 }
Example #6
0
 public void InsertValue(int row_idx, int col_idx, double val)
 {
     LSqrDll.InsertValue(m_id, row_idx, col_idx, val);
 }
Example #7
0
 public LSqrSparseMatrix(int row_count)
 {
     m_id = LSqrDll.NewMatrix(row_count);
 }