// Start is called before the first frame update void Start() { path = GetComponent <EnemyAI>(); loss = GetComponent <LOSS>(); pos = target.transform.position; InvokeRepeating("Check", 0, 4f); }
public void Add(int size, ACTIVATION a, LOSS l, double bias) { activation = a; loss = l; for (int i = 0; i < size; i++) { Neuron n = new Neuron(this.Owner); n.activation = activation; n.loss = loss; n.bias = bias; n.father = this; Neurons.Add(n); } }
public void LoadFromCode(List <string> code) { string s; string s2; string tag; string[] ss; string[] ss2; Synapse _synapse; Neuron _neuron; Layer _layer; Dictionary <int, NeuralObject> mapping = new Dictionary <int, NeuralObject>(); int _id = -1; string _class = ""; ACTIVATION _activation = ACTIVATION.SOFTMAX; LOSS _loss = LOSS.CROSS_ENTROPY; int _father = -1; double _bias = 0.00; double _weight = 0.00; double _learnfactor = 0.00; int _previous = -1; int _next = -1; int maxID = -1; for (int i = 0; i < code.Count; i++) { s = code[i].Trim(); ss = s.Split('|'); for (int j = 0; j < ss.Length; j++) { s = ss[j].Trim(); ss2 = s.Split(':'); s = ss2[0].Trim(); s2 = ss2[1].Trim(); switch (s) { default: throw new System.Exception("unknow parameter"); case "ID": if (!int.TryParse(s2, out _id)) { throw new System.Exception("id not integer"); } break; case "Class": _class = s2; break; case "Activation": if (!Enum.TryParse <ACTIVATION>(s2, out _activation)) { throw new System.Exception("invalid activation"); } break; case "Loss": if (!Enum.TryParse <LOSS>(s2, out _loss)) { throw new System.Exception("invalid loss"); } break; case "Bias": if (!double.TryParse(s2, out _bias)) { throw new System.Exception("bias is not double"); } break; case "Father": if (!int.TryParse(s2, out _father)) { throw new System.Exception("father not integer"); } break; case "Weight": if (!double.TryParse(s2, out _weight)) { throw new System.Exception("weight is not double"); } break; case "Learn Factor": if (!double.TryParse(s2, out _learnfactor)) { throw new System.Exception("learn factor is not double"); } break; case "Previous": if (!int.TryParse(s2, out _previous)) { throw new System.Exception("previous not integer"); } break; case "Next": if (!int.TryParse(s2, out _next)) { throw new System.Exception("next not integer"); } break; } } maxID = maxID < _id ? _id : maxID; _lastid = _id; switch (_class) { case "NeuralNetwork": break; case "Layer": _layer = new Layer(this); _layer.activation = _activation; _layer.loss = _loss; layers.Add(_layer); mapping.Add(_id, _layer); break; case "Neuron": _neuron = new Neuron(this); _neuron.father = (Layer)mapping[_father]; _neuron.bias = _bias; _neuron.activation = _activation; _neuron.loss = _loss; layers.Last().Neurons.Add(_neuron); mapping.Add(_id, _neuron); break; case "Synapse": _synapse = new Synapse(this); _synapse.weight = _weight; _synapse.learnFactor = _learnfactor; _synapse.previous = (Neuron)mapping[_previous]; _synapse.next = (Neuron)mapping[_next]; layers.Last().Synapses.Add(_synapse); mapping.Add(_id, _synapse); break; default: break; } } _lastid = maxID + 1; }
void Start() { loss = GetComponent <LOSS>(); col = GetComponent <BoxCollider2D>(); rb = GetComponent <Rigidbody2D>(); }