예제 #1
0
        /// <summary>
        /// Add a key point at a specified index
        /// </summary>
        /// <param name="index">The index at which the key point will be added</param>
        /// <returns>The new key point</returns>
        public BezierPoint3D AddKeyPointAt(int index)
        {
            BezierPoint3D newPoint = new GameObject("Point " + KeyPoints.Count, typeof(BezierPoint3D)).GetComponent<BezierPoint3D>();
            newPoint.Curve = this;
            newPoint.transform.parent = transform;
            newPoint.transform.localRotation = Quaternion.identity;

            if (KeyPointsCount == 0 || KeyPointsCount == 1)
            {
                newPoint.LocalPosition = Vector3.zero;
            }
            else
            {
                if (index == 0)
                {
                    newPoint.Position = (KeyPoints[0].Position - KeyPoints[1].Position).normalized + KeyPoints[0].Position;
                }
                else if (index == KeyPointsCount)
                {
                    newPoint.Position = (KeyPoints[index - 1].Position - KeyPoints[index - 2].Position).normalized + KeyPoints[index - 1].Position;
                }
                else
                {
                    newPoint.Position = GetPointOnCubicCurve(0.5f, KeyPoints[index - 1], KeyPoints[index]);
                }
            }

            KeyPoints.Insert(index, newPoint);

            return newPoint;
        }
예제 #2
0
        public IYieldCurve BumpKeyRate(int index, double resetRate)
        {
            if (index < 0 || index > KeyPoints.Count() - 1)
            {
                throw new IndexOutOfRangeException("YieldCurve");
            }


            if (MarketInstruments == null)
            {
                //var offset = MarketInstruments == null ? 0 : KeyPoints.Length - MarketInstruments.Length;
                //var additionalBumpIndex = (index == 0 && offset > 0) ? 0 : Int32.MaxValue;
                return(new YieldCurve(
                           Name,
                           ReferenceDate,
                           KeyPoints.Select((x, i) => i == index ? Tuple.Create(x.Item1, resetRate) : x).ToArray(),
                           Bda,
                           DayCount,
                           Calendar,
                           Currency,
                           Compound,
                           Interpolation,
                           Trait,
                           BaseMarket,
                           CalibrateMktUpdateCondition,
                           Spread
                           ));
            }
            else
            {
                return(new YieldCurve(
                           Name,
                           ReferenceDate,
                           MarketInstruments.Select((x, i) => i == index ? new MarketInstrument(x.Instrument.Bump(resetRate), resetRate, x.CalibMethod) : x as MarketInstrument).ToArray(),
                           Bda,
                           DayCount,
                           Calendar,
                           Currency,
                           Compound,
                           Interpolation,
                           Trait,
                           BaseMarket,
                           CalibrateMktUpdateCondition,
                           null
                           )
                {
                    Spread = Spread
                });
            }
        }
예제 #3
0
        /// <summary>
        /// Removes a key point at a specified index
        /// </summary>
        /// <param name="index">The index of the key point that will be removed</param>
        /// <returns>true - if the point was removed, false - otherwise</returns>
        public bool RemoveKeyPointAt(int index)
        {
            if (KeyPointsCount < 2)
            {
                return false;
            }

            var point = KeyPoints[index];
            KeyPoints.RemoveAt(index);

            Destroy(point.gameObject);

            return true;
        }
