public AssociationsLookup CreateAssociations(SenseInputs senseInputs) { var associations = new AssociationsLookup(); foreach (var senseInput in senseInputs) { var otherSenseInputs = senseInputs.Where(s => s.Key != senseInput.Key); var associationsDictionary = otherSenseInputs .Select(o => new KeyValuePair <string, double>(o.Key, o.Value * senseInput.Value)) .ToDictionary(x => x.Key, x => x.Value); //var normalisedAssociationsDictionary = mathsService.NormaliseAssociations(new Associations(associationsDictionary)); associations.Add(senseInput.Key, new Associations(associationsDictionary)); } return(associations); }
/// <summary> /// Associations1 will be multiplied by the weightFactor then added to associations2. The result will be normalised. /// </summary> /// <param name="associations1"></param> /// <param name="associations2"></param> /// <param name="weightFactor"></param> /// <returns></returns> public AssociationsLookup AddAssociationLookups(AssociationsLookup associationsLookup1, AssociationsLookup associationsLookup2, double weightFactor) { var otherWeightFactor = 1 - weightFactor; var combinedAssociationsLookup = new AssociationsLookup(); foreach (var associationEntry in associationsLookup1) { var key = associationEntry.Key; var associations = new Associations(); var weightedAssociations1 = associationEntry.Value.Select(x => new KeyValuePair <string, double>(x.Key, x.Value * weightFactor)); var associations2 = associationsLookup2[key]; var combinedAssociations = weightedAssociations1.ToDictionary(x => x.Key, x => x.Value + associations2[x.Key] * otherWeightFactor); combinedAssociationsLookup.Add(key, new Associations(combinedAssociations)); } return(combinedAssociationsLookup); }