Esempio n. 1
0
        /// <summary>
        /// Generate SQL code to alter table
        /// </summary>
        /// <param name="table">Table object</param>
        /// <param name="columnAction">Alteration kind</param>
        /// <param name="field">Field object</param>
        /// <returns>SQL code</returns>
        public override string AlterTableColumnSQL(InTable table, ColumnAction columnAction, InField field)
        {

            string code = "ALTER TABLE " + AsFieldName(table.Name);
            switch (columnAction)
            {
                case ColumnAction.Remove:
                    code += " DROP COLUMN " + AsFieldName(field.Name);
                    break;

                case ColumnAction.Recreate:
                    code += " DROP COLUMN " + AsFieldName(field.Name);
                    code += ", ";
                    code += " ADD COLUMN " + AsFieldName(field.Name) + " " + GetSqlType(field);
                    break;

                case ColumnAction.Insert:
                    code += " ADD COLUMN " + AsFieldName(field.Name) + " " + GetSqlType(field);
                    break;

                case ColumnAction.ChangeType:
                    code += " ALTER COLUMN " + AsFieldName(field.Name) + " TYPE " + GetSqlType(field);
                    break;

                default: code = null;
                    break;
            }
            return code;
        }
Esempio n. 2
0
        public string addConstantGroupField()
        {
            string            outNm = "gr";
            IObjectClassInfo2 ocI2  = (IObjectClassInfo2)InTable;

            if (!ocI2.CanBypassEditSession())
            {
                System.Windows.Forms.MessageBox.Show("Input table has a composition relationship. Please export data and try again!");
            }
            else
            {
                outNm = geoUtil.createField(InTable, outNm, esriFieldType.esriFieldTypeString, false);
                IQueryFilter qf = new QueryFilterClass();
                qf.SubFields = outNm;
                ICursor cur     = InTable.Update(qf, false);
                int     flIndex = cur.FindField(outNm);
                IRow    rw      = cur.NextRow();
                while (rw != null)
                {
                    rw.set_Value(flIndex, "1");
                    cur.UpdateRow(rw);
                    rw = cur.NextRow();
                }
            }
            return(outNm);
        }
Esempio n. 3
0
        public override double[,] getMatrix()
        {
            if (unVlDic == null)
            {
                unVlDic = UniqueClassValues;
            }
            List <string> aVlLst = new List <string>();

            foreach (KeyValuePair <string, List <string> > kvp in unVlDic)
            {
                List <string> vlLst = kvp.Value;
                aVlLst.AddRange(vlLst);
            }
            labels = aVlLst.Distinct().ToList();
            double[] weights = new double[labels.Count];
            mctable = new int[2, 2];
            g1table = new int[labels.Count, labels.Count];
            g2table = new int[labels.Count, labels.Count];
            g3table = new int[labels.Count, labels.Count];
            ICursor cur      = InTable.Search(null, false);
            int     refIndex = cur.FindField(DependentFieldNames[0]);
            int     m1Index  = cur.FindField(IndependentFieldNames[0]);
            int     m2index  = cur.FindField(IndependentFieldNames[1]);
            //Console.WriteLine(wIndex.ToString());
            IRow rw = cur.NextRow();

            while (rw != null)
            {
                string rVl   = rw.get_Value(refIndex).ToString();
                string m1Vl  = rw.get_Value(m1Index).ToString();
                string m2Vl  = rw.get_Value(m2index).ToString();
                string rVll  = rVl.ToLower();
                string m1Vll = m1Vl.ToLower();
                string m2Vll = m2Vl.ToLower();
                int    mClm  = 0;
                int    mRws  = 0;
                if (rVll != m1Vll && rVll != m2Vll)
                {
                    mClm = 1;
                    mRws = 1;
                }
                else if (rVll == m1Vll && rVll != m2Vll)
                {
                    mClm = 0;
                    mRws = 1;
                }
                else if (rVll != m1Vll && rVll == m2Vll)
                {
                    mClm = 1;
                    mRws = 0;
                }
                mctable[mClm, mRws] += 1;
                g1table[labels.IndexOf(rVl), labels.IndexOf(m1Vl)]  += 1;
                g2table[labels.IndexOf(rVl), labels.IndexOf(m2Vl)]  += 1;
                g3table[labels.IndexOf(m1Vl), labels.IndexOf(m2Vl)] += 1;
                rw = cur.NextRow();
            }
            return(null);
        }