예제 #4
0
        static void Main(string[] args)
        {
            var bayes = new Bayes();

            bayes.LoadData(@"D:\Politechnika\Semestr4\ArtificialIntelligencePOLSL\BayesAndKeyPoints\BayesAndKeyPoints\GoForAWalk.txt");
            bayes.Learn();
            bayes.Predict("Sunny", "Cool", "Weak");
            bayes.Predict("Rainy", "Hot", "Strong");

            var keyPoints = new KeyPoints();

            keyPoints.AddMask();
            keyPoints.PotencialPoints(5000);

            Console.ReadKey();
        }
    void CopyBlendShapes()
    {
        //sourceMesh = source.GetComponent<SkinnedMeshRenderer>().sharedMesh;
        targetMesh = target.GetComponent <SkinnedMeshRenderer>().sharedMesh;

        SetStatusMessage("Locating sub meshes");
        m_sourceSubMeshes = LocateSubMeshes(sourceMesh);
        m_targetSubMeshes = LocateSubMeshes(targetMesh);

        SetStatusMessage("Finding key points in meshes");
        m_sourceKeyPoints = FindKeyPoints(sourceMesh);
        m_targetKeyPoints = FindKeyPoints(targetMesh);

        DebugLog("SOURCE KEY POINTS: " + m_sourceKeyPoints.ToString());
        DebugLog("SOURCE BOUNDS: center=" + V3ToStr(m_sourceSubMeshes[SM_FACE].bounds.center) + ", extents=" + V3ToStr(m_sourceSubMeshes[SM_FACE].bounds.extents));
        DebugLog("TARGET KEY POINTS: " + m_targetKeyPoints.ToString());
        DebugLog("TARGET BOUNDS: center=" + V3ToStr(m_targetSubMeshes[SM_FACE].bounds.center) + ", extents=" + V3ToStr(m_targetSubMeshes[SM_FACE].bounds.extents));

        SetStatusMessage("Calculating face warps");
        CalculateFaceWarps();

        SetStatusMessage("Looping through blend shapes");
        for (int shapeIndex = 0; shapeIndex < sourceMesh.blendShapeCount; shapeIndex++)
        {
            string shapeName = sourceMesh.GetBlendShapeName(shapeIndex);
            DebugLog("======== BLEND SHAPE " + shapeName);

            // Don't copy if target already has a blend shape with this name. (It throws an exception.)
            if (targetMesh.GetBlendShapeIndex(shapeName) < 0)
            {
                // Copy across the keyframes in the blendshape (most have 1 keyframe).
                int frameCount = sourceMesh.GetBlendShapeFrameCount(shapeIndex);
                for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
                {
                    CopyBlendShapesOfFrame(shapeName, shapeIndex, frameIndex);
                }
                //break; // TODO: FOR NOW JUST DO ONE!
            }
            else
            {
                SetStatusMessage("Blend Shape " + shapeName + " already there");
            }
        }
    }
예제 #6
0
        //internal use + keyPoint manipulation, i.e. solving zspread
        //Note: this api will bypass curve calibration
        public YieldCurve(
            string name,
            Date referenceDate,
            Tuple <Date, double>[] keyPoints,
            BusinessDayConvention bda,
            IDayCount dayCount,
            ICalendar calendar,
            CurrencyCode currency,
            Compound compound,
            Interpolation interpolation,
            YieldCurveTrait trait,
            IMarketCondition baseMarket = null,
            Expression <Func <IMarketCondition, object> >[] calibrateMktUpdateCondition = null,
            ISpread spread     = null,
            string[] keyTenors = null,
            InstrumentCurveDefinition rawDefinition = null
            )
        {
            Name          = name;
            ReferenceDate = referenceDate;
            Currency      = currency;
            Bda           = bda;
            DayCount      = dayCount;
            Compound      = compound;
            Calendar      = calendar;
            Interpolation = interpolation;
            Trait         = trait;
            BaseMarket    = baseMarket;
            Spread        = spread ?? new ZeroSpread(0.0);
            CalibrateMktUpdateCondition = calibrateMktUpdateCondition;
            MarketInstruments           = null;
            KeyPoints     = keyPoints.OrderBy(x => x.Item1).ToArray();
            KeyTenors     = keyTenors ?? KeyPoints.Select(x => new Term(x.Item1 - ReferenceDate, Period.Day)).Select(x => x.ToString()).ToArray();
            RawDefinition = rawDefinition;

            InputRateByTenor = KeyPoints.Select(x => Tuple.Create <string, double> (new Term(x.Item1 - ReferenceDate, Period.Day).ToString(), x.Item2)).
                               ToDictionary(v => v.Item1, v => v.Item2);

            //_curve = new Curve<Date>(ReferenceDate, KeyPoints, x => x.ToOADate(), interpolation);
            _curveXInYears = new Curve <double>(0.0,
                                                KeyPoints.Select(x => Tuple.Create(DayCount.CalcDayCountFraction(ReferenceDate, x.Item1), x.Item2)).ToArray(),
                                                x => x,
                                                Interpolation);
        }
