/// <summary> /// Calculation method. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Redundant parameter, not used in calculations. /// </param> /// <returns> /// Frequency of element in congeneric chain as <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { var count = new ElementsCount(); var length = new Length(); return count.Calculate(chain, link) / length.Calculate(chain, link); }
/// <summary> /// Calculation method. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Link of intervals in chain. /// </param> /// <returns> /// Average remoteness <see cref="double"/> value. /// </returns> public double Calculate(CongenericChain chain, Link link) { double depth = depthCalculator.Calculate(chain, link); int nj = (int)intervalsCount.Calculate(chain, link); return nj == 0 ? 0 : depth / nj; }
/// <summary> /// Calculation method. /// </summary> /// <param name="firstChain"> /// The first chain. /// </param> /// <param name="secondChain"> /// The second chain. /// </param> /// <param name="link"> /// The link. /// </param> /// <returns> /// The <see cref="double"/>. /// </returns> public double Calculate(CongenericChain firstChain, CongenericChain secondChain, Link link) { var partialAccordanceCalculator = new PartialComplianceDegree(); var firstResult = partialAccordanceCalculator.Calculate(firstChain, secondChain, link); var secondResult = partialAccordanceCalculator.Calculate(secondChain, firstChain, link); return Math.Sqrt(firstResult * secondResult); }
/// <summary> /// Initializes a new instance of the <see cref="AccordanceIntervalsManager"/> class. /// </summary> /// <param name="firstChain"> /// The first chain. /// </param> /// <param name="secondChain"> /// The second chain. /// </param> public AccordanceIntervalsManager(CongenericChain firstChain, CongenericChain secondChain) { this.firstChain = firstChain; this.secondChain = secondChain; Length = firstChain.GetLength(); FirstOccurrencesCount = firstChain.OccurrencesCount; SecondOccurrencesCount = secondChain.OccurrencesCount; FillAccordanceIntervals(); }
/// <summary> /// Initializes a new instance of the <see cref="BinaryIntervalsManager"/> class. /// </summary> /// <param name="firstChain"> /// The first chain. /// </param> /// <param name="secondChain"> /// The second chain. /// </param> public BinaryIntervalsManager(CongenericChain firstChain, CongenericChain secondChain) { FirstElement = firstChain.Element; SecondElement = secondChain.Element; FirstChain = firstChain; SecondChain = secondChain; Length = firstChain.GetLength(); PairsCount = FillPairsCount(); relationIntervals = new int[PairsCount]; FillIntervals(); }
/// <summary> /// Initializes a new instance of the <see cref="CongenericIntervalsManager"/> class. /// </summary> /// <param name="chain"> /// The chain. /// </param> public CongenericIntervalsManager(CongenericChain chain) { var positions = chain.Positions; int count = positions.Length; // if sequence is empty if (count == 0) { throw new ArgumentException("Sequence should not be empty", "chain"); } intervals = new int[count - 1]; FillIntervals(positions, chain.GetLength()); }
/// <summary> /// Calculation method. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Link of intervals in chain. /// </param> /// <returns> /// Variations count as <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { int count = 1; for (int i = 0; i < chain.GetLength(); i++) { var j = chain[i] as ValuePhantom; if (j != null) { count *= ((ValuePhantom)chain[i]).Cardinality; } } return count; }
/// <summary> /// Calculation methods. /// </summary> /// <param name="firstChain"> /// The first chain. /// </param> /// <param name="secondChain"> /// The second chain. /// </param> /// <param name="link"> /// The link. /// </param> /// <returns> /// The <see cref="double"/>. /// </returns> public double Calculate(CongenericChain firstChain, CongenericChain secondChain, Link link) { var manager = new AccordanceIntervalsManager(firstChain, secondChain); if (manager.FilteredFirstIntervals.Count == 0) { return 0; } double result = 1; for (int i = 0; i < manager.FilteredFirstIntervals.Count; i++) { result *= LocalCompliance(manager.FilteredFirstIntervals[i], manager.FilteredSecondIntervals[i]); } double firstAndSecondOccurrences = manager.FirstOccurrencesCount + manager.SecondOccurrencesCount; double occurrencesCoefficient = 2.0 * manager.FilteredFirstIntervals.Count / firstAndSecondOccurrences; result = occurrencesCoefficient * Math.Pow(result, 1.0 / manager.FilteredFirstIntervals.Count); return result; }
/// <summary> /// Calculation method. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Redundant parameter, not used in calculations. /// </param> /// <returns> /// Cut length as <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { return CutCommon(chain); }
/// <summary> /// Calculation method. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Link of intervals in chain. /// </param> /// <returns> /// Regularity as <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { return geometricMean.Calculate(chain, link) / descriptiveInformation.Calculate(chain, link); }
/// <summary> /// Calculated as product of all intervals in sequence. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Redundant parameter, not used in calculations. /// </param> /// <returns> /// Volume characteristic of chain as <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { var intervals = chain.GetIntervals(link); return intervals.Length == 0 ? 1 : intervals.Aggregate((result, interval) => result * interval); }
/// <summary> /// Calculation method. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Link of intervals in chain. /// </param> /// <returns> /// Descriptive informations count as <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { var calculator = new ArithmeticMean(); double arithmeticMean = calculator.Calculate(chain, link); return arithmeticMean == 0 ? 1 : Math.Pow(arithmeticMean, 1 / arithmeticMean); }
/// <summary> /// Logarithm of all intervals multiplied. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Link of intervals in chain. /// </param> /// <returns> /// <see cref="double"/> value of alphabetic average remoteness. /// </returns> /// <exception cref="InvalidOperationException"> /// Thrown if method is called not from <see cref="Calculate(Chain,Link)"/> and alphabet cardinality is unknown. /// </exception> /// <exception cref="ArgumentException"> /// Thrown if link is unknown. /// </exception> private double Calculate(CongenericChain chain, Link link) { int[] intervals = chain.GetIntervals(link); return intervals.Length == 0 ? 0 : intervals.Sum(interval => Math.Log(interval, alphabetCardinality)); }
/// <summary> /// Calculation method. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Link of intervals in chain. /// </param> /// <returns> /// Average geometric of intervals lengths as <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { double remoteness = averageRemoteness.Calculate(chain, link); return Math.Pow(2, remoteness); }
/// <summary> /// Calculation method. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Link of intervals in chain. /// </param> /// <returns> /// Identification informations count as <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { double mean = arithmeticMean.Calculate(chain, link); return mean == 0 ? 0 : (-1 / mean) * Math.Log(1 / mean, 2); }
/// <summary> /// Calculation method. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Redundant parameter, not used in calculations. /// </param> /// <returns> /// Chain length as <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { return chain.GetLength(); }
/// <summary> /// Calculation method. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Redundant parameter, not used in calculations. /// </param> /// <returns> /// Cut length vocabulary entropy as <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { return Math.Log(chain.GetLength() - cutLength.Calculate(chain, link) + 1, 2); }
/// <summary> /// Calculation method for congeneric sequences. /// </summary> /// <param name="chain"> /// The congeneric chain. /// </param> /// <param name="link"> /// The link. /// </param> /// <returns> /// The <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { return entropyCalculator.Calculate(chain, link) - remotenessCalculator.Calculate(chain, link); }
public ActionResult Index( long[] matterIds, int characteristicLinkId, Notation notation, Language?language, Translator?translator, PauseTreatment?pauseTreatment, bool?sequentialTransfer, string calculationType) { return(CreateTask(() => { if (matterIds.Length != 2) { throw new ArgumentException("Number of selected matters must be 2.", nameof(matterIds)); } var characteristics = new List <List <double> >(); string characteristicName = characteristicTypeLinkRepository.GetCharacteristicName(characteristicLinkId, notation); var result = new Dictionary <string, object> { { "characteristics", characteristics }, { "matterNames", db.Matter.Where(m => matterIds.Contains(m.Id)).Select(m => m.Name).ToList() }, { "characteristicName", characteristicName }, { "calculationType", calculationType } }; long firstMatterId = matterIds[0]; long secondMatterId = matterIds[1]; long firstSequenceId; long secondSequenceId; switch (notation.GetNature()) { case Nature.Literature: firstSequenceId = db.LiteratureSequence.Single(l => l.MatterId == firstMatterId && l.Notation == notation && l.Language == language && l.Translator == translator).Id; secondSequenceId = db.LiteratureSequence.Single(l => l.MatterId == secondMatterId && l.Notation == notation && l.Language == language && l.Translator == translator).Id; break; case Nature.Music: firstSequenceId = db.MusicSequence.Single(m => m.MatterId == firstMatterId && m.Notation == notation && m.PauseTreatment == pauseTreatment && m.SequentialTransfer == sequentialTransfer).Id; secondSequenceId = db.MusicSequence.Single(m => m.MatterId == secondMatterId && m.Notation == notation && m.PauseTreatment == pauseTreatment && m.SequentialTransfer == sequentialTransfer).Id; break; default: firstSequenceId = db.CommonSequence.Single(c => c.MatterId == firstMatterId && c.Notation == notation).Id; secondSequenceId = db.CommonSequence.Single(c => c.MatterId == secondMatterId && c.Notation == notation).Id; break; } Chain firstChain = commonSequenceRepository.GetLibiadaChain(firstSequenceId); Chain secondChain = commonSequenceRepository.GetLibiadaChain(secondSequenceId); AccordanceCharacteristic accordanceCharacteristic = characteristicTypeLinkRepository.GetCharacteristic(characteristicLinkId); IAccordanceCalculator calculator = AccordanceCalculatorsFactory.CreateCalculator(accordanceCharacteristic); Link link = characteristicTypeLinkRepository.GetLinkForCharacteristic(characteristicLinkId); Alphabet firstChainAlphabet = firstChain.Alphabet; Alphabet secondChainAlphabet = secondChain.Alphabet; switch (calculationType) { case "Equality": if (!firstChainAlphabet.SetEquals(secondChainAlphabet)) { throw new Exception("Alphabets of sequences are not equal."); } characteristics.Add(new List <double>()); characteristics.Add(new List <double>()); var alphabet = new List <string>(); for (int i = 0; i < firstChainAlphabet.Cardinality; i++) { IBaseObject element = firstChainAlphabet[i]; alphabet.Add(element.ToString()); CongenericChain firstCongenericChain = firstChain.CongenericChain(element); CongenericChain secondCongenericChain = secondChain.CongenericChain(element); double characteristicValue = calculator.Calculate(firstCongenericChain, secondCongenericChain, link); characteristics[0].Add(characteristicValue); characteristicValue = calculator.Calculate(secondCongenericChain, firstCongenericChain, link); characteristics[1].Add(characteristicValue); } result.Add("alphabet", alphabet); break; case "All": var firstAlphabet = new List <string>(); for (int i = 0; i < firstChain.Alphabet.Cardinality; i++) { characteristics.Add(new List <double>()); IBaseObject firstElement = firstChainAlphabet[i]; firstAlphabet.Add(firstElement.ToString()); for (int j = 0; j < secondChainAlphabet.Cardinality; j++) { var secondElement = secondChainAlphabet[j]; var firstCongenericChain = firstChain.CongenericChain(firstElement); var secondCongenericChain = secondChain.CongenericChain(secondElement); var characteristicValue = calculator.Calculate(firstCongenericChain, secondCongenericChain, link); characteristics[i].Add(characteristicValue); } } var secondAlphabet = new List <string>(); for (int j = 0; j < secondChainAlphabet.Cardinality; j++) { secondAlphabet.Add(secondChainAlphabet[j].ToString()); } result.Add("firstAlphabet", firstAlphabet); result.Add("secondAlphabet", secondAlphabet); break; case "Specified": throw new NotImplementedException(); default: throw new ArgumentException("Calculation type is not implemented", nameof(calculationType)); } return result; })); }
/// <summary> /// Amount of not empty positions, /// in other words elements count. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Redundant parameter, not used in calculations. /// </param> /// <returns> /// Elements count in chain as <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { return chain.OccurrencesCount; }
/// <summary> /// Calculation method. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Link of intervals in chain. /// </param> /// <returns> /// Periodicity as <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { return geometricMean.Calculate(chain, link) / arithmeticMean.Calculate(chain, link); }
public ActionResult Index( long[] matterIds, int characteristicLinkId, Notation notation, Language?language, Translator?translator, PauseTreatment?pauseTreatment, bool?sequentialTransfer, ImageOrderExtractor?trajectory, string calculationType) { return(CreateTask(() => { if (matterIds.Length != 2) { throw new ArgumentException("Number of selected matters must be 2.", nameof(matterIds)); } var characteristics = new Dictionary <int, Dictionary <int, double> >(); string characteristicName = characteristicTypeLinkRepository.GetCharacteristicName(characteristicLinkId, notation); var result = new Dictionary <string, object> { { "characteristics", characteristics }, { "matterNames", Cache.GetInstance().Matters.Where(m => matterIds.Contains(m.Id)).Select(m => m.Name).ToList() }, { "characteristicName", characteristicName }, { "calculationType", calculationType } }; var sequenceIds = commonSequenceRepository.GetSequenceIds(matterIds, notation, language, translator, pauseTreatment, sequentialTransfer, trajectory); Chain firstChain = commonSequenceRepository.GetLibiadaChain(sequenceIds[0]); Chain secondChain = commonSequenceRepository.GetLibiadaChain(sequenceIds[1]); AccordanceCharacteristic accordanceCharacteristic = characteristicTypeLinkRepository.GetCharacteristic(characteristicLinkId); IAccordanceCalculator calculator = AccordanceCalculatorsFactory.CreateCalculator(accordanceCharacteristic); Link link = characteristicTypeLinkRepository.GetLinkForCharacteristic(characteristicLinkId); Alphabet firstChainAlphabet = firstChain.Alphabet; Alphabet secondChainAlphabet = secondChain.Alphabet; switch (calculationType) { case "Equality": if (!firstChainAlphabet.SetEquals(secondChainAlphabet)) { throw new Exception("Alphabets of sequences are not equal."); } characteristics.Add(0, new Dictionary <int, double>()); characteristics.Add(1, new Dictionary <int, double>()); var alphabet = new List <string>(); for (int i = 0; i < firstChainAlphabet.Cardinality; i++) { IBaseObject element = firstChainAlphabet[i]; alphabet.Add(element.ToString()); CongenericChain firstCongenericChain = firstChain.CongenericChain(element); CongenericChain secondCongenericChain = secondChain.CongenericChain(element); double characteristicValue = calculator.Calculate(firstCongenericChain, secondCongenericChain, link); characteristics[0].Add(i, characteristicValue); characteristicValue = calculator.Calculate(secondCongenericChain, firstCongenericChain, link); characteristics[1].Add(i, characteristicValue); } result.Add("alphabet", alphabet); break; case "All": var firstAlphabet = new List <string>(); for (int i = 0; i < firstChain.Alphabet.Cardinality; i++) { characteristics.Add(i, new Dictionary <int, double>()); IBaseObject firstElement = firstChainAlphabet[i]; firstAlphabet.Add(firstElement.ToString()); for (int j = 0; j < secondChainAlphabet.Cardinality; j++) { var secondElement = secondChainAlphabet[j]; var firstCongenericChain = firstChain.CongenericChain(firstElement); var secondCongenericChain = secondChain.CongenericChain(secondElement); var characteristicValue = calculator.Calculate(firstCongenericChain, secondCongenericChain, link); characteristics[i].Add(j, characteristicValue); } } var secondAlphabet = new List <string>(); for (int j = 0; j < secondChainAlphabet.Cardinality; j++) { secondAlphabet.Add(secondChainAlphabet[j].ToString()); } result.Add("firstAlphabet", firstAlphabet); result.Add("secondAlphabet", secondAlphabet); break; case "Specified": throw new NotImplementedException(); default: throw new ArgumentException("Calculation type is not implemented", nameof(calculationType)); } return new Dictionary <string, string> { { "data", JsonConvert.SerializeObject(result) } }; })); }
/// <summary> /// Calculated as base 2 logarithm of multiplication /// of intervals between nearest elements /// in congeneric sequence. /// </summary> /// <param name="chain"> /// Congeneric sequence. /// </param> /// <param name="link"> /// Link of intervals in chain. /// </param> /// <returns> /// <see cref="double"/> value of depth. /// </returns> public double Calculate(CongenericChain chain, Link link) { var intervals = chain.GetIntervals(link); return intervals.Length == 0 ? 0 : intervals.Sum(interval => Math.Log(interval, 2)); }
/// <summary> /// Calculates multiplication of all intervals /// between nearest elements in congeneric sequence /// divided by number of intervals. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Link of intervals in chain. /// </param> /// <returns> /// <see cref="double"/> value of average arithmetic of intervals lengths. /// </returns> public double Calculate(CongenericChain chain, Link link) { double sum = adder.Calculate(chain, link); int intervalsCount = (int)counter.Calculate(chain, link); return intervalsCount == 0 ? 0 : sum / intervalsCount; }
/// <summary> /// If link is to start, to end or cycle then intervals count equals elements count. /// If link is to start and end then intervals count equals elements count + 1. /// If link is none then intervals count equals elements count - 1. /// </summary> /// <param name="chain"> /// Source sequence. /// </param> /// <param name="link"> /// Link of intervals in chain. /// </param> /// <returns> /// Intervals count in chain as <see cref="double"/>. /// </returns> public double Calculate(CongenericChain chain, Link link) { return chain.GetIntervals(link).Length; }