Esempio n. 4
0
        public ActionResult Create(FormCollection collection)//新增
        {
            var model = new InTable();

            this.TryUpdateModel <InTable>(model);

            this.ToolManageService.SaveInTable(model);

            return(this.RefreshParent());
        }
Esempio n. 5
0
        public ActionResult Create(FormCollection formCollection)
        {
            var Data = new InTable();

            this.TryUpdateModel(Data);
            Data.WarehousingDate = DateTime.Now;
            Data.Workcell        = LoginInfo.Workcell;
            ToolManageService.SaveInTable(Data);
            return(RedirectToAction("Index"));
        }
Esempio n. 6
0
        private Dictionary <string, List <string> > getUniqueClassValues()
        {
            Dictionary <string, List <string> > outDic = new Dictionary <string, List <string> >();

            if (ClassFieldNames == null || ClassFieldNames.Length == 0)
            {
                return(outDic);
            }
            string cFldn1 = ClassFieldNames[0];

            if (cFldn1 == "")
            {
                return(outDic);
            }
            IQueryFilter qf = new QueryFilterClass();

            if (generalQf != null)
            {
                qf.WhereClause = generalQf.WhereClause;
            }
            qf.SubFields = String.Join(",", ClassFieldNames);
            HashSet <string>[] hshStrgLst = new HashSet <string> [ClassFieldNames.Length];
            //Console.WriteLine("HashStrgLstLength = " + hshStrgLst.Length);
            int[]   fldIndexArr = new int[ClassFieldNames.Length];
            ICursor cur         = InTable.Search(qf, true);

            for (int i = 0; i < ClassFieldNames.Length; i++)
            {
                fldIndexArr[i] = cur.FindField(ClassFieldNames[i]);
                hshStrgLst[i]  = new HashSet <string>();
            }
            IRow rw = cur.NextRow();

            while (rw != null)
            {
                for (int i = 0; i < fldIndexArr.Length; i++)
                {
                    int    indVl = fldIndexArr[i];
                    string vl    = rw.get_Value(indVl).ToString();
                    //Console.WriteLine(vl);
                    //Console.WriteLine(indVl.ToString());
                    hshStrgLst[i].Add(vl);
                }
                rw = cur.NextRow();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);

            for (int i = 0; i < ClassFieldNames.Length; i++)
            {
                outDic.Add(ClassFieldNames[i], hshStrgLst[i].ToList());
            }
            return(outDic);
        }
Esempio n. 7
0
        public override double[,] getMatrix()
        {
            if (unVlDic == null)
            {
                unVlDic = UniqueClassValues;
            }
            List <string> aVlLst = new List <string>();

            foreach (KeyValuePair <string, List <string> > kvp in unVlDic)
            {
                List <string> vlLst = kvp.Value;
                aVlLst.AddRange(vlLst);
            }
            labels = aVlLst.Distinct().ToList();
            double[] weights = new double[labels.Count];
            int      clms    = labels.Count();
            int      rws     = clms;

            xtable = new int[clms, rws];
            ICursor cur      = InTable.Search(null, false);
            int     depIndex = cur.FindField(DependentFieldNames[0]);
            int     indIndex = cur.FindField(IndependentFieldNames[0]);
            int     wIndex   = -1;

            if (weightfld != "")
            {
                wIndex = cur.FindField(weightfld);
            }
            //Console.WriteLine(wIndex.ToString());
            IRow rw = cur.NextRow();

            while (rw != null)
            {
                string dVl = rw.get_Value(depIndex).ToString();
                string iVl = rw.get_Value(indIndex).ToString();
                double w   = 1;
                if (wIndex != -1)
                {
                    w = System.Convert.ToDouble(rw.get_Value(wIndex));
                }
                int mClm = labels.IndexOf(iVl);
                int mRws = labels.IndexOf(dVl);
                weights[mClm]       = w;
                xtable[mClm, mRws] += 1;
                rw = cur.NextRow();
            }
            //Console.WriteLine(String.Join(", ", (from d in weights select d.ToString()).ToArray()));
            if (wIndex != -1)
            {
                updateXTable(weights);
            }
            return(null);
        }
Esempio n. 8
0
 public void SaveInTable(InTable Data)
 {
     using (var dbContext = new ToolManageDbContext())
     {
         if (Data.ID > 0)
         {
             dbContext.Update <InTable>(Data);
         }
         else
         {
             dbContext.Insert <InTable>(Data);
         }
     }
 }
