Esempio n. 1
0
        public SimpleLevelInfo(int[] _partitions, int size, int[] _factorsIndex)
        {
            Size         = size;
            Partitions   = _partitions;
            FactorsIndex = _factorsIndex;
            PatternInfoGenerator generator = new PatternInfoGenerator();

            PatternInfo        = generator.MakePatternInfo(PatternInfoType.Basic, _partitions, size);
            ApplyFactorPattern = generator.MakeFactorPatternInfo(_factorsIndex);
        }
        public void AggregateLowestLevel(ICoverLevelResiduleInfo ResiduleInfo, ICoverLevelTermAriteInfo AriteInfo, ICoverState lowestLevelResiduleState,
                                         ICoverState lowestLevelAriteState, ICoverState ParentState, ICoverAllocationState lowestLevelaRiteAllocationRatio, ICoverAllocationState lowestLevelResidualAllocationRatio)
        {
            float[] ResiduleArr        = lowestLevelResiduleState.GetSubjectLoss();
            float[] aRiteArr           = lowestLevelAriteState.GetSubjectLoss();
            float[] parentArr          = ParentState.GetSubjectLoss();
            int[]   ResidulePartitions = ResiduleInfo.GetResiduleSubAggPartitions();
            int[]   AritePartitions    = AriteInfo.GetARiteAggregationPartitions();
            float[] aRiteRArr          = lowestLevelAriteState.GetSubjectLoss(); //TODO: this should be recoverables
            float[] residualRatio      = lowestLevelResidualAllocationRatio.GetCoverAllocationRatioP();
            float[] aRiteRatio         = lowestLevelaRiteAllocationRatio.GetCoverAllocationRatioP();

            //co-op factors
            float[]       aRiteFactors         = lowestLevelAriteState.GetFactors();    //AriteInfo.GetLowestCoverLevelInfo().LeafCoveraRiteFactors;
            float[]       residualRiteFactors  = lowestLevelResiduleState.GetFactors(); //ResiduleInfo.GetLowestCoverLevelInfo().LeafCoverResidualFactors;
            FactorPattern aRiteFPattern        = AriteInfo.GetLowestCoverLevelInfo().ApplyFactorPatternForaRite;
            FactorPattern residualRiteFPattern = ResiduleInfo.GetLowestCoverLevelInfo().ApplyFactorPatternForResidualRite;

            //pre-process
            float[] newResidualArr;
            float[] newaRiteArr;
            float[] newaRiteRArr;

            //TODO: tricky part, whether apply factor depending on if the allocated Rite recoverable is allocated from
            //summed term or PerRisk term. If allocated from summed term, no need apply factor again; if allocated
            //from PerRisk term, need apply factor
            //right now assuem all the top terms are either summed or PerRisk. This will make this temporarily implementation
            //easier. The Factor List is updated when forming LeafAriteFactor
            if (aRiteFPattern == FactorPattern.AllOnes)
            {
                newaRiteArr  = aRiteArr;
                newaRiteRArr = aRiteRArr;
            }
            else
            {
                newaRiteArr  = aRiteArr.Zip(aRiteFactors, (x1, x2) => x1 * x2).ToArray();
                newaRiteRArr = aRiteRArr.Zip(aRiteFactors, (x1, x2) => x1 * x2).ToArray();
            }

            if (residualRiteFPattern == FactorPattern.AllOnes)
            {
                newResidualArr = ResiduleArr;
            }
            else
            {
                newResidualArr = ResiduleArr.Zip(residualRiteFactors, (x1, x2) => x1 * x2).ToArray();
            }


            SumTwoArrayByPartition(newResidualArr, newaRiteArr, parentArr, ResidulePartitions, AritePartitions, newaRiteRArr, residualRatio, aRiteRatio);
        }
        public CoverLevel(FunctionType _payoutFunctionType, float[] _payoutMultiplier, int _numOfNodes, float[] _share, float[] _codedLim, float[] _codedAttPt,
                          int[] _aggregationPartition, int[] _childrenMap, int[] _factorsIndex, params int[] _leafTopCoverList)
        {
            levelsize             = _numOfNodes;
            Share                 = _share;
            CodedLimit            = _codedLim;
            CodedAttPt            = _codedAttPt;
            AggregationPartitions = _aggregationPartition;
            ChildrenMap           = _childrenMap;
            payoutFunctionType    = _payoutFunctionType;
            PayOutMultiplier      = _payoutMultiplier;
            leafTopCoverList      = _leafTopCoverList;
            FactorsIndex          = _factorsIndex;
            PatternInfoGenerator generator = new PatternInfoGenerator();

            ApplyFactorPattern = generator.MakeFactorPatternInfo(_factorsIndex);
        }
        public LowestCoverLevelInfo(int _numOfArites, int _numOfResidules, int[] _residuleSubAggPartitions, int[] _ariteAggPartitions, int[] _gulossIndices,
                                    int[] _recoverableLevelIndex, int[] _recoverableIndices, int[] _ariteGULossIndicies, int[] _leafCoveraRiteFactorsIndex, int[] _leafCoverResidualFactorsIndex)
        {
            NumOfArites                   = _numOfArites;
            NumOfResidules                = _numOfResidules;
            ResiduleSubAggPartitions      = _residuleSubAggPartitions;
            AriteAggPartitions            = _ariteAggPartitions;
            GULossIndices                 = _gulossIndices;
            RecoverableLevelIndex         = _recoverableLevelIndex;
            RecoverableIndices            = _recoverableIndices;
            LeafCoveraRiteFactorsIndex    = _leafCoveraRiteFactorsIndex;
            LeafCoverResidualFactorsIndex = _leafCoverResidualFactorsIndex;
            PatternInfoGenerator generator = new PatternInfoGenerator();

            ApplyFactorPatternForaRite        = generator.MakeFactorPatternInfo(_leafCoveraRiteFactorsIndex);
            ApplyFactorPatternForResidualRite = generator.MakeFactorPatternInfo(_leafCoverResidualFactorsIndex);
            AriteGULossIndices = _ariteGULossIndicies;
        }
