Exemplo n.º 1
0
    public void Initialize(int m_HiddenLayers, ThoughtProcess thoughtProcess)
    {
        this.thoughtProcess    = thoughtProcess;
        thoughtProcessStringed = thoughtProcess.GetThoughtAsString();
        hiddenLayers           = new NeuralNetworkNode[m_HiddenLayers];
        for (int i = 0; i < m_HiddenLayers; i++)
        {
            hiddenLayers[i] = new NeuralNetworkNode();
        }

        foreach (var layer in hiddenLayers)
        {
            layer.SetBias(thoughtProcess.GetNext());
            for (int i = 0; i < inputLayer.Length; i++)
            {
                layer.ConnectTo(inputLayer[i], thoughtProcess.GetNext());
            }
        }

        foreach (var layer in outputLayer)
        {
            layer.SetBias(thoughtProcess.GetNext());
            for (int i = 0; i < hiddenLayers.Length; i++)
            {
                layer.ConnectTo(hiddenLayers[i], thoughtProcess.GetNext());
            }
        }

        if (!thoughtProcess.HasNoNext())
        {
            Debug.LogWarning("INputnodes, hidden nodes, or output node amount is wrong, is at " + thoughtProcess.GetCurrentIndex() + " but expected " + thoughtProcess.biasAndWeights.Length);
        }
    }
    public ThoughtProcess ProduceChild(int thoughtProcessSize, float processThoughtRandomnessRange)
    {
        var chance = UnityEngine.Random.Range(0, 100);

        if (chance < randomPercentage)
        {
            return(new ThoughtProcess(thoughtProcessSize, processThoughtRandomnessRange));
        }
        else
        {
            int firstParent  = random.Next(topAmountToUse);
            int secondParent = 0;
            while (topAmountToUse > 1 && firstParent == secondParent)
            {
                secondParent = random.Next(topAmountToUse);
            }
            var child = new ThoughtProcess(bestThoughtProcesses[firstParent].process, bestThoughtProcesses[secondParent].process);

            if (chance < randomPercentage + mutatePercentage)
            {
                Tweak(child, thoughtProcessSize, processThoughtRandomnessRange);
                return(child);
            }
            else
            {
                return(child);
            }
        }
    }
 private void Tweak(ThoughtProcess thoughtProcesses, int thoughtProcessSize, float processThoughtRandomnessRange)
 {
     for (int x = 0; x < maxProcessSizeToTweak; x++)
     {
         thoughtProcesses.biasAndWeights[random.Next(thoughtProcessSize - 1)] = random.Next(Mathf.RoundToInt(processThoughtRandomnessRange));
     }
 }
 public void CreateInitialThoughtProcesses(int thoughtProcessSize, float processThoughtRandomnessRange)
 {
     for (int i = bestThoughtProcesses.Count; i < topAmountToUse; i++)
     {
         var process = new ThoughtProcess(thoughtProcessSize, processThoughtRandomnessRange);
         bestThoughtProcesses.Add(new Pair()
         {
             process = process
         });
     }
 }
    public ThoughtProcess(ThoughtProcess firstParent, ThoughtProcess secondParent)
    {
        biasAndWeights = new float[firstParent.biasAndWeights.Length];
        List <int> indexes = new List <int>();

        for (int i = 0; i < firstParent.biasAndWeights.Length; i++)
        {
            indexes.Add(i);
        }
        for (int i = 0; i < firstParent.biasAndWeights.Length / 2; i++)
        {
            int randomIndex = UnityEngine.Random.Range(0, indexes.Count);
            var indexToUse  = indexes[randomIndex];
            indexes.RemoveAt(randomIndex);
            biasAndWeights[indexToUse] = firstParent.biasAndWeights[indexToUse];
        }
        foreach (var index in indexes)
        {
            biasAndWeights[index] = secondParent.biasAndWeights[index];
        }
    }
Exemplo n.º 6
0
 /// <summary>
 /// begins a new process flow, usually on the event of a current need change
 /// </summary>
 /// <param name="mindState">The new current need type</param>
 private void startNewProcess(MindState mindState)
 {
     switch (mindState) {
         case MindState.Thirsty:
             thoughtProcess = new BarProcess(boid, drinkNeed);
             break;
         case MindState.Dancey:
             thoughtProcess = new DanceProcess(boid, danceNeed);
             break;
         case MindState.Incontenent:
             thoughtProcess = new ToiletProcess(boid, toiletNeed);
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }