コード例 #1
0
        /// <summary>
        /// Applies the specified inputs.
        /// </summary>
        /// <param name="inputs">The inputs.</param>
        /// <param name="featureBuckets">The feature buckets.</param>
        /// <param name="priors">The priors.</param>
        /// <param name="results">The results.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="showFactorGraph">if set to <c>true</c> [show factor graph].</param>
        /// <exception cref="System.NotImplementedException">Not implemented for this model</exception>
        public virtual void Apply(Inputs inputs, FeatureSet featureBuckets, Priors priors, ref Results results, InputMode mode, bool showFactorGraph = false)
        {
            this.Engine.ShowFactorGraph = showFactorGraph;

            if (mode.HasFlag(InputMode.Validation))
            {
                this.SetObservedValues(inputs.Validation.Instances, featureBuckets, InputMode.Validation, priors);
                results.Validation = new Results.ResultsSet {
                    IsRepliedTo = this.Engine.Infer <Bernoulli[]>(this.RepliedTo)
                };
            }

            if (mode.HasFlag(InputMode.Testing))
            {
                this.SetObservedValues(inputs.Test.Instances, featureBuckets, InputMode.Testing, priors);
                results.Test = new Results.ResultsSet {
                    IsRepliedTo = this.Engine.Infer <Bernoulli[]>(this.RepliedTo)
                };
            }

            if (mode.HasFlag(InputMode.TrainAndValidation))
            {
                this.SetObservedValues(inputs.TrainAndValidation.Instances, featureBuckets, InputMode.TrainAndValidation, priors);
                results.Validation = new Results.ResultsSet {
                    IsRepliedTo = this.Engine.Infer <Bernoulli[]>(this.RepliedTo)
                };
            }

            this.Engine.ShowFactorGraph = this.ShowFactorGraph;
        }
コード例 #2
0
        internal override void RemoveKey(IEntityKey key)
        {
            base.RemoveKey(key);
            var job = key as JobKey;

            if (job != null && Priors != null)
            {
                Priors.Remove(job);
            }
            var res = key as ResourceKey;

            if (res != null && Resources != null)
            {
                Resources.Remove(res);
            }
        }
コード例 #3
0
ファイル: ModelRunner.cs プロジェクト: raudut/Infernet-asthme
        /// <summary>
        /// The three player toy experiment.
        /// </summary>
        public void ThreePlayerToyExperiment()
        {
            var players  = new[] { "Jill", "Fred", "Steve" };
            var scores   = new[] { new[] { 2, 1, 0 }, new[] { 1, 2, 0 } };
            var outcomes =
                scores.Select(s => players.Zip(s, (p, score) => new { p, score }).ToDictionary(ia => ia.p, ia => ia.score)).ToArray();

            var inputs = Inputs <MultiPlayerGame> .CreateToyInputs(outcomes);

            outputter.Out(inputs,
                          Contents.S4ExtensionsToTheCoreModel.NumberedName,
                          "ThreePlayerToyExperiment",
                          "Inputs");

            // Rerun first game with different variances
            var priors = new Priors
            {
                Skills =
                {
                    { "Jill",  new Gaussian(120,                    400) },
                    { "Fred",  new Gaussian(100, inputs.InitialVariance) },
                    { "Steve", new Gaussian(140, inputs.InitialVariance) }
                }
            };


            var model = new MultiPlayer(inputs.TrueSkillParameters, ShowFactorGraph);
            var threePlayerToyExperiment = new[]
            {
                new ToyExperiment(model, inputs.Games[0], priors),
                new ToyExperiment(model, inputs.Games[1], priors)
            };

            outputter.Out(threePlayerToyExperiment,
                          Contents.S4ExtensionsToTheCoreModel.NumberedName,
                          "ThreePlayerToyExperiment",
                          "Experiments");
        }
コード例 #4
0
        private static void AgentIsRival_Postfix(Agent myAgent, StatusEffects __instance, ref bool __result)
        {
            // All custom Social traits with Rivalry & XP bonus

            Agent otherAgent = __instance.agent;

            if (MobDebt.AgentIsRival(myAgent, otherAgent) || BootLicker.AgentIsRival(myAgent, otherAgent) || Priors.AgentIsRival(myAgent, otherAgent))
            {
                __result = true;
            }
        }
コード例 #5
0
        /// <summary>
        /// Sets the observed values.
        /// </summary>
        /// <param name="instances">The instances.</param>
        /// <param name="featureSet">The feature buckets.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="priors">The priors.</param>
        /// <exception cref="System.InvalidOperationException">Data is null</exception>
        public override void SetObservedValues(IList <Inputs.Instance> instances, FeatureSet featureSet, InputMode mode, Priors priors)
        {
            if (instances == null)
            {
                throw new InvalidOperationException("Data is null");
            }

            this.NumberOfMessages.ObservedValue = instances.Count;
            this.FeatureValue.ObservedValue     = instances.Select(ia => ia.FeatureValues.First().Value).ToArray();
            this.NoiseVariance.ObservedValue    = priors.NoiseVariance;

            if (mode == InputMode.Training)
            {
                // No priors - this is training
                this.RepliedTo.ObservedValue      = instances.Select(ia => ia.Label).ToArray();
                this.WeightPrior.ObservedValue    = priors.Weights.First().Value;
                this.ThresholdPrior.ObservedValue = priors.Threshold;
            }
            else
            {
                // This is testing, don't set isRepliedTo observed values
                this.RepliedTo.ClearObservedValue();
                this.WeightPrior.ObservedValue    = priors.Weights.First().Value;
                this.ThresholdPrior.ObservedValue = priors.Threshold;
            }
        }