Esempio n. 5
0
        public static Summand Parse(string input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (!SummandPattern.IsMatch(input))
            {
                throw new FormatException("Invalid format.");
            }


            string sFactor = FactorPattern.Match(input).Value;

            sFactor = AddImplicitOneAsNeeded(sFactor);

            var factor    = float.Parse(sFactor);
            var variables = VariablePattern.Matches(input)
                            .Cast <Match>().Select(m => Variable.Parse(m.Value));

            return(new Summand(factor, variables));
        }
        public void AggregateLevel(ISimpleLevelState childLevel, ILevelState parentLevel, ILevelAtomicRITEInfo aRITEINfo)
        {
            int             childlevelsize = aRITEINfo.NumOfARITEs;
            IAggPatternInfo patterinInfo   = aRITEINfo.GetARitePatternInfo();

            int[]         partitions = aRITEINfo.GetARiteAggregationPartitions();
            float[]       factors    = childLevel.GetFactors(); //aRITEINfo.GetaRiteInfo().Factors;
            FactorPattern fPattern   = aRITEINfo.GetaRiteInfo().ApplyFactorPattern;

            //pre-process for factor
            float[] childrenLoss;
            if (fPattern == FactorPattern.AllOnes)
            {
                childrenLoss = childLevel.GetSubjectLoss();
            }
            else
            {
                childrenLoss = childLevel.GetSubjectLoss().Zip(factors, (x1, x2) => x1 * x2).ToArray();
            }

            switch (patterinInfo.GetLevelRelation)
            {
            case AggRelationship.OneToOne:
                Array.Copy(childrenLoss, parentLevel.GetSubjectLoss(), childlevelsize);
                break;

            case AggRelationship.RepeatedPattern:
                int groupSize = patterinInfo.RepeatedPartitionSize;
                SumArrayByPattern(childrenLoss, parentLevel.GetSubjectLoss(), groupSize);
                break;

            case AggRelationship.NoPattern:
                SumArrayByPartition(childrenLoss, parentLevel.GetSubjectLoss(), partitions);
                break;
            }
        }
        private void AggregateMixSubject(int ParentPosition, ICoverState TotalCoverState, ICoverLevelNodeAggInfo LevelAggInfo, IDerivedCoverLevelNodeAggInfo DerivedInfo, float[] coverRatio, float[] FactorVector)
        {
            //TODO: for agg is fine, but for allocation we cannot use this method
            throw new NotSupportedException("Mix Derived cover subject is not supported");
            int[]   ChildrenMap       = LevelAggInfo.GetChildrenMap();
            int[]   MapPartitions     = LevelAggInfo.GetCoverAggregationPartitions();
            float[] TotalPayoutState  = TotalCoverState.GetPayout();
            float[] TotalSubjectState = TotalCoverState.GetSubjectLoss();
            int     MapPosition       = 1;
            float   TempSubject       = 0;
            float   ChildR            = 0;
            float   x = 0;

            float[] multiplier = DerivedInfo.GetMixFunctionMultiplier();
            //float[] factors = LevelAggInfo.GetFactor();
            int[] factorsIndex = LevelAggInfo.GetFactorIndex();
            int   counter      = factorsIndex.Count();

            float[] factors = new float[counter];
            for (int i = 0; i < counter; i++)
            {
                int uniqueIndex = factorsIndex[i];
                if (uniqueIndex == -1)
                {
                    factors[i] = 1;
                }
                else
                {
                    factors[i] = FactorVector[uniqueIndex];
                }
            }
            FactorPattern factorPattern = LevelAggInfo.GetLevelFactorPattern();

            if (factorPattern == FactorPattern.AllOnes || factorPattern == FactorPattern.Constant)
            {
                for (int i = 0; i < MapPartitions.Length; i++)
                {
                    TempSubject = TotalPayoutState[ChildrenMap[0]];
                    x           = multiplier[i];

                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        ChildR      = TotalPayoutState[ChildrenMap[j]];
                        TempSubject = (TempSubject + ChildR) - x * Math.Abs(TempSubject - ChildR) - Math.Abs(x) * (TempSubject + ChildR);
                    }
                    TotalSubjectState[ParentPosition] = TempSubject * factors[MapPosition];
                    MapPosition += MapPartitions[i];
                    ParentPosition++;
                }
            }
            else
            {
                for (int i = 0; i < MapPartitions.Length; i++)
                {
                    TempSubject = TotalPayoutState[ChildrenMap[0]] * factors[0];
                    x           = multiplier[i];

                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        ChildR      = TotalPayoutState[ChildrenMap[j]] * factors[j];
                        TempSubject = (TempSubject + ChildR) - x * Math.Abs(TempSubject - ChildR) - Math.Abs(x) * (TempSubject + ChildR);
                    }
                    TotalSubjectState[ParentPosition] = TempSubject;
                    MapPosition += MapPartitions[i];
                    ParentPosition++;
                }
            }
        }
        private void AggregateMaxSubject(int ParentPosition, ICoverState TotalCoverState, ICoverLevelNodeAggInfo LevelAggInfo, float[] coverRatio, float[] FactorVector)
        {
            int[]   ChildrenMap       = LevelAggInfo.GetChildrenMap();
            int[]   MapPartitions     = LevelAggInfo.GetCoverAggregationPartitions();
            float[] TotalPayoutState  = TotalCoverState.GetPayout();
            float[] TotalSubjectState = TotalCoverState.GetSubjectLoss();
            //float[] factors = LevelAggInfo.GetFactor();
            int[] factorsIndex = LevelAggInfo.GetFactorIndex();
            int   counter      = factorsIndex.Count();

            float[] factors = new float[counter];
            for (int i = 0; i < counter; i++)
            {
                int uniqueIndex = factorsIndex[i];
                if (uniqueIndex == -1)
                {
                    factors[i] = 1;
                }
                else
                {
                    factors[i] = FactorVector[uniqueIndex];
                }
            }
            FactorPattern factorPattern = LevelAggInfo.GetLevelFactorPattern();

            int   MapPosition = 1;
            float MaxSubject  = 0;
            int   numOfMax    = 0;

            if (factorPattern == FactorPattern.AllOnes || factorPattern == FactorPattern.Constant)
            {
                for (int i = 0; i < MapPartitions.Length; i++) //for each parent
                {
                    //MaxSubject = TotalPayoutState[ChildrenMap[0]];
                    //MaxSubject = 0;
                    MaxSubject = TotalPayoutState[ChildrenMap[MapPosition - 1]] * factors[MapPosition - 1];
                    numOfMax   = 0;

                    for (int j = MapPosition + 1; j <= MapPartitions[i]; j++)
                    {
                        float temp = TotalPayoutState[ChildrenMap[j - 1]] * factors[j - 1];
                        MaxSubject = Math.Max(MaxSubject, temp);
                    }

                    //ratio
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        if (MaxSubject == TotalPayoutState[ChildrenMap[j]] * factors[j])
                        {
                            coverRatio[j - 1] = 1;
                            numOfMax++;
                        }
                    }

                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        coverRatio[j - 1] /= numOfMax;
                    }

                    TotalSubjectState[ParentPosition] = MaxSubject * factors[MapPosition];
                    //MapPosition += MapPartitions[i];
                    MapPosition = MapPartitions[i] + 1;
                    ParentPosition++;
                }
            }
            else
            {
                for (int i = 0; i < MapPartitions.Length; i++) //for each parent
                {
                    MaxSubject = TotalPayoutState[ChildrenMap[MapPosition - 1]] * factors[MapPosition - 1];
                    numOfMax   = 0;

                    for (int j = MapPosition + 1; j <= MapPartitions[i]; j++)
                    {
                        float temp = TotalPayoutState[ChildrenMap[j - 1]] * factors[j - 1];
                        MaxSubject = Math.Max(MaxSubject, temp);
                    }

                    //ratio
                    for (int j = MapPosition; j <= MapPartitions[i]; j++)
                    {
                        if (MaxSubject == TotalPayoutState[ChildrenMap[j - 1]] * factors[j - 1])
                        {
                            coverRatio[j - 1] = 1;
                            numOfMax++;
                        }
                    }

                    for (int j = MapPosition; j <= MapPartitions[i]; j++)
                    {
                        coverRatio[j - 1] /= numOfMax;
                    }

                    TotalSubjectState[ParentPosition] = MaxSubject;
                    //MapPosition += MapPartitions[i];
                    MapPosition = MapPartitions[i] + 1;
                    ParentPosition++;
                }
            }
        }
        private void AggregateSumSubject(int ParentPosition, ICoverState TotalCoverState, ICoverLevelNodeAggInfo LevelAggInfo, float[] coverRatio, float[] FactorVector)
        {
            int[]   ChildrenMap       = LevelAggInfo.GetChildrenMap();
            int[]   MapPartitions     = LevelAggInfo.GetCoverAggregationPartitions();
            float[] TotalPayoutState  = TotalCoverState.GetPayout();
            float[] TotalSubjectState = TotalCoverState.GetSubjectLoss();
            int     MapPosition       = 0;

            int[] factorsIndex = LevelAggInfo.GetFactorIndex();
            int   counter      = factorsIndex.Count();

            float[] factors = new float[counter];
            for (int i = 0; i < counter; i++)
            {
                int uniqueIndex = factorsIndex[i];
                if (uniqueIndex == -1)
                {
                    factors[i] = 1;
                }
                else
                {
                    factors[i] = FactorVector[uniqueIndex];
                }
            }

            FactorPattern factorPattern = LevelAggInfo.GetLevelFactorPattern();

            if (factorPattern == FactorPattern.AllOnes || factorPattern == FactorPattern.Constant)
            {
                for (int i = 0; i < MapPartitions.Length; i++)
                {
                    float ParentSubject = 0;
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        ParentSubject += TotalPayoutState[ChildrenMap[j]] * factors[j];  //denominator
                    }

                    //ratio
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        coverRatio[j] = (ParentSubject == 0) ? 0 : TotalPayoutState[ChildrenMap[j]] * factors[j] / ParentSubject;
                    }

                    TotalSubjectState[ParentPosition] = ParentSubject;
                    MapPosition = MapPartitions[i] + 1;
                    ParentPosition++;
                }
            }
            else
            {
                for (int i = 0; i < MapPartitions.Length; i++)
                {
                    float ParentSubject = 0;
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        ParentSubject += TotalPayoutState[ChildrenMap[j]] * factors[j];  //denominator
                    }

                    //ratio
                    for (int j = MapPosition; j < MapPartitions[i]; j++)
                    {
                        coverRatio[j] = (ParentSubject == 0) ? 0 : TotalPayoutState[ChildrenMap[j]] * factors[j] / ParentSubject;
                    }

                    TotalSubjectState[ParentPosition] = ParentSubject;
                    MapPosition = MapPartitions[i] + 1;
                    ParentPosition++;
                }
            }
        }
