//-------------------------------------------------------------------------
        public virtual void test_interpolation()
        {
            GridSurfaceInterpolator  test = GridSurfaceInterpolator.of(LINEAR, FLAT, FLAT, LINEAR, FLAT, FLAT);
            BoundSurfaceInterpolator bci  = test.bind(X_DATA, Y_DATA, Z_DATA);

            for (int i = 0; i < X_DATA.size(); i++)
            {
                assertEquals(bci.interpolate(X_DATA.get(i), Y_DATA.get(i)), Z_DATA.get(i), TOL);
            }
            for (int i = 0; i < X_TEST.size(); i++)
            {
                assertEquals(bci.interpolate(X_TEST.get(i), Y_TEST.get(i)), Z_TEST.get(i), TOL);
            }
        }
Exemple #2
0
        // constructor that sorts (artificial boolean flag)
        private InterpolatedNodalSurface(SurfaceMetadata metadata, DoubleArray xValues, DoubleArray yValues, DoubleArray zValues, SurfaceInterpolator interpolator, bool sort)
        {
            validateInputs(metadata, xValues, yValues, zValues, interpolator);
            // sort inputs
            IDictionary <DoublesPair, ObjDoublePair <ParameterMetadata> > sorted = new SortedDictionary <DoublesPair, ObjDoublePair <ParameterMetadata> >();

            for (int i = 0; i < xValues.size(); i++)
            {
                ParameterMetadata pm = metadata.getParameterMetadata(i);
                sorted[DoublesPair.of(xValues.get(i), yValues.get(i))] = ObjDoublePair.of(pm, zValues.get(i));
            }
            double[]            sortedX  = new double[sorted.Count];
            double[]            sortedY  = new double[sorted.Count];
            double[]            sortedZ  = new double[sorted.Count];
            ParameterMetadata[] sortedPm = new ParameterMetadata[sorted.Count];
            int pos = 0;

            foreach (KeyValuePair <DoublesPair, ObjDoublePair <ParameterMetadata> > entry in sorted.SetOfKeyValuePairs())
            {
                sortedX[pos]  = entry.Key.First;
                sortedY[pos]  = entry.Key.Second;
                sortedZ[pos]  = entry.Value.Second;
                sortedPm[pos] = entry.Value.First;
                pos++;
            }
            // assign
            SurfaceMetadata sortedMetadata = metadata.withParameterMetadata(Arrays.asList(sortedPm));

            this.metadata = sortedMetadata;
            this.xValues  = DoubleArray.ofUnsafe(sortedX);
            this.yValues  = DoubleArray.ofUnsafe(sortedY);
            this.zValues  = DoubleArray.ofUnsafe(sortedZ);
            IDictionary <DoublesPair, double> pairs = new Dictionary <DoublesPair, double>();

            for (int i = 0; i < xValues.size(); i++)
            {
                pairs[DoublesPair.of(xValues.get(i), yValues.get(i))] = zValues.get(i);
            }
            this.interpolator      = interpolator;
            this.boundInterpolator = interpolator.bind(this.xValues, this.yValues, this.zValues);
            this.parameterMetadata = IntStream.range(0, ParameterCount).mapToObj(i => sortedMetadata.getParameterMetadata(i)).collect(toImmutableList());
        }
Exemple #3
0
        //-------------------------------------------------------------------------
        // restricted constructor
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ImmutableConstructor private InterpolatedNodalSurface(SurfaceMetadata metadata, com.opengamma.strata.collect.array.DoubleArray xValues, com.opengamma.strata.collect.array.DoubleArray yValues, com.opengamma.strata.collect.array.DoubleArray zValues, com.opengamma.strata.market.surface.interpolator.SurfaceInterpolator interpolator)
        private InterpolatedNodalSurface(SurfaceMetadata metadata, DoubleArray xValues, DoubleArray yValues, DoubleArray zValues, SurfaceInterpolator interpolator)
        {
            validateInputs(metadata, xValues, yValues, zValues, interpolator);
            for (int i = 1; i < xValues.size(); i++)
            {
                if (xValues.get(i) < xValues.get(i - 1))
                {
                    throw new System.ArgumentException("Array of x-values must be sorted");
                }
                if (xValues.get(i) == xValues.get(i - 1) && yValues.get(i) <= yValues.get(i - 1))
                {
                    throw new System.ArgumentException("Array of y-values must be sorted and unique within x-values");
                }
            }
            this.metadata          = metadata;
            this.xValues           = xValues;
            this.yValues           = yValues;
            this.zValues           = zValues;
            this.interpolator      = interpolator;
            this.boundInterpolator = interpolator.bind(xValues, yValues, zValues);
            this.parameterMetadata = IntStream.range(0, ParameterCount).mapToObj(i => metadata.getParameterMetadata(i)).collect(toImmutableList());
        }