Esempio n. 9
0
        private void getTableMatrix()
        {
            n = 0;
            List <double[]> inputMatrixLst = new List <double[]>();

            int[]        fldsIndex = new int[VariableFieldNames.Length];
            IQueryFilter qrf       = new QueryFilterClass();

            qrf.SubFields = String.Join(", ", VariableFieldNames);
            ICursor cur  = InTable.Search(qrf, false);
            IFields flds = cur.Fields;

            for (int i = 0; i < VariableFieldNames.Length; i++)
            {
                //Console.WriteLine(VariableFieldNames[i]);
                fldsIndex[i] = flds.FindField(VariableFieldNames[i]);
            }
            IRow rw = cur.NextRow();

            System.Random r = new Random();

            while (rw != null)
            {
                if (r.NextDouble() <= prop)
                {
                    double[] vlArr = new double[VariableFieldNames.Length];
                    for (int i = 0; i < fldsIndex.Length; i++)
                    {
                        int    fldIndex = fldsIndex[i];
                        double vl       = System.Convert.ToDouble(rw.get_Value(fldIndex));
                        //Console.WriteLine(vl.ToString());
                        if (Double.IsNaN(vl))
                        {
                            vl = 0;
                        }
                        vlArr[i] = vl;
                    }
                    inputMatrixLst.Add(vlArr);
                    n++;
                }

                rw = cur.NextRow();
            }
            inputMatrix = inputMatrixLst.ToArray();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
        }
Esempio n. 10
0
        public override double[,] getMatrix()
        {
            if (unVlDic == null)
            {
                unVlDic = UniqueClassValues;
            }
            int indCnt = IndependentFieldNames.Length;
            int depCnt = DependentFieldNames.Length;
            int rws    = InTable.RowCount(null);

            n = rws;
            ICursor cur  = InTable.Search(null, false);
            int     clms = IndependentFieldNames.Length + DependentFieldNames.Length;

            int[] allFieldIndexArray = new int[clms];
            allFieldNames = new string[clms];
            for (int i = 0; i < indCnt; i++)
            {
                string lu = IndependentFieldNames[i];
                allFieldNames[i]      = lu;
                allFieldIndexArray[i] = cur.FindField(lu);
                List <string> outSet = null;
                if (unVlDic.TryGetValue(lu, out outSet))
                {
                    int t = (outSet.Count() - 1);
                    clms = clms + t;
                }
            }
            for (int i = 0; i < depCnt; i++)
            {
                string lu = DependentFieldNames[i];
                categories = unVlDic[lu].ToArray();
                nclasses  += unVlDic[lu].Count;
                allFieldNames[i + indCnt]      = lu;
                allFieldIndexArray[i + indCnt] = cur.FindField(lu);
            }
            nvars     = clms - 1;
            outMatrix = new double[rws, clms];
            int  rwCnt = 0;
            IRow rw    = cur.NextRow();

            while (rw != null)
            {
                int indMatrixClm = 0;
                for (int i = 0; i < allFieldIndexArray.Length; i++)
                {
                    string lu         = allFieldNames[i];
                    int    fldClmCntT = 1;
                    int    indexFld   = allFieldIndexArray[i];
                    object vl         = rw.get_Value(indexFld);
                    updateMinMaxSum(vl, i);
                    double dblVl = 0;
                    try
                    {
                        string        strVl = vl.ToString();
                        List <string> unVl  = null;
                        if (unVlDic.TryGetValue(lu, out unVl))
                        {
                            int fldClmCntP = unVl.IndexOf(strVl);
                            if (i == allFieldIndexArray.Length - 1)
                            {
                                dblVl = fldClmCntP;
                            }
                            else
                            {
                                fldClmCntT    = unVl.Count() - fldClmCntP;
                                indMatrixClm += fldClmCntP;
                                dblVl         = 1;
                            }
                        }
                        else
                        {
                            dblVl = System.Convert.ToDouble(strVl);
                        }
                    }
                    catch
                    {
                        dblVl = 0;
                    }
                    outMatrix[rwCnt, indMatrixClm] = dblVl;
                    indMatrixClm += fldClmCntT;
                }
                rw     = cur.NextRow();
                rwCnt += 1;
            }
            return(outMatrix);
        }