Esempio n. 10
0
        public void AggregateLevel(ILevelState childLevel, ISimpleLevelState childARITELevel, ILevelState parentLevel, ILevelNodeAggInfo childAggInfo, ILevelAtomicRITEInfo aRITEINfo, Stopwatch aggregation1)
        {
            int             childlevelsize = childAggInfo.NumOfNodes;
            IAggPatternInfo patterinInfo   = childAggInfo.GetNodePatternInfo();

            int[] partitions = childAggInfo.GetNodeAggregationPartitions();

            IAggPatternInfo aRITEpatterinInfo = aRITEINfo.GetARitePatternInfo();

            int[] aRITEpartitions = aRITEINfo.GetARiteAggregationPartitions();

            float[]       nodeFactors  = childLevel.GetFactors();      //childAggInfo.GetSimpleLevelInfo().Factors;
            float[]       riteFactor   = childARITELevel.GetFactors(); //aRITEINfo.GetaRiteInfo().Factors;
            FactorPattern nodeFPattern = childAggInfo.GetSimpleLevelInfo().ApplyFactorPattern;
            FactorPattern riteFPattern = aRITEINfo.GetaRiteInfo().ApplyFactorPattern;

            float[] childrenDed;
            float[] childrenExcess;

            //pre-process to multiply the Factor array
            if (nodeFPattern == FactorPattern.AllOnes)
            {
                childrenDed    = childLevel.GetDeductible();
                childrenExcess = childLevel.GetExcess();
            }
            else
            {
                childrenDed    = childLevel.GetDeductible().Zip(nodeFactors, (x1, x2) => x1 * x2).ToArray();
                childrenExcess = childLevel.GetExcess().Zip(nodeFactors, (x1, x2) => x1 * x2).ToArray();
            }

            //Aggregate D and X (ARITEs do not have D, X)
            switch (patterinInfo.GetLevelRelation)
            {
            case AggRelationship.OneToOne:
                Array.Copy(childrenDed, parentLevel.GetDeductible(), childlevelsize);
                Array.Copy(childrenExcess, parentLevel.GetExcess(), childlevelsize);
                break;

            case AggRelationship.RepeatedPattern:
                int groupSize = patterinInfo.RepeatedPartitionSize;
                SumArrayByPattern(childrenDed, parentLevel.GetDeductible(), groupSize);
                SumArrayByPattern(childrenExcess, parentLevel.GetExcess(), groupSize);
                break;

            case AggRelationship.NoPattern:
                SumArrayByPartition(childrenDed, parentLevel.GetDeductible(), partitions);

                aggregation1.Start();
                SumArrayByPartition(childrenExcess, parentLevel.GetExcess(), partitions);
                aggregation1.Stop();
                break;
            }

            // Aggregate S in case with Atomic Rites & Aggregate R for allocation
            float[] childrenNodeSubLoss;
            float[] childrenRiteSubLoss;
            float[] childrenRecov;

            if (nodeFPattern == FactorPattern.AllOnes)
            {
                childrenNodeSubLoss = childLevel.GetSubjectLoss();
                childrenRecov       = childLevel.GetRecoverable();
            }
            else
            {
                childrenNodeSubLoss = childLevel.GetSubjectLoss().Zip(nodeFactors, (x1, x2) => x1 * x2).ToArray();
                childrenRecov       = childLevel.GetRecoverable().Zip(nodeFactors, (x1, x2) => x1 * x2).ToArray();
            }

            if (aRITEINfo.HasAtomicRITEs)
            {
                //pre-process
                if (riteFPattern == FactorPattern.AllOnes)
                {
                    childrenRiteSubLoss = childARITELevel.GetSubjectLoss();
                }
                else
                {
                    childrenRiteSubLoss = childARITELevel.GetSubjectLoss().Zip(riteFactor, (x1, x2) => x1 * x2).ToArray();
                }

                if (aRITEpatterinInfo.GetLevelRelation == AggRelationship.NoPattern ||
                    patterinInfo.GetLevelRelation == AggRelationship.NoPattern)
                {
                    SumTwoArrayByPartition(childrenNodeSubLoss, childrenRiteSubLoss, parentLevel.GetSubjectLoss(), partitions, aRITEpartitions);
                    SumTwoArrayByPartition(childrenRecov, childrenRiteSubLoss, parentLevel.GetRecoverable(), partitions, aRITEpartitions);
                }
                else
                {
                    int termgroupsize;
                    int aRITEgroupsize;

                    switch (patterinInfo.GetLevelRelation)
                    {
                    case AggRelationship.OneToOne:
                        termgroupsize = 1;
                        break;

                    case AggRelationship.RepeatedPattern:
                        termgroupsize = aRITEpatterinInfo.RepeatedPartitionSize;
                        break;

                    default:
                        throw new NotSupportedException("The Level realtion " + patterinInfo.GetLevelRelation + " is currently not supported");
                    }

                    switch (aRITEpatterinInfo.GetLevelRelation)
                    {
                    case AggRelationship.OneToOne:
                        aRITEgroupsize = 1;
                        break;

                    case AggRelationship.RepeatedPattern:
                        aRITEgroupsize = aRITEpatterinInfo.RepeatedPartitionSize;
                        break;

                    default:
                        throw new NotSupportedException("The Level realtion " + patterinInfo.GetLevelRelation + " is currently not supported");
                    }

                    SumTwoArrayByPatternNew(childrenNodeSubLoss, childrenRiteSubLoss, parentLevel.GetSubjectLoss(), termgroupsize, aRITEgroupsize);
                    SumTwoArrayByPatternNew(childrenRecov, childrenRiteSubLoss, parentLevel.GetRecoverable(), termgroupsize, aRITEgroupsize);
                }
            }
            // Aggregate S in case with no Atomic Rites
            else
            {
                switch (patterinInfo.GetLevelRelation)
                {
                case AggRelationship.OneToOne:
                    Array.Copy(childrenNodeSubLoss, parentLevel.GetSubjectLoss(), childlevelsize);
                    Array.Copy(childrenRecov, parentLevel.GetRecoverable(), childlevelsize);
                    break;

                case AggRelationship.RepeatedPattern:
                    int groupSize = patterinInfo.RepeatedPartitionSize;
                    SumArrayByPattern(childrenNodeSubLoss, parentLevel.GetSubjectLoss(), groupSize);
                    SumArrayByPattern(childrenRecov, parentLevel.GetRecoverable(), groupSize);
                    break;

                case AggRelationship.NoPattern:
                    SumArrayByPartition(childrenNodeSubLoss, parentLevel.GetSubjectLoss(), partitions);
                    SumArrayByPartition(childrenRecov, parentLevel.GetRecoverable(), partitions);
                    break;
                }
            }
        }