public Cell(IClockDown c) { m_charge = 0; m_counter = c; m_output = new Axon(); m_output.src = this; }
public static Brain Evolve(List <Creature> parents) { int parentsTotal = parents.Count; var newBrain = new Axon[BRAIN_WIDTH - 1, BRAIN_HEIGHT, BRAIN_HEIGHT - 1]; var newNeurons = new float[BRAIN_WIDTH, BRAIN_HEIGHT]; float randomParentRotation = Random.value; for (int x = 0; x < BRAIN_WIDTH - 1; x++) { for (int y = 0; y < BRAIN_HEIGHT; y++) { for (int z = 0; z < BRAIN_HEIGHT - 1; z++) { newBrain[x, y, z] = parents[(int)((Mathf.Atan2((y + z) / 2 - BRAIN_HEIGHT / 2, x - BRAIN_WIDTH / 2) / (2 * Mathf.PI) + Mathf.PI + randomParentRotation) % 1.0f) * parentsTotal].CreatureBrain.axons[x, y, z].MutateAxon(); } } } for (int x = 0; x < BRAIN_WIDTH; x++) { for (int y = 0; y < BRAIN_HEIGHT; y++) { newNeurons[x, y] = parents[(int)((Mathf.Atan2(y - BRAIN_HEIGHT / 2, x - BRAIN_WIDTH / 2) / (2 * Mathf.PI) + Mathf.PI + randomParentRotation) % 1.0f * parentsTotal)].CreatureBrain.neurons[x, y]; } } return(new Brain(newBrain, newNeurons)); }
public void ApplyAxon(Axon a) { if (!axons.Contains(a)) { axons.Add(a); } }
public void add_cell(Cell c) { Axon n = new Axon(); n.dst = c; n.src = this; m_outputs.Add(n); }
public void ApplyDentrite(Axon a) { if (a != null) { chargeTreshold++; } }
/// <summary> /// Init the Axons /// </summary> private void InitAxons() { //双向边 axons = new List <Axon>(); for (int i = 0; i < cells.Count; ++i) { for (int j = i + 1; j < cells.Count; ++j) { Cell cell_a = cells[i]; Cell cell_b = cells[j]; Vector3 pa = cell_a.Position; Vector3 pb = cell_b.Position; if (Vector3.Distance(pa, pb) < maxAxonDistance) { if (cell_a.AxonNumber < maxAxonNumber && cell_b.AxonNumber < maxAxonNumber) { //创建新的axon //分别存到cell a, cell b, network里 Axon newA = new Axon(cell_a, cell_b); newA.senderMaker = senderMaker; cell_a.selfAxons.Add(newA); cell_b.selfAxons.Add(newA); axons.Add(newA); } } } } Debug.Log("Number of axons : " + axons.Count); }
public Synapse() { weight = 1; axon = new Axon(); axon.value = 0; }
public Axon setAxonTo(Cell b) { Axon axon = new Axon(this, b); selfAxons.Add(axon); b.selfAxons.Add(axon); return(axon); }
public AxonInitData(Axon axon) { weight = axon.weight; fromID = axon.from.index; toID = axon.to.index; //Debug.Log($"Creating axon from {axon.from.neuronType} {axon.from.data.name} to " + // $"{axon.to.neuronType} {axon.to.data.name}"); // OK }
/// <summary> Copies connection WEIGHTS top down. </summary> /// <param name="n"></param> public void CopyWeightsFrom(Neuron n) { int mIndex = n.axons.Count > axons.Count ? axons.Count : n.axons.Count; for (int i = 0; i < mIndex; ++i) { axons[i] = new Axon(n.axons[i].weight, axons[i].receivingNode); } }
public Axon Mutated() { Axon axon = new Axon(); axon.weight += AiMath.RandomRange(-0.1f, 0.1f); axon.A = A; axon.B = B; axon.inovation = inovation; return(axon); }
public NeuronaEntrada(double[] valoresDeEntrada) { dendritas = new DendritaEntrada[valoresDeEntrada.Length]; for (int i = 0; i < valoresDeEntrada.Length; i++) { dendritas[i] = new DendritaEntrada(this, valoresDeEntrada[i]); } axon = new Axon(this); bia = new Bia(this); }
public Neurona(NeuronaAbstracta[] neuronas) { dendritas = new Dendrita[neuronas.Length]; for (int i = 0; i < neuronas.Length; i++) { dendritas[i] = new Dendrita(this, neuronas[i].axon); } axon = new Axon(this); bia = new Bia(this); }
public Neuron(Range sensitivity, ActivationFunctionType f_type) { this.sensitivity = sensitivity; activationFunc = new ActivationFunction(f_type); synapses = new List <Synapse>(); axon = new Axon(); }
public NeuronaSalida(NeuronaAbstracta[] neuronas, double salidaDeseada) { this.salidaDeseada = salidaDeseada; dendritas = new DendritaSalida[neuronas.Length]; for (int i = 0; i < neuronas.Length; i++) { dendritas[i] = new DendritaSalida(this, neuronas[i].axon); } axon = new Axon(this); bia = new Bia(this); }
public static Axon NewAxon(int range) { range = Math.Max(1, range); Axon axon = new Axon(); axon.weight = AiMath.RandomRange(-1f, 1f); axon.A = AiMath.random.Next(0, range); axon.B = AiMath.random.Next(0, range); axon.inovation = ++_inovation; return(axon); }
public ParticleSender(Vector3 fpos, Vector3 tpos, int pIn, float limi_time, Cell tcell, Axon faxon, particleMaker pm) { fromPoint = fpos; toPoint = tpos; particleIndex = pIn; limitTime = limi_time; startTime = Time.time; targetCell = tcell; fromAxon = faxon; pMaker = pm; active = true; }
public void RebuildBrain(BrainGenome genome, Agent agent) { // Create Neurons: neuronList = new List <Neuron>(); IDs = new Dictionary <NID, int>(); // I need access to all of the Modules in order to link the neuron values to the module values!!!! for (int i = 0; i < genome.bodyNeuronList.Count; i++) { Neuron neuron = new Neuron(); agent.MapNeuronToModule(genome.bodyNeuronList[i].nid, neuron); IDs.Add(genome.bodyNeuronList[i].nid, i); neuronList.Add(neuron); } for (int i = 0; i < genome.hiddenNeuronList.Count; i++) // REVISIT { Neuron neuron = new Neuron(); agent.MapNeuronToModule(genome.hiddenNeuronList[i].nid, neuron); IDs.Add(genome.hiddenNeuronList[i].nid, i); neuronList.Add(neuron); } //Debug.Log("RebuildBrain " + genome.bodyNeuronList.Count + ", " + neuronList.Count.ToString()); // Create Axons: axonList = new List <Axon>(); for (int i = 0; i < genome.linkList.Count; i++) { // find out neuronIDs: int fromID = -1; if (IDs.TryGetValue(new NID(genome.linkList[i].fromModuleID, genome.linkList[i].fromNeuronID), out fromID)) { } else { Debug.LogError("fromNID NOT FOUND " + genome.linkList[i].fromModuleID.ToString() + ", " + genome.linkList[i].fromNeuronID.ToString()); } int toID = -1; if (IDs.TryGetValue(new NID(genome.linkList[i].toModuleID, genome.linkList[i].toNeuronID), out toID)) { } else { Debug.LogError("toNID NOT FOUND " + genome.linkList[i].fromModuleID.ToString() + ", " + genome.linkList[i].fromNeuronID.ToString()); } //Debug.Log(fromID.ToString() + " --> " + toID.ToString() + ", " + genome.linkList[i].weight.ToString()); //int fromID = IDs < new NID(genome.linkList[i].fromModuleID, genome.linkList[i].fromNeuronID) >; Axon axon = new Axon(fromID, toID, genome.linkList[i].weight); axonList.Add(axon); } //PrintBrain(); }
public IAxon Create(IList <Synapse> terminals, Type activationFunction) { var functionObj = Activator.CreateInstance(activationFunction); if (!(functionObj is IActivationFunction)) { throw new NotSupportedException( $"{activationFunction} is not a supported activation function type for Create() as it does not implement IActivationFunction"); } var function = functionObj as IActivationFunction; return(Axon.GetInstance(terminals, function)); }
public Axon Clone() { Axon axon = new Axon(); if (AiMath.PercentChance(mutationChance)) { axon.weight = weight + AiMath.RandomRange(-0.1f, 0.1f); } else { axon.weight = weight; } axon.A = A; axon.B = B; axon.inovation = inovation; return(axon); }
// Configuration: means creating dendrites, BIAS and axon public void Configure(int dendritesAmount, LayerType layerType, Random random, NeuronType neuronType) { NeuronType = neuronType; LayerType = layerType; Dendrites = new List <Dendrite>(); if (!IsInputLayer(layerType)) { Bias = new Dendrite(random, NeuronType); } dendritesAmount = IsInputLayer(LayerType) ? 1 : dendritesAmount; for (int i = 0; i < dendritesAmount; i++) { Dendrites.Add(new Dendrite(random, NeuronType, IsInputLayer(LayerType))); } Axon = new Axon(); }
public IAxon Create(IList <Synapse> terminals, Type activationFunction) { if (activationFunction == typeof(AbsoluteXActivationFunction)) { return(Axon.GetInstance(terminals, new AbsoluteXActivationFunction())); } else if (activationFunction == typeof(IdentityActivationFunction)) { return(Axon.GetInstance(terminals, new IdentityActivationFunction())); } else if (activationFunction == typeof(InverseActivationFunction)) { return(Axon.GetInstance(terminals, new InverseActivationFunction())); } else if (activationFunction == typeof(SechActivationFunction)) { return(Axon.GetInstance(terminals, new SechActivationFunction())); } else if (activationFunction == typeof(SigmoidActivationFunction)) { return(Axon.GetInstance(terminals, new SigmoidActivationFunction())); } else if (activationFunction == typeof(SinhActivationFunction)) { return(Axon.GetInstance(terminals, new SinhActivationFunction())); } else if (activationFunction == typeof(StepActivationFunction)) { return(Axon.GetInstance(terminals, new StepActivationFunction())); } else if (activationFunction == typeof(TanhActivationFunction)) { return(Axon.GetInstance(terminals, new TanhActivationFunction())); } else { throw new NotSupportedException(string.Format("{0} is not a supported activation function type for Create()", activationFunction)); } }
void SafeAxon() { Axon na = Axon.NewAxon(nodes.Count); //check if clone bool clone = false; for (int i = 0; i < axons.Count; i++) { if (na.A == axons[i].A && na.B == axons[i].B) { clone = true; } } for (int i = 0; i < 10; i++) { if (na.A == na.B || clone) { na = Axon.NewAxon(nodes.Count); clone = false; for (int t = 0; t < axons.Count; t++) { if ((na.A == axons[t].A) && (na.B == axons[t].B)) { clone = true; } } } else { axons.Add(na); return; } } }
public Brain(Axon[,,] tbrain, float[,] tneurons) { if (tbrain == null) { for (int x = 0; x < BRAIN_WIDTH - 1; x++) { for (int y = 0; y < BRAIN_HEIGHT; y++) { for (int z = 0; z < BRAIN_HEIGHT - 1; z++) { float startingWeight = (Random.value * 2 - 1) * STARTING_AXON_VARIABLILITY; axons[x, y, z] = new Axon(startingWeight, AXON_START_MUTABILITY); } } } for (int x = 0; x < BRAIN_WIDTH; x++) { for (int y = 0; y < BRAIN_HEIGHT; y++) { if (y == BRAIN_HEIGHT - 1) { neurons[x, y] = 1; } else { neurons[x, y] = 0; } } } } else { axons = tbrain; neurons = tneurons; } }
void RebuildAxons(BrainGenome genome) { axons = new List <Axon>(); if (genome.linkCount <= 0) { Debug.LogError("Cannot rebuild axons because genome has zero links"); return; } foreach (var link in genome.links) { var from = GetMatchingNeuron(neurons, link.from); var to = GetMatchingNeuron(neurons, link.to); if (from == null || to == null) { continue; } Axon axon = new Axon(from, to, link.weight); axons.Add(axon); } }
public IAxon Create() { return(Axon.GetInstance(new List <Synapse>(), _activationFunction)); }
public IAxon Create(IList <Synapse> terminals) { return(Axon.GetInstance(terminals, _activationFunction)); }
public void addAxon(Axon axon) { mAxon.Add(axon); }
public void MutateSexual(Axon axon) { // Modify the value of the weight by getting the mean of the two axons, then allowing that value to shift a bit. weight = Mathc.Random.GetMarsagliaBetween(weight, axon.weight); }
private void CreateDummyBrain() { // create a random small genome brain to test // Neurons! tempNeuronList = new List <Neuron>(); int numInputs = UnityEngine.Random.Range(Mathf.RoundToInt((float)numNeurons * 0.2f), Mathf.RoundToInt((float)numNeurons * 0.8f)); for (int i = 0; i < numNeurons; i++) { Neuron neuron = new Neuron(); if (i < numInputs) { neuron.neuronType = NeuronGenome.NeuronType.In; } else { neuron.neuronType = NeuronGenome.NeuronType.Out; } neuron.currentValue = new float[1]; neuron.currentValue[0] = UnityEngine.Random.Range(-2f, 2f); tempNeuronList.Add(neuron); } tempAxonList = new List <Axon>(); // Axons: for (int i = 0; i < numInputs; i++) { for (int j = 0; j < numNeurons - numInputs; j++) { if (j + i * numInputs < numAxons) { Axon axon = new Axon(i, numInputs + j, UnityEngine.Random.Range(-1f, 1f)); tempAxonList.Add(axon); } } } numAxons = tempAxonList.Count; /*Neuron neuron1 = new Neuron(); * neuron1.neuronType = NeuronGenome.NeuronType.In; * neuron1.currentValue = new float[1]; * neuron1.currentValue[0] = 1f; * tempNeuronList.Add(neuron1); * Neuron neuron2 = new Neuron(); * neuron2.neuronType = NeuronGenome.NeuronType.In; * neuron2.currentValue = new float[1]; * neuron2.currentValue[0] = -1f; * tempNeuronList.Add(neuron2); * Neuron neuron3 = new Neuron(); * neuron3.neuronType = NeuronGenome.NeuronType.In; * neuron3.currentValue = new float[1]; * neuron3.currentValue[0] = 0.1f; * tempNeuronList.Add(neuron3); * Neuron neuron4 = new Neuron(); * neuron4.neuronType = NeuronGenome.NeuronType.Out; * neuron4.currentValue = new float[1]; * neuron4.currentValue[0] = -0.45f; * tempNeuronList.Add(neuron4); * Neuron neuron5 = new Neuron(); * neuron5.neuronType = NeuronGenome.NeuronType.Out; * neuron5.currentValue = new float[1]; * neuron5.currentValue[0] = 1.5f; * tempNeuronList.Add(neuron5); * Neuron neuron6 = new Neuron(); * neuron6.neuronType = NeuronGenome.NeuronType.Out; * neuron6.currentValue = new float[1]; * neuron6.currentValue[0] = -0.22f; * tempNeuronList.Add(neuron6); * Debug.Log("tempNeuronList " + tempNeuronList.Count.ToString()); * * tempAxonList = new List<Axon>(); * Axon axon1 = new Axon(0, 3, UnityEngine.Random.Range(-1f, 1f)); * tempAxonList.Add(axon1); * Axon axon2 = new Axon(0, 4, UnityEngine.Random.Range(-1f, 1f)); * tempAxonList.Add(axon2); * Axon axon3 = new Axon(0, 5, UnityEngine.Random.Range(-1f, 1f)); * tempAxonList.Add(axon3); * Axon axon4 = new Axon(1, 3, UnityEngine.Random.Range(-1f, 1f)); * tempAxonList.Add(axon4); * Axon axon5 = new Axon(1, 4, UnityEngine.Random.Range(-1f, 1f)); * tempAxonList.Add(axon5); * Axon axon6 = new Axon(1, 5, UnityEngine.Random.Range(-1f, 1f)); * tempAxonList.Add(axon6); * Axon axon7 = new Axon(2, 3, UnityEngine.Random.Range(-1f, 1f)); * tempAxonList.Add(axon7); * Axon axon8 = new Axon(2, 4, UnityEngine.Random.Range(-1f, 1f)); * tempAxonList.Add(axon8); * Axon axon9 = new Axon(2, 5, UnityEngine.Random.Range(-1f, 1f)); * tempAxonList.Add(axon9); */ //Brain brain = new Brain(); }
public void MakeNewSender(Vector3 pa, Vector3 pb, float limitTime, Cell targetCell, Axon axon) { //Debug.Log("Make a new sender"); //GameObject sendergo = Instantiate(senderGameObject, pa, Quaternion.identity); //Sender se = sendergo.GetComponent<Sender>(); //se.fromPoint = pa; //se.toPoint = pb; //se.limitTime = limitTime; //se.startTime = Time.time; //se.targetCell = targetCell; //se.fromAxon = axon; //se.active = true; int emptyId = findEmptyId(); if (emptyId == -1) { return; } _pSender[emptyId].fromPoint = pa; _pSender[emptyId].toPoint = pb; _pSender[emptyId].position = pa; _pSender[emptyId].limitTime = limitTime; _pSender[emptyId].startTime = Time.time; _pSender[emptyId].targetCell = targetCell; _pSender[emptyId].fromAxon = axon; _pSender[emptyId].active = true; }
public void Fire() { Axon.Set(Dendrite.Get() * Weight); }