예제 #7
0
 public IYieldCurve Shift(int bp)
 {
     if (MarketInstruments == null)
     {
         return(new YieldCurve(
                    Name,
                    ReferenceDate,
                    KeyPoints.Select(x => Tuple.Create(x.Item1, x.Item2 + bp * 0.0001)).ToArray(),
                    Bda,
                    DayCount,
                    Calendar,
                    Currency,
                    Compound,
                    Interpolation,
                    Trait,
                    BaseMarket,
                    CalibrateMktUpdateCondition,
                    Spread
                    ));
     }
     else
     {
         return(new YieldCurve(
                    Name,
                    ReferenceDate,
                    MarketInstruments.Select(x => new MarketInstrument(x.Instrument.Bump(bp), x.TargetValue + bp * 0.0001, x.CalibMethod)).ToArray(),
                    Bda,
                    DayCount,
                    Calendar,
                    Currency,
                    Compound,
                    Interpolation,
                    Trait,
                    BaseMarket,
                    CalibrateMktUpdateCondition,
                    null
                    )
         {
             Spread = Spread
         });
     }
 }
    // Find some key points on the face (center of eyes etc)
    // These don't have to be exact - they just help normalize the source mesh to the target mesh a bit as eyes, nose, mouth can be different sizes.
    private KeyPoints FindKeyPoints(Mesh mesh)
    {
        // TODO: This assumes sub meshes are at certain places - if VRoid changes, these assumptions may become incorrect.

        KeyPoints kp = new KeyPoints();

        // Just pick any point in mesh as a relative value for Z so Z does not dominate below because the mouth is further forward in the head.
        float baseZ = mesh.vertices[0].z;

        // Assume subMesh 0 is the mouth. Find forward left and forward right most points as edges of mouth.
        UnityEngine.Rendering.SubMeshDescriptor mouthSmd = mesh.GetSubMesh(SM_MOUTH);
        for (int i = mouthSmd.firstVertex; i < mouthSmd.firstVertex + mouthSmd.vertexCount; i++)
        {
            Vector3 v = mesh.vertices[i];

            // Left is +ve X. Forward is +ve Z. We want front left, so add the -X and Z offsets.
            if ((v.x + (v.z - baseZ) / 2.0f) > (kp.leftEdgeOfMouth.x + (kp.leftEdgeOfMouth.z - baseZ) / 2.0f))
            {
                kp.leftEdgeOfMouth = v;
            }

            // Right is -ve X. Forward is +ve Z. We want front right, so add the X and Z offsets.
            if ((-v.x + (v.z - baseZ) / 2.0f) > (-kp.rightEdgeOfMouth.x + (kp.rightEdgeOfMouth.z - baseZ) / 2.0f))
            {
                kp.rightEdgeOfMouth = v;
            }
        }

        // Just approximate the eye positions.
        // TODO: Could do a more accurate estimation by perhaps taking average of all vertices with +ve and -ve X values.
        UnityEngine.Rendering.SubMeshDescriptor eyeSmd = mesh.GetSubMesh(SM_EYEWHITES);
        kp.centerOfLeftEye  = eyeSmd.bounds.center + new Vector3(eyeSmd.bounds.extents.x * 0.75f, 0, 0);
        kp.centerOfRightEye = eyeSmd.bounds.center - new Vector3(eyeSmd.bounds.extents.x * 0.75f, 0, 0);

        return(kp);
    }
예제 #9
0
 private void Awake()
 {
     compKeyPoints = GetComponent <KeyPoints>();
 }
예제 #10
0
 private void Awake()
 {
     kp = GetComponent <KeyPoints>();
     ts = GetComponent <TimeScale>();
 }