コード例 #6
0
        private static void SetupRelationshipOriginal_Postfix(Agent otherAgent, Relationships __instance, ref Agent ___agent)
        {
            // Relationships defines how ___agent feels about otherAgent
            // Don't delete this comment, it gets confusing-er-than-shit

            if (GameController.gameController.levelType == nameof(InterfaceNameDB.rowIds.HomeBase))
            {
                __instance.SetRelInitial(otherAgent, nameof(relStatus.Aligned));
                otherAgent.relationships.SetRelInitial(___agent, nameof(relStatus.Aligned));

                return;
            }

            string currentRelationship = __instance.GetRel(otherAgent);

            if (currentRelationship == null)
            {
                logger.LogWarning("SetupRelationshipOriginal - currentRelationship was null!");

                return;
            }

            relStatus?newRelationship;

            if (___agent.IsAgent(AgentNameDB.rowIds.ResistanceLeader) && otherAgent.isPlayer > 0)
            {
                newRelationship = relStatus.Aligned;
            }
            else
            {
                // Order matters here, the first non-Null relStatus will be used.
                newRelationship =
                    MobDebt.SetupInitialRelationship(___agent, otherAgent, currentRelationship)
                    ?? Domineering.SetupInitialRelationship(___agent, otherAgent, currentRelationship)
                    ?? Domineering2.SetupInitialRelationship(___agent, otherAgent, currentRelationship)
                    ?? Polarizing.SetupInitialRelationship(___agent, otherAgent, currentRelationship)
                    ?? Polarizing2.SetupInitialRelationship(___agent, otherAgent, currentRelationship)
                    ?? BootLicker.SetupInitialRelationship(___agent, otherAgent, currentRelationship)
                    ?? Priors.SetupInitialRelationship(___agent, otherAgent, currentRelationship)
                    ?? GenerallyUnpleasant.SetupInitialRelationship(___agent, otherAgent, currentRelationship)
                    ?? ObjectivelyUnpleasant.SetupInitialRelationship(___agent, otherAgent, currentRelationship);
            }

            if (newRelationship != null)
            {
                string relationshipString = newRelationship.Value.ToString();
                __instance.SetRelInitial(otherAgent, relationshipString);
                otherAgent.relationships.SetRelInitial(___agent, relationshipString);

                if (newRelationship.Value == relStatus.Annoyed)
                {
                    otherAgent.relationships.SetStrikes(___agent, 2);
                    __instance.SetStrikes(otherAgent, 2);
                }
                else if (newRelationship.Value == relStatus.Hostile)
                {
                    otherAgent.relationships.SetStrikes(___agent, 5);
                    __instance.SetStrikes(otherAgent, 5);
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Sets the observed values.
        /// </summary>
        /// <param name="instances">The instances.</param>
        /// <param name="featureSet">The feature set.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="priors">The priors.</param>
        /// <exception cref="System.InvalidOperationException">Data is null</exception>
        public override void SetObservedValues(IList <Inputs.Instance> instances, FeatureSet featureSet, InputMode mode, Priors priors)
        {
            if (instances == null)
            {
                throw new InvalidOperationException("Data is null");
            }

            this.NumberOfMessages.ObservedValue = instances.Count;
            this.NumberOfFeatures.ObservedValue = featureSet.FeatureVectorLength;

            this.NoiseVariance.ObservedValue = priors.NoiseVariance;

            if (mode == InputMode.Training)
            {
                this.RepliedTo.ObservedValue      = instances.Select(ia => ia.Label).ToArray();
                this.WeightPriors.ObservedValue   = DistributionArrayHelpers.DistributionArray(priors.Weights.Values);
                this.ThresholdPrior.ObservedValue = priors.Threshold;
            }
            else
            {
                // This is testing, don't set isRepliedTo observed values
                this.RepliedTo.ClearObservedValue();
                this.WeightPriors.ObservedValue   = DistributionArrayHelpers.Copy(priors.Weights.Values);
                this.ThresholdPrior.ObservedValue = priors.Threshold;
            }

            // Convert feature values to dense jagged array
            var featureValues = new double[instances.Count][];

            for (int i = 0; i < instances.Count; i++)
            {
                featureValues[i] = new double[featureSet.FeatureVectorLength];
                foreach (var featureBucketValue in instances[i].FeatureValues)
                {
                    int index = instances[i].FeatureSet.FeatureBuckets.IndexOf(featureBucketValue.Key);
                    if (index < 0)
                    {
                        throw new InvalidOperationException("Bucket index not found");
                    }

                    featureValues[i][index] = featureBucketValue.Value;
                }
            }

            this.FeatureValue.ObservedValue = featureValues;
        }
コード例 #8
0
 /// <summary>
 /// Sets the observed values.
 /// </summary>
 /// <param name="instances">The instances.</param>
 /// <param name="featureSet">The feature buckets.</param>
 /// <param name="mode">The mode.</param>
 /// <param name="priors">The priors.</param>
 public abstract void SetObservedValues(IList <Inputs.Instance> instances, FeatureSet featureSet, InputMode mode, Priors priors);
コード例 #9
0
        /// <summary>
        /// Sets the observed values.
        /// </summary>
        /// <param name="instances">The instances.</param>
        /// <param name="featureSet">The feature buckets.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="priors">The priors.</param>
        /// <exception cref="System.InvalidOperationException">Data is null</exception>
        /// <exception cref="System.ArgumentNullException">parameters;@Mode expected in parameters</exception>
        /// <exception cref="System.ArgumentException"></exception>
        public override void SetObservedValues(IList <Inputs.Instance> instances, FeatureSet featureSet, InputMode mode, Priors priors)
        {
            if (instances == null)
            {
                throw new InvalidOperationException("Data is null");
            }

            this.NumberOfMessages.ObservedValue = instances.Count;
            this.NumberOfFeatures.ObservedValue = featureSet.FeatureVectorLength;

            this.NoiseVariance.ObservedValue = priors.NoiseVariance;

            if (mode == InputMode.Training)
            {
                this.RepliedTo.ObservedValue    = instances.Select(ia => ia.Label).ToArray();
                this.WeightPriors.ObservedValue = DistributionArrayHelpers.DistributionArray(priors.Weights.Values);
            }
            else
            {
                // This is testing, don't set isRepliedTo observed values
                this.WeightPriors.ObservedValue = DistributionArrayHelpers.Copy(priors.Weights.Values);
            }

            var featureIndices = featureSet.FeatureBuckets.Select((ia, i) => new { ia, i }).ToDictionary(anon => anon.ia, anon => anon.i);

            this.FeatureIndices.ObservedValue =
                instances.Select(ia => ia.FeatureValues.Select(fbv => featureIndices[fbv.Key]).ToArray()).ToArray();

            this.FeatureValue.ObservedValue  = instances.Select(ia => ia.FeatureValues.Select(fbv => fbv.Value).ToArray()).ToArray();
            this.FeatureCounts.ObservedValue = this.FeatureIndices.ObservedValue.Select(ia => ia.Length).ToArray();
        }