コード例 #1
0
        public static System.Collections.ArrayList GetLasts(this System.Collections.ArrayList data, int count)
        {
            var l = data.Count;

            count = l > count ? count : l;
            return(data.GetRange(l - count, count));
        }
コード例 #2
0
ファイル: Utilities.cs プロジェクト: kryssb/SySal.NET
        public static NumericalTools.ComputationResult SafeMeanAverage(double[] x, double fraction, out double mean, out double min, out double max, out double err)
        {
            System.Collections.ArrayList a = new System.Collections.ArrayList(x);
            if (a.Count <= 1)
            {
                mean = min = max = err = 0.0;
                return(NumericalTools.ComputationResult.SingularityEncountered);
            }
            a.Sort();
            int minf = Math.Min(a.Count - 1, (int)Math.Round((1.0 - fraction) * 0.5 + a.Count));
            int maxf = Math.Min(a.Count - 1, (int)Math.Round((1.0 + fraction) * 0.5 + a.Count));

            a = a.GetRange(minf, maxf - minf);
            if (minf > maxf)
            {
                minf = maxf;
            }
            min = (double)a[0];
            max = (double)a[a.Count - 1];
            double d = 0.0;

            foreach (double dx in a)
            {
                d += dx;
            }
            mean = d / a.Count;
            err  = (max - min) * 0.5 / Math.Sqrt(a.Count);
            return(NumericalTools.ComputationResult.OK);
        }
コード例 #3
0
        public base_scopeArrayList GetRange(int index, int count)
        {
            System.Collections.ArrayList al   = arr.GetRange(index, count);
            base_scopeArrayList          tnal = new base_scopeArrayList();

            tnal.arr = al;
            return(tnal);
        }
コード例 #4
0
        public unit_nodeArrayList GetRange(int index, int count)
        {
            System.Collections.ArrayList al   = arr.GetRange(index, count);
            unit_nodeArrayList           tnal = new unit_nodeArrayList();

            tnal.arr = al;
            return(tnal);
        }
コード例 #5
0
        public using_namespaceArrayList GetRange(int index, int count)
        {
            System.Collections.ArrayList al   = arr.GetRange(index, count);
            using_namespaceArrayList     tnal = new using_namespaceArrayList();

            tnal.arr = al;
            return(tnal);
        }
コード例 #6
0
        public SymbolInfoArrayList GetRange(int index, int count)
        {
            System.Collections.ArrayList al   = arr.GetRange(index, count);
            SymbolInfoArrayList          tnal = new SymbolInfoArrayList();

            tnal.arr = al;
            return(tnal);
        }
コード例 #7
0
        /// <summary>
        /// Rollback the instruction stream for a program so that
        /// the indicated instruction (via instructionIndex) is no
        /// longer in the stream.
        /// </summary>
        /// <remarks>
        /// UNTESTED!
        /// </remarks>
        /// <param name="programName"></param>
        /// <param name="instructionIndex"></param>
        public void rollback(string programName, int instructionIndex)
        {
            ArrayList il = (ArrayList)programs[programName];

            if (il != null)
            {
                programs[programName] = il.GetRange(MIN_TOKEN_INDEX, (instructionIndex - MIN_TOKEN_INDEX));
            }
        }
