// i(t) = sigmoid(W(i)*x(t) + U(i)*h(t-1)) input gate // f(t) = sigmoid(W(f)*x(t) + U(f)*h(t-1)) forget gate // o(t) = sigmoid(W(o)*x(t) + U(o)*h(t-1)) output exposure gate // c tilde(t) = tanh(W(c)*x(t) + U(c)*h(t-1)) new memory cell // c(t) = f(t).*c tilde(t-1) + i(t).*c tilde(t) final memory cell // h(t) = o(t).*tanh(c(t)) public Tensor Step(Graph.Graph f, Tensor x, Tensor h) { // input gate var inputGate = f.Sigmoid(f.AddBias(f.Add(f.Multiply(x, _wix), f.Multiply(h, _wih)), _bi)); // forget gate var forgetGate = f.Sigmoid(f.AddBias(f.Add(f.Multiply(x, _wfx), f.Multiply(h, _wfh)), _bf)); var newInput = f.Tanh(f.Multiply(x, _wcx)); return(f.Add(f.ElementwiseMultiply(inputGate, newInput), f.ElementwiseMultiply(forgetGate, f.Tanh(h)))); }
// i(t) = sigmoid(W(i)*x(t) + U(i)*h(t-1)) input gate // f(t) = sigmoid(W(f)*x(t) + U(f)*h(t-1)) forget gate // o(t) = sigmoid(W(o)*x(t) + U(o)*h(t-1)) output exposure gate // c tilde(t) = tanh(W(c)*x(t) + U(c)*h(t-1)) new memory cell // c(t) = f(t).*c tilde(t-1) + i(t).*c tilde(t) final memory cell // h(t) = o(t).*tanh(c(t)) public Tensor Step(Graph.Graph f, Tensor x, Tensor c, Tensor h, out Tensor nc) { // input gate var inputGate = f.Sigmoid(f.AddBias(f.Add(f.Multiply(x, _wix), f.Multiply(h, _wih)), _bi)); // forget gate var forgetGate = f.Sigmoid(f.AddBias(f.Add(f.Multiply(x, _wfx), f.Multiply(h, _wfh)), _bf)); // output gate var outputGate = f.Sigmoid(f.AddBias(f.Add(f.Multiply(x, _wox), f.Multiply(h, _woh)), _bo)); // new cell var newInfo = f.Tanh(f.AddBias(f.Add(f.Multiply(x, _wcx), f.Multiply(h, _wch)), _bc)); // final cell var retainCell = f.ElementwiseMultiply(forgetGate, c); var writeCell = f.ElementwiseMultiply(inputGate, newInfo); var finalCell = f.Add(retainCell, writeCell); // hidden unit nc = finalCell; return(f.ElementwiseMultiply(outputGate, f.Tanh(finalCell))); }
/// <summary> /// Takes a Room and creates everything that is not a floor tile /// </summary> /// <param name="enemyTexture">Texture of enemies in this room</param> /// <param name="wallTexture">Texture of walls in this room</param> public void initRoom(Texture2D wallTextures, Texture2D floorTextures, Graph.Graph graph) { //Init room's textures this.wallTextures = wallTextures; this.floorTextures = floorTextures; //Should change this later int tileSize = 64; int roomSize = 10; int enemySpriteWidth = 39; int enemySpriteHeight = 38; Pod pod = new Pod(); for (int i = 0; i < roomSize; i++) { for (int j = 0; j < roomSize; j++) { Vector2 currPos = new Vector2( position.X + tileSize * i, position.Y + tileSize * j); Vector2 midPos = new Vector2( currPos.X + (tileSize / 4), currPos.Y + (tileSize / 4)); switch (tileLayout[i, j]) { //Create walls case TileType.WALL: ChunkManager.Instance.Add( new Wall( floorTextures, currPos, new Rectangle( (int)currPos.X, (int)currPos.Y, tileSize, tileSize))); break; //Move player case TileType.PLAYER: Player.Instance.Position = currPos; Player.Instance.ResetPlayerNewMap(); Player.Instance.CurrWeapon.ResetWeapon(); Weapons.Weapon temp = Player.Instance.CurrWeapon; temp.X = currPos.X + Player.Instance.BoundingBox.Width / 2; temp.Y = currPos.Y + Player.Instance.BoundingBox.Height / 2; Camera.Instance.resetPosition(Player.Instance.Position); //Add this position to the graph graph.Add(new Graph.GraphNode(midPos)); spawnroom = true; break; //Create Melee Enemies case TileType.MELEEENEMY: graph.Add(new Graph.GraphNode(midPos)); //Create new enemy MeleeEnemy newEnemy = new MeleeEnemy( TextureManager.Instance.GetEnemyTexture("EnemyTexture"), midPos, new Rectangle( (int)midPos.X, (int)midPos.Y, enemySpriteWidth, enemySpriteHeight)); //Add Enemy to game EntityManager.Instance.Add(newEnemy); ChunkManager.Instance.Add(newEnemy); pod.Add(newEnemy); break; //Create Turret Enemies case TileType.TURRET: //Create new enemy TurretEnemy turret = new TurretEnemy( TextureManager.Instance.GetEnemyTexture("EnemyTexture"), midPos, new Rectangle( (int)midPos.X, (int)midPos.Y, enemySpriteWidth, enemySpriteHeight)); //Add Enemy to game EntityManager.Instance.Add(turret); ChunkManager.Instance.Add(turret); pod.Add(turret); break; case TileType.DASHENEMY: graph.Add(new Graph.GraphNode(midPos)); //Create new enemy DashEnemy dash = new DashEnemy( TextureManager.Instance.GetEnemyTexture("EnemyTexture"), midPos, new Rectangle( (int)midPos.X, (int)midPos.Y, enemySpriteWidth, enemySpriteHeight)); //Add Enemy to game EntityManager.Instance.Add(dash); ChunkManager.Instance.Add(dash); pod.Add(dash); break; default: //Add this position to the graph graph.Add(new Graph.GraphNode(midPos)); break; } } } PodManager.Instance.Add(pod); InitTextureMap(); }
public Tensor Step(Graph.Graph f, Tensor x, Tensor h) { return(f.AddBias(f.Add(f.Multiply(x, _wxh), f.Multiply(h, _whh)), _bh)); }