Esempio n. 11
0
        private void formatData()
        {
            string depFldName = DependentFieldNames[0];

            if (unVlDic == null)
            {
                unVlDic = UniqueClassValues;
            }
            int indCnt = IndependentFieldNames.Length;
            int depCnt = DependentFieldNames.Length;
            int rws    = InTable.RowCount(null);

            n = rws;
            ICursor cur  = InTable.Search(null, false);
            int     clms = indCnt;

            int[] allFieldIndexArray = new int[clms];
            allFieldNames = new string[clms];
            for (int i = 0; i < indCnt; i++)
            {
                string lu = IndependentFieldNames[i];
                allFieldNames[i]      = lu;
                allFieldIndexArray[i] = cur.FindField(lu);
                List <string> outSet = null;
                if (unVlDic.TryGetValue(lu, out outSet))
                {
                    int t = (outSet.Count() - 1);
                    clms = clms + t;
                }
            }
            categories = unVlDic[depFldName].ToArray();
            ncat       = categories.Length;
            int depIndex = cur.FindField(depFldName);

            nvars       = clms;
            independent = new double[rws][];
            dependent   = new double[rws];
            int  rwCnt = 0;
            IRow rw    = cur.NextRow();

            while (rw != null)
            {
                int      indMatrixClm = 0;
                double[] rwVls        = new double[clms];
                for (int i = 0; i < allFieldIndexArray.Length; i++)
                {
                    string lu         = allFieldNames[i];
                    int    fldClmCntT = 1;
                    int    indexFld   = allFieldIndexArray[i];
                    object vl         = rw.get_Value(indexFld);
                    updateMinMaxSum(vl, i);
                    double dblVl = 0;
                    try
                    {
                        string        strVl = vl.ToString();
                        List <string> unVl  = null;
                        if (unVlDic.TryGetValue(lu, out unVl))
                        {
                            int fldClmCntP = unVl.IndexOf(strVl);
                            fldClmCntT    = unVl.Count() - fldClmCntP;
                            indMatrixClm += fldClmCntP;
                            dblVl         = 1;
                        }
                        else
                        {
                            dblVl = System.Convert.ToDouble(strVl);
                        }
                    }
                    catch
                    {
                        dblVl = 0;
                    }
                    rwVls[indMatrixClm] = dblVl;
                    indMatrixClm       += fldClmCntT;
                }
                independent[rwCnt] = rwVls;
                string dVl   = rw.get_Value(depIndex).ToString();
                int    index = unVlDic[depFldName].IndexOf(dVl);
                dependent[rwCnt] = index;
                rw     = cur.NextRow();
                rwCnt += 1;
            }
        }
Esempio n. 12
0
        public ActionResult Create()//报修
        {
            var model = new InTable();

            return(View(model));
        }
Esempio n. 13
0
        public override double[,] getMatrix()
        {
            if (unVlDic == null)
            {
                unVlDic = UniqueClassValues;
            }
            int indCnt = IndependentFieldNames.Length;
            int depCnt = DependentFieldNames.Length;

            int rws = InTable.RowCount(null);

            n = rws;
            ICursor cur        = InTable.Search(null, true);
            string  depFldName = DependentFieldNames[0];
            int     depIndex   = cur.FindField(depFldName);
            int     clms       = indCnt;

            int[] allFieldIndexArray = new int[clms];
            allFieldNames = new string[clms + 1];
            for (int i = 0; i < indCnt; i++)
            {
                string lu = IndependentFieldNames[i];
                allFieldNames[i]      = lu;
                allFieldIndexArray[i] = cur.FindField(lu);
                List <string> outSet = null;
                if (unVlDic.TryGetValue(lu, out outSet))
                {
                    int t = (outSet.Count() - 1);
                    clms = clms + t;
                }
            }


            allFieldNames[indCnt] = depFldName;
            nvars          = clms;
            independentVls = new double[rws][];
            dependentVls   = new int[rws];
            List <string> depKey = unVlDic[depFldName];
            int           rwCnt  = 0;
            IRow          rw     = cur.NextRow();

            while (rw != null)
            {
                double[] rwVls        = new double[clms];
                int      indMatrixClm = 0;
                for (int i = 0; i < allFieldIndexArray.Length; i++)
                {
                    string lu         = allFieldNames[i];
                    int    fldClmCntT = 1;
                    int    indexFld   = allFieldIndexArray[i];
                    object vl         = rw.get_Value(indexFld);
                    updateMinMaxSum(vl, i);
                    double dblVl = 0;
                    try
                    {
                        string        strVl = vl.ToString();
                        List <string> unVl  = null;
                        if (unVlDic.TryGetValue(lu, out unVl))
                        {
                            int fldClmCntP = unVl.IndexOf(strVl);
                            fldClmCntT    = unVl.Count() - fldClmCntP;
                            indMatrixClm += fldClmCntP;
                            dblVl         = 1;
                        }
                        else
                        {
                            dblVl = System.Convert.ToDouble(strVl);
                        }
                    }
                    catch
                    {
                        dblVl = 0;
                    }
                    rwVls[indMatrixClm] = dblVl;
                    indMatrixClm       += fldClmCntT;
                }
                independentVls[rwCnt] = rwVls;
                string depStr = rw.get_Value(depIndex).ToString();
                dependentVls[rwCnt] = depKey.IndexOf(depStr);
                rw     = cur.NextRow();
                rwCnt += 1;
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
            return(null);
        }
Esempio n. 14
0
        /// <summary>
        /// Adds Probabilities confidence intervals to the map given the plr model
        /// </summary>

        public void addConfidenceIntervals()
        {
            IEnumerable <string> hdArr = null;
            Dictionary <string, IEnumerable <string> > vlDic = new Dictionary <string, IEnumerable <string> >();

            using (System.IO.StreamReader sr = new System.IO.StreamReader(SasOutputFile))
            {
                string ln = sr.ReadLine();
                hdArr = ln.Split(new char[] { ',' }).Skip(2);
                foreach (string s in hdArr)
                {
                    if (InTable.FindField(s) == -1)
                    {
                        geoUtil.createField(InTable, s, esriFieldType.esriFieldTypeSingle);
                    }
                }
                while ((ln = sr.ReadLine()) != null)
                {
                    string[]             vlArr   = ln.Split(new char[] { ',' });
                    string               mpCls   = vlArr[0];
                    IEnumerable <string> enumVls = vlArr.Skip(2);
                    vlDic[mpCls] = enumVls;
                }
                sr.Close();
            }
            IDataset       dSet    = (IDataset)InTable;
            IWorkspace     wks     = dSet.Workspace;
            IWorkspaceEdit wksE    = (IWorkspaceEdit)wks;
            bool           weStart = true;

            if (wksE.IsBeingEdited())
            {
                weStart = false;
            }
            else
            {
                wksE.StartEditing(false);
            }
            wksE.StartEditOperation();
            ICursor uCur     = InTable.Update(null, false);
            int     valIndex = uCur.FindField(MapField);
            IRow    uRow     = uCur.NextRow();

            while (uRow != null)
            {
                string mpVl = uRow.get_Value(valIndex).ToString();
                IEnumerable <string> vls;
                if (vlDic.TryGetValue(mpVl, out vls))
                {
                    for (int i = 0; i < hdArr.Count(); i++)
                    {
                        string fldNm    = hdArr.ElementAt(i);
                        float  fldVl    = System.Convert.ToSingle(vls.ElementAt(i));
                        int    fldIndex = uCur.FindField(fldNm);
                        uRow.set_Value(fldIndex, fldVl);
                    }
                    uCur.UpdateRow(uRow);
                }
                uRow = uCur.NextRow();
            }
            wksE.StopEditOperation();
            if (weStart)
            {
                wksE.StopEditing(true);
            }
        }
Esempio n. 15
0
        private void buildVector()
        {
            n = 0;
            int[]        fldsIndex = new int[VariableFieldNames.Length];
            IQueryFilter qrf       = new QueryFilterClass();

            qrf.SubFields = String.Join(", ", VariableFieldNames);
            ICursor cur  = InTable.Search(qrf, false);
            IFields flds = cur.Fields;

            for (int i = 0; i < VariableFieldNames.Length; i++)
            {
                //Console.WriteLine(VariableFieldNames[i]);
                fldsIndex[i] = flds.FindField(VariableFieldNames[i]);
            }
            IRow rw = cur.NextRow();

            double[] vlArr = new double[VariableFieldNames.Length];
            while (rw != null)
            {
                bool check = true;
                for (int i = 0; i < fldsIndex.Length; i++)
                {
                    int    fldIndex = fldsIndex[i];
                    double vl       = System.Convert.ToDouble(rw.get_Value(fldIndex));
                    //Console.WriteLine(vl.ToString());
                    if (Double.IsNaN(vl))
                    {
                        check = false;
                        break;
                    }
                    else
                    {
                        vlArr[i] = vl;
                    }
                }
                if (check)
                {
                    for (int i = 0; i < vlArr.Length; i++)
                    {
                        double vl1 = vlArr[i];
                        sumClms[i]     += vlArr[i];
                        sumCross[i, i] += Math.Pow(vlArr[i], 2);
                        for (int j = 0 + i + 1; j < vlArr.Length; j++)
                        {
                            double vl2 = vlArr[j];
                            double p12 = vl1 * vl2;
                            sumCross[i, j] += p12;
                            sumCross[j, i] += p12;
                        }
                    }
                    n++;
                }
                rw = cur.NextRow();
            }
            int sampN = n;

            for (int i = 0; i < sumClms.Length; i++)
            {
                double var = (sumCross[i, i] / (sampN)) - (Math.Pow(sumClms[i], 2) / Math.Pow((sampN), 2));
                cov[i, i] = var;
                for (int j = 0 + i + 1; j < sumClms.Length; j++)
                {
                    double vl1 = (sumCross[j, i] / (sampN));
                    double vl2 = (sumClms[j] / (sampN)) * (sumClms[i] / (sampN));
                    double p12 = vl1 - vl2;
                    cov[i, j] = p12;
                    cov[j, i] = p12;
                }
            }
        }
Esempio n. 16
0
        private void buildModelftr()
        {
            Dictionary <string, int> stratDic = new Dictionary <string, int>();

            n = 0;
            int[]        fldsIndex = new int[VariableFieldNames.Length];
            IQueryFilter qrf       = new QueryFilterClass();

            qrf.SubFields = String.Join(",", VariableFieldNames) + "," + StrataField;
            ICursor cur  = InTable.Search(qrf, false);
            IFields flds = cur.Fields;

            for (int i = 0; i < VariableFieldNames.Length; i++)
            {
                //Console.WriteLine(VariableFieldNames[i]);
                fldsIndex[i] = flds.FindField(VariableFieldNames[i]);
            }
            int  stratIndex = flds.FindField(StrataField);
            IRow rw         = cur.NextRow();

            double[] vlArr   = new double[VariableFieldNames.Length];
            double[] sumClms = null;
            double[,] sumCross = null;
            double[,] cov      = null;
            double[,] scov     = null;
            while (rw != null)
            {
                bool   check = true;
                object sObj  = rw.get_Value(stratIndex);
                if (sObj == null)
                {
                }
                else
                {
                    string strataValue = sObj.ToString();
                    int    sCnt;
                    if (stratDic.TryGetValue(strataValue, out sCnt))
                    {
                        stratDic[strataValue] = sCnt + 1;
                        int lIndex = lbl.IndexOf(strataValue);
                        sumClms  = sumClmsLst[lIndex];
                        sumCross = sumCrossLst[lIndex];
                    }
                    else
                    {
                        stratDic.Add(strataValue, 1);
                        int lIndex = lbl.Count;
                        lbl.Add(strataValue);
                        sumClms  = new double[VariableFieldNames.Length];
                        sumCross = new double[VariableFieldNames.Length, VariableFieldNames.Length];
                        cov      = new double[VariableFieldNames.Length, VariableFieldNames.Length];
                        scov     = new double[VariableFieldNames.Length, VariableFieldNames.Length];
                        sumClmsLst.Add(sumClms);
                        sumCrossLst.Add(sumCross);
                        covLst.Add(cov);
                        scovLst.Add(scov);
                    }

                    for (int i = 0; i < fldsIndex.Length; i++)
                    {
                        int    fldIndex = fldsIndex[i];
                        double vl       = System.Convert.ToDouble(rw.get_Value(fldIndex));
                        //Console.WriteLine(vl.ToString());
                        if (Double.IsNaN(vl))
                        {
                            check = false;
                            break;
                        }
                        else
                        {
                            vlArr[i] = vl;
                        }
                    }
                    if (check)
                    {
                        for (int i = 0; i < vlArr.Length; i++)
                        {
                            double vl1 = vlArr[i];
                            sumClms[i]     += vlArr[i];
                            sumCross[i, i] += Math.Pow(vlArr[i], 2);
                            for (int j = 0 + i + 1; j < vlArr.Length; j++)
                            {
                                double vl2 = vlArr[j];
                                double p12 = vl1 * vl2;
                                sumCross[i, j] += p12;
                                sumCross[j, i] += p12;
                            }
                        }
                        n++;
                    }
                }
                rw = cur.NextRow();
            }
            for (int l = 0; l < lbl.Count; l++)
            {
                string lblVl = lbl[l];
                int    sampN = stratDic[lblVl];
                double r     = sampN / (sampN - 1);
                proportionsLst.Add(System.Convert.ToDouble(sampN) / n);
                sumClms = sumClmsLst[l];
                meansLst.Add((from double d in sumClms select d / sampN).ToArray());
                sumCross = sumCrossLst[l];
                cov      = covLst[l];
                scov     = scovLst[l];
                for (int i = 0; i < sumClms.Length; i++)
                {
                    double var = (sumCross[i, i] / sampN) - (Math.Pow(sumClms[i], 2) / Math.Pow((sampN), 2));
                    cov[i, i]  = var;
                    scov[i, i] = var * r;
                    for (int j = 0 + i + 1; j < sumClms.Length; j++)
                    {
                        double vl1 = (sumCross[j, i] / (sampN));
                        double vl2 = (sumClms[j] / (sampN)) * (sumClms[i] / (sampN));
                        double p12 = vl1 - vl2;
                        cov[i, j]  = p12;
                        cov[j, i]  = p12;
                        scov[i, j] = p12 * r;
                        scov[j, i] = p12 * r;
                    }
                }
            }

            k = lbl.Count;
            makeKMeans();
        }
Esempio n. 17
0
        private void buildModelftr()
        {
            sumX.Clear();
            sumX2.Clear();
            cateDic.Clear();
            lbl.Clear();
            int v1 = VariableFieldNames.Length;

            double[] s  = new double[(v1 * v1 - v1) / 2];
            double[] s2 = new double[s.Length];
            n = 0;
            IQueryFilter qf = new QueryFilterClass();

            qf.SubFields = StrataField + "," + String.Join(",", VariableFieldNames);
            ICursor cur = InTable.Search(qf, false);

            int[] varIndex = new int[VariableFieldNames.Length];
            for (int i = 0; i < VariableFieldNames.Length; i++)
            {
                string var = VariableFieldNames[i];
                varIndex[i] = cur.FindField(var);
            }
            int  stIndex = cur.FindField(StrataField);
            IRow rw      = cur.NextRow();

            while (rw != null)
            {
                object strata = rw.get_Value(stIndex);
                if (strata == null)
                {
                    continue;
                }
                else
                {
                    string strataStr = strata.ToString();
                    int    strataIndex;
                    int    cnt;
                    if (cateDic.TryGetValue(strataStr, out cnt))
                    {
                        cnt         = cnt + 1;
                        strataIndex = lbl.IndexOf(strataStr);
                        s           = sumX[strataIndex];
                        s2          = sumX2[strataIndex];
                    }
                    else
                    {
                        cnt = 1;
                        cateDic.Add(strataStr, 0);
                        lbl.Add(strataStr);
                        strataIndex = lbl.Count - 1;
                        s           = new double[s.Length];
                        s2          = new double[s.Length];
                        sumX.Add(s);
                        sumX2.Add(s2);
                    }
                    bool     checkVl = true;
                    double[] vlArr   = new double[VariableFieldNames.Length];
                    for (int p = 0; p < VariableFieldNames.Length; p++)
                    {
                        int    fldIndex = varIndex[p];
                        object vl       = rw.get_Value(fldIndex);
                        if (vl == null)
                        {
                            checkVl = false;
                            break;
                        }
                        else
                        {
                            vlArr[p] = System.Convert.ToDouble(vl);
                        }
                    }
                    if (checkVl)
                    {
                        int vlCnter = 1;
                        int sCnter  = 0;
                        for (int i = 0; i < vlArr.Length - 1; i++)
                        {
                            for (int k = vlCnter; k < vlArr.Length; k++)
                            {
                                double m  = vlArr[i] - vlArr[k];
                                double m2 = m * m;
                                s[sCnter]  = s[sCnter] + m;
                                s2[sCnter] = s2[sCnter] + m2;
                                sCnter    += 1;
                            }
                            vlCnter += 1;
                        }
                        cateDic[strataStr] = cnt;
                        n += 1;
                    }
                }
                rw = cur.NextRow();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
        }