Exemple #1
0
        Tuple <IIndex <c>, VectorConstruction> IIndexBuilder.Search <c, d>(Tuple <IIndex <c>, VectorConstruction> _arg8, IVector <d> searchVector, d searchValue)
        {
            Tuple <IIndex <c>, VectorConstruction> tuple = _arg8;
            VectorConstruction vectorConstruction        = tuple.Item2;
            IIndex <c>         index1   = tuple.Item1;
            List <c>           cList    = new List <c>();
            List <long>        longList = new List <long>();
            int index2 = 0;
            int count  = index1.Keys.Count;
            int length = (int)searchVector.Length;
            int num    = (count >= length ? length : count) - 1;

            if (num >= index2)
            {
                do
                {
                    d optionalValue = searchVector.GetValue((long)index2);
                    if ((!optionalValue.HasValue ? 0 : (LanguagePrimitives.HashCompare.GenericEqualityIntrinsic <d>((M0)optionalValue.Value, (M0)searchValue) ? 1 : 0)) != 0)
                    {
                        cList.Add(index1.Keys[index2]);
                        longList.Add((long)index2);
                    }
                    ++index2;
                }while (index2 != num + 1);
            }
            LinearIndex <c>         linearIndex      = new LinearIndex <c>(System.Array.AsReadOnly <c>(ArrayModule.OfSeq <c>((IEnumerable <c>)cList)), (IIndexBuilder)this, (FSharpOption <bool>)null);
            IEnumerable <long>      indices          = (IEnumerable <long>)SeqModule.Map <long, long>((Func <M0, M1>) new LinearIndex.range(), (IEnumerable <M0>)longList);
            RangeRestriction <long> rangeRestriction = VectorHelpers.RangeRestriction.ofSeq((long)longList.Count, indices);

            return(new Tuple <IIndex <c>, VectorConstruction>((IIndex <c>)linearIndex, VectorConstruction.NewGetRange(vectorConstruction, rangeRestriction)));
        }
        public IVector GetObservedValues(IObservationDescriptions descr)
        {
            IVector result = new VectorJ2N(descr.ObservationCount);

            // TODO: handle TimeSeriesObservationDescriptions
            IVector obsTimes = descr.GetValueProperties("time");

            IVector obsIndex = descr.GetValueProperties("index") ?? descr.GetValueProperties("xPosition");

            IVector transformIndex;

            try
            {
                transformIndex = descr.GetValueProperties("transform");
            }
            catch (Exception)
            {
                transformIndex = null;
            }

            Time tHor = new Time(parameterValues[StartTimeId],
                                 parameterValues[StopTimeId])
            ;

            tHor.StepMJD = parameterValues[TimeStepId];

            if (storeObs)
            {
                //work from stored states
                for (int i = 0; i < descr.ObservationCount; i++)
                {
                    // at which timestep is this obs
                    long iObs = Utils.GetTimeStep(tHor, (new Time(obsTimes.GetValue(i))));
                    // find corresponding storage location
                    int thisTIndex = iStore.IndexOf((int)iObs);                      //time index in storage
                    if (thisTIndex < 0)
                    {
                        throw (new Exception("model.getValues: time out of range for observation nr. " + i));
                    }
                    int thisXIndex = (int)obsIndex.GetValue(i);
                    if ((thisXIndex < 0) | (thisXIndex >= state.Size))
                    {
                        throw (new Exception("model.getValues: index out of range for "
                                             + " observation nr. " + i
                                             + " index= " + thisXIndex));
                    }
                    //Console.Out.WriteLine("i="+i+" it="+thisTIndex+" ind= "+thisXIndex);
                    double thisValue = xStore[thisTIndex].GetValue(thisXIndex);
                    // transform values if needed
                    if (transformIndex != null)
                    {
                        if (transformIndex.GetValue(i) == 2)
                        {
                            // magic number for quadratic observations
                            thisValue = thisValue * thisValue;
                        }
                    }
                    result.SetValue(i, thisValue);
                }
            }
            else
            {
                // only current state is available
                for (int i = 0; i < descr.ObservationCount; i++)
                {
                    int thisXIndex = (int)obsIndex.GetValue(i);
                    //TODO if(){ //check time
                    double thisValue = state.GetValue(thisXIndex);
                    // transform values if needed
                    if (transformIndex != null)
                    {
                        if (transformIndex.GetValue(i) == 2)
                        {
                            // magic number for quadratic observations
                            thisValue = thisValue * thisValue;
                        }
                    }
                    result.SetValue(i, thisValue);
                }
            }

            return(result);
        }