예제 #11
0
        //swap curve building for both pricing and pnl,   bond curve building only,  not for pnl
        public YieldCurve(
            string name,
            Date referenceDate,
            MarketInstrument[] marketInstruments,
            BusinessDayConvention bda,
            IDayCount dayCount,
            ICalendar calendar,
            CurrencyCode currency,
            Compound compound,
            Interpolation interpolation,
            YieldCurveTrait trait,
            IMarketCondition baseMarket = null,
            Expression <Func <IMarketCondition, object> >[] calibrateMktUpdateCondition = null,
            ISpread spread     = null,
            Date[] knotPoints  = null,
            string[] keyTenors = null,
            InstrumentCurveDefinition rawDefinition = null
            )
        {
            Name          = name;
            ReferenceDate = referenceDate;
            Currency      = currency;
            Bda           = bda;
            DayCount      = dayCount;
            Compound      = compound;
            Calendar      = calendar;
            Interpolation = interpolation;
            Trait         = trait;
            RawDefinition = rawDefinition;
            var tempMarketInstruments     = marketInstruments.OrderBy(x => x.Instrument.UnderlyingMaturityDate).ToArray();
            var uniqueTenorMktInstruments = new List <MarketInstrument> {
                tempMarketInstruments[0]
            };

            for (var i = 1; i < tempMarketInstruments.Length; ++i)
            {
                if (tempMarketInstruments[i].Instrument.GetCalibrationDate() != tempMarketInstruments[i - 1].Instrument.GetCalibrationDate())
                {
                    uniqueTenorMktInstruments.Add(tempMarketInstruments[i]);
                }
            }
            MarketInstruments = uniqueTenorMktInstruments.ToArray();
            InputRateByTenor  = MarketInstruments.ToDictionary(p => p.Instrument.Tenor, p => p.TargetValue);

            BaseMarket = baseMarket;
            Spread     = spread ?? new ZeroSpread(0.0);
            CalibrateMktUpdateCondition = calibrateMktUpdateCondition;

            if (MarketInstruments.Any(x => x.Instrument is Bond))
            {
                var err = double.NaN;
                KeyPoints    = BondCurveCalibrator.Calibrate(Name, ReferenceDate, MarketInstruments.ToArray(), Bda, DayCount, Calendar, Compound, Interpolation, Trait, Currency, knotPoints, out err, baseMarket, CalibrateMktUpdateCondition);
                fittingError = err;
            }
            else
            {
                KeyPoints = YieldCurveCalibrator.Calibrate(name, ReferenceDate, MarketInstruments.ToArray(), Bda, DayCount, Calendar, Compound, Interpolation, Trait, Currency, baseMarket, CalibrateMktUpdateCondition);
            }


            //if (KeyPoints.Select(x => x.Item1).Any(z => z is Date))
            //{
            //	_curve = new Curve<Date>(ReferenceDate, KeyPoints, x => x.ToOADate(), interpolation);
            //}
            _curveXInYears = new Curve <double>(0.0,
                                                KeyPoints.Select(x => Tuple.Create(DayCount.CalcDayCountFraction(ReferenceDate, x.Item1), x.Item2)).ToArray(),
                                                x => x,
                                                Interpolation);
        }
예제 #12
0
        public override void Calc()
        {
            map  = input.Replace("\r", "") + " ";
            mapW = map.IndexOf("\n") + 1;
            mapH = map.Length / mapW;


            LocatePoints();

/*
 *          for (int i = 0; i < mapH; i++)
 *          {
 *              for (int j = 0; j < mapW; j++)
 *              {
 *                  Console.Write(pos(j, i));
 *              }
 *              Console.WriteLine();
 *
 *          }
 */
            var lst = KeyPoints.ToList();

            for (int i = 0; i < lst.Count; i++)
            {
                var p = lst[i];

                if (p.Value == "AA")
                {
                    entrance = p.Key;
                }
                if (p.Value == "ZZ")
                {
                    exit = p.Key;
                }

                var pp = p.Key;
                if (pp.X <= 3 || pp.X >= mapW - 3 || pp.Y <= 3 || pp.Y >= mapH - 3)
                {
                    KeyPoints[p.Key] += "_O";
                }
                else
                {
                    KeyPoints[p.Key] += "_I";
                }

                if (!Links.ContainsKey(KeyPoints[p.Key]))
                {
                    Link l = new Link();
                    l.from = KeyPoints[p.Key];
                    Links.Add(KeyPoints[p.Key], l);
                }
            }
            // Console.WriteLine(entrance);
            // Console.WriteLine(exit);

            Scan();

            lst = KeyPoints.ToList();
            for (int i = 0; i < lst.Count; i++)
            {
                var p = lst[i];
                if (p.Value == "AA_O" || p.Value == "ZZ_O")
                {
                    continue;
                }
                string dir  = p.Value.Substring(3, 1);
                string name = p.Value.Substring(0, 2);

                if (dir == "O")
                {
                    name += "_I";
                }
                else
                {
                    name += "_O";
                }

                Links[p.Value].addLink(name, 1);
            }

            foreach (var item in Links)
            {
                for (int i = 0; i < item.Value.To.Count; i++)
                {
                    //  Console.WriteLine("Path from {0} to {1} takes {2}", item.Value.from, item.Value.To[i], item.Value.Lengths[i]);
                }
            }


            Links["AA_O"].minPath = 0;

            paths.Add(new state(0, "AA_O"), 0);
            toUpdate.Enqueue(new state(0, "AA_O"));

            while (toUpdate.Count > 0)
            {
                var s = toUpdate.Dequeue();

                //Console.WriteLine(s.node+" "+s.layer);

                Links[s.node].Update(s.layer);
            }



            output = "" + (paths[new state(0, "ZZ_O")]);
        }