コード例 #8
0
        private void Compute(bool comp_x, bool comp_y, object btn)
        {
            m_Running = true;
            EnableButtons(btn);
            m_Stop           = false;
            pbProgress.Value = 0.0;
            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
            {
                try
                {
                    SySal.Processing.QuickMapping.QuickMapper QM    = new SySal.Processing.QuickMapping.QuickMapper();
                    SySal.Processing.QuickMapping.Configuration qmc = (SySal.Processing.QuickMapping.Configuration)QM.Config;
                    qmc.FullStatistics       = false;
                    qmc.UseAbsoluteReference = true;
                    qmc.PosTol   = S.PosTolerance;
                    qmc.SlopeTol = 1.0;
                    QM.Config    = qmc;
                    System.Collections.ArrayList xconv = new System.Collections.ArrayList();
                    System.Collections.ArrayList yconv = new System.Collections.ArrayList();
                    int sfi;
                    for (sfi = 0; sfi < SummaryFiles.Length; sfi++)
                    {
                        QuasiStaticAcquisition Q = new QuasiStaticAcquisition(SummaryFiles[sfi]);
                        foreach (QuasiStaticAcquisition.Sequence seq in Q.Sequences)
                        {
                            int ly;
                            SySal.Imaging.Cluster[] prevC = FilterClusters(seq.Layers[0].ReadClusters());
                            SySal.Imaging.Cluster[] nextC = null;
                            SySal.BasicTypes.Vector prevP = seq.Layers[0].Position;
                            SySal.BasicTypes.Vector nextP = new SySal.BasicTypes.Vector();
                            for (ly = 1; ly < seq.Layers.Length; ly++)
                            {
                                if (m_Stop)
                                {
                                    throw new Exception("Stopped.");
                                }
                                nextC = FilterClusters(seq.Layers[ly].ReadClusters());
                                nextP = seq.Layers[ly].Position;
                                this.Invoke(new dSetValue(SetValue), 100.0 * (((double)seq.Id + (double)(ly - 1) / (double)(seq.Layers.Length - 1)) / (double)(Q.Sequences.Length) + sfi) / SummaryFiles.Length);
                                SySal.BasicTypes.Vector2 dp   = new SySal.BasicTypes.Vector2(seq.Layers[ly].Position - seq.Layers[ly - 1].Position);
                                SySal.BasicTypes.Vector2 dp1  = dp; dp1.X /= S.MinConv; dp1.Y /= S.MinConv;
                                SySal.BasicTypes.Vector2 dp2  = dp; dp2.X /= S.MaxConv; dp2.Y /= S.MaxConv;
                                SySal.BasicTypes.Vector2 da   = new SySal.BasicTypes.Vector2(); da.X = 0.5 * (dp1.X + dp2.X); da.Y = 0.5 * (dp1.Y + dp2.Y);
                                SySal.BasicTypes.Vector2 dext = new SySal.BasicTypes.Vector2(); dext.X = Math.Abs(dp1.X - dp2.X); dext.Y = Math.Abs(dp1.Y - dp2.Y);
                                SySal.Tracking.MIPEmulsionTrackInfo[] prevmap = new SySal.Tracking.MIPEmulsionTrackInfo[prevC.Length];
                                int i;
                                for (i = 0; i < prevC.Length; i++)
                                {
                                    SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo();
                                    info.Intercept.X = prevC[i].X;
                                    info.Intercept.Y = prevC[i].Y;
                                    prevmap[i]       = info;
                                }
                                SySal.Tracking.MIPEmulsionTrackInfo[] nextmap = new SySal.Tracking.MIPEmulsionTrackInfo[nextC.Length];
                                for (i = 0; i < nextC.Length; i++)
                                {
                                    nextmap[i] = new SySal.Tracking.MIPEmulsionTrackInfo();
                                }
                                double[,] convopt = new double[, ] {
                                    { 1.0, 1.0 }, { -1.0, 1.0 }, { -1.0, -1.0 }, { 1.0, -1.0 }
                                };
                                int o;
                                SySal.Scanning.PostProcessing.PatternMatching.TrackPair[] bestpairs = new SySal.Scanning.PostProcessing.PatternMatching.TrackPair[0];
                                SySal.BasicTypes.Vector2 bestda = new SySal.BasicTypes.Vector2();
                                for (o = 0; o < convopt.GetLength(0); o++)
                                {
                                    try
                                    {
                                        for (i = 0; i < nextC.Length; i++)
                                        {
                                            SySal.Tracking.MIPEmulsionTrackInfo info = nextmap[i];
                                            info.Intercept.X = nextC[i].X + da.X * convopt[o, 0];
                                            info.Intercept.Y = nextC[i].Y + da.Y * convopt[o, 1];
                                            nextmap[i]       = info;
                                        }
                                        SySal.Scanning.PostProcessing.PatternMatching.TrackPair[] prs = QM.Match(prevmap, nextmap, 0.0, dext.X, dext.Y);
                                        if (prs.Length > bestpairs.Length)
                                        {
                                            bestda.X  = da.X * convopt[o, 0];
                                            bestda.Y  = da.Y * convopt[o, 1];
                                            bestpairs = prs;
                                        }
                                    }
                                    catch (Exception xc) { }
                                }

                                if (bestpairs.Length >= S.MinMatches)
                                {
                                    double[] deltas = new double[bestpairs.Length];
                                    for (i = 0; i < bestpairs.Length; i++)
                                    {
                                        deltas[i] = bestpairs[i].First.Info.Intercept.X - nextC[bestpairs[i].Second.Index].X;
                                    }
                                    bestda.X = NumericalTools.Fitting.Quantiles(deltas, new double[] { 0.5 })[0];
                                    if (bestda.X != 0.0)
                                    {
                                        double v = dp.X / bestda.X;
                                        int pos  = xconv.BinarySearch(v);
                                        if (pos < 0)
                                        {
                                            pos = ~pos;
                                        }
                                        xconv.Insert(pos, v);
                                    }
                                    for (i = 0; i < bestpairs.Length; i++)
                                    {
                                        deltas[i] = bestpairs[i].First.Info.Intercept.Y - nextC[bestpairs[i].Second.Index].Y;
                                    }
                                    bestda.Y = NumericalTools.Fitting.Quantiles(deltas, new double[] { 0.5 })[0];
                                    if (bestda.Y != 0.0)
                                    {
                                        double v = dp.Y / bestda.Y;
                                        int pos  = yconv.BinarySearch(v);
                                        if (pos < 0)
                                        {
                                            pos = ~pos;
                                        }
                                        yconv.Insert(pos, v);
                                    }
                                    if (comp_x && xconv.Count > 0)
                                    {
                                        int bmin, bmax;
                                        bmin = (int)Math.Ceiling(xconv.Count * 0.16);
                                        bmax = (int)Math.Floor(xconv.Count * 0.84);
                                        if (bmax < bmin)
                                        {
                                            bmin = bmax;
                                        }
                                        double[] sample1s = (double[])xconv.GetRange(bmin, bmax - bmin + 1).ToArray(typeof(double));
                                        XConv             = NumericalTools.Fitting.Average(sample1s);
                                        this.Invoke(new dSetConv(SetConv), new object[] { true, XConv, 0.5 * (sample1s[sample1s.Length - 1] - sample1s[0]) / Math.Sqrt(sample1s.Length) });
                                    }
                                    if (comp_y && yconv.Count > 0)
                                    {
                                        int bmin, bmax;
                                        bmin = (int)Math.Ceiling(yconv.Count * 0.16);
                                        bmax = (int)Math.Floor(yconv.Count * 0.84);
                                        if (bmax < bmin)
                                        {
                                            bmin = bmax;
                                        }
                                        double[] sample1s = (double[])yconv.GetRange(bmin, bmax - bmin + 1).ToArray(typeof(double));
                                        YConv             = NumericalTools.Fitting.Average(sample1s);
                                        this.Invoke(new dSetConv(SetConv), new object[] { false, YConv, 0.5 * (sample1s[sample1s.Length - 1] - sample1s[0]) / Math.Sqrt(sample1s.Length) });
                                    }
                                }
                                prevP = nextP;
                                prevC = nextC;
                            }
                        }
                    }
                }
                catch (Exception xc1)
                {
                    iLog.Log("Compute", xc1.ToString());
                }
                m_Running = false;
                this.Invoke(new dEnableButtons(EnableButtons), btn);
            }));
            thread.Start();
        }
コード例 #9
0
ファイル: Match.cs プロジェクト: chunlea/rubydotnetcompiler
        // --------------------------------------------------------------------------------

        internal static Array match_array(Match match, int start)
        {
            bool taint = match.Tainted;

            System.Collections.ArrayList result = new System.Collections.ArrayList();

            foreach (System.Text.RegularExpressions.Group group in match.value.Groups)
            {
                String str;
                if (group.Success)
                {
                    str = new String(group.Value);
                    str.Tainted = taint;
                }
                else
                {
                    str = null;
                }
                result.Add(str);
            }

            if (start == 0)
                return new Array(result);

            return new Array(result.GetRange(start, result.Count - 1));
        }