public static int Main(string[] args) { MathE mathE = new MathE(); TestLibrary.TestFramework.BeginTestCase("Testing System.Math.E..."); if (mathE.RunTests()) { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("PASS"); return 100; } else { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("FAIL"); return 0; } }
public void UniformRandomPriors() { logPi = MathE.elnify(NormalMass(logPi.Length)); for (int i = 0; i < logTransition.GetLength(0); i++) { double[] trans = MathE.elnify(NormalMass(states)); for (int j = 0; j < logTransition.GetLength(0); j++) { logTransition[i, j] = trans[j]; } } for (int i = 0; i < logEmission.GetLength(0); i++) { double[] ems = MathE.elnify(NormalMass(observationSymbols)); for (int j = 0; j < logEmission.GetLength(1); j++) { logEmission[i, j] = ems[j]; } } }
private void AimHyperdrive() { float direction = 0f; #if UNITY_STANDALONE if (!MathE.IsPointerOverUIObject(Input.mousePosition) && Input.GetMouseButton(0)) { Vector2 point = mainCamera.ScreenToWorldPoint(Input.mousePosition); direction = Mathf.Clamp(point.y - transform.position.y, -1f, 1f); } else { if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { direction = 1f; } else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { direction = -1f; } } #elif UNITY_IOS || UNITY_ANDROID if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (!MathE.IsPointerOverUIObject(touch.position)) { Vector2 point = mainCamera.ScreenToWorldPoint(touch.position); direction = Mathf.Clamp(point.y - transform.position.y, -1f, 1f); } } #endif transform.position += Vector3.up * hyperdriveMoveSpeed * direction * Time.deltaTime; transform.position = new Vector3(0f, Mathf.Clamp(transform.position.y, -MapController.Singleton.ScreenHeight / 2f, MapController.Singleton.ScreenHeight / 2f)); }
public static IEnumerable <TSource> SubArraySmart <TSource>( this IEnumerable <TSource> enumerable, int startIndex, int cycles, int stepsize = 1 ) { TSource[] final = new TSource[cycles]; int currentIndex = startIndex; for (int i = 0; i < cycles; i++) { currentIndex = MathE.ClampWrap( startIndex + (i * stepsize), 0, enumerable.Count() ); final[i] = enumerable.ElementAt(currentIndex); } return(final.AsEnumerable()); }
// ln(a_t(i)) private double[,] LogSpaceForward(int[] O) { int N = states; int M = observationSymbols; int T = O.Length; var logAlpha = new double[T, N]; #region Alpha Pass for (int i = 0; i < N; i++) { //logAlpha[0, i] = MathE.elnproduct(MathE.eln(pi[i]), MathE.eln(emission[i, O[0]])); logAlpha[0, i] = MathE.elnproduct(logPi[i], logEmission[i, O[0]]); } //compute a_t(i) for (int t = 1; t < T; t++) { for (int i = 0; i < N; i++) { double logalpha = MathE.LOGZERO; //alpha[t, i] = 0; for (int j = 0; j < N; j++) { //logalpha = MathE.elnsum(logalpha, MathE.elnproduct(logAlpha[t - 1, j], MathE.eln(transition[j, i]))); logalpha = MathE.elnsum(logalpha, MathE.elnproduct(logAlpha[t - 1, j], logTransition[j, i])); } // logAlpha[t, i] = MathE.elnproduct(logalpha, MathE.eln(emission[i, O[t]])); logAlpha[t, i] = MathE.elnproduct(logalpha, logEmission[i, O[t]]); } } return(logAlpha); #endregion }
// ln(b_t(i)) private double[,] LogSpaceBackward(int[] O) { int N = states; int M = observationSymbols; int T = O.Length; var logBeta = new double[T, N]; #region Beta Pass for (int i = 0; i < N; i++) { logBeta[T - 1, i] = 0; } // Beta pass for (int t = T - 2; t >= 0; t--) { for (int i = 0; i < N; i++) { double logbeta = MathE.LOGZERO; for (int j = 0; j < N; j++) { // logbeta = MathE.elnsum(logbeta, MathE.elnproduct(MathE.eln(transition[i, j]), // MathE.elnproduct(emission[j, O[t + 1]], logBeta[t + 1, j]))); // mISTAKE ??? MathE.elnproduct(emission[j, O[t + 1]],... logbeta = MathE.elnsum(logbeta, MathE.elnproduct(logTransition[i, j], MathE.elnproduct(logEmission[j, O[t + 1]], logBeta[t + 1, j]))); } logBeta[t, i] = logbeta; } } #endregion return(logBeta); }
/// <summary> /// Sets the Pitch and Yaw to point in the direction of the vector. /// </summary> /// <param name="vector">Point the entity will look at</param> /// <returns>The location with the new Pitch and Yaw</returns> public Location SetDirection(Vector vector) { const double double2Pi = 2 * Math.PI; double x = vector.GetX(); double z = vector.GetZ(); if (x == 0 && z == 0) { Pitch = vector.GetY() > 0 ? -90 : 90; return(this); } double theta = Math.Atan2(-x, z); Yaw = (float)MathE.ToDegrees((theta + double2Pi) % double2Pi); double x2 = Math.Pow(x, 2); double z2 = Math.Pow(z, 2); double xz = Math.Sqrt(x2 + z2); Pitch = (float)MathE.ToDegrees(Math.Atan(-vector.GetY() / xz)); return(this); }
double MapRotToDeg(ulong rot) { return(MathE.ReMap( rot, 0.0, ulong.MaxValue, 0.0, 360.0)); }
public double[,] CalculateGamma(int[] O) { return(MathE.eexpify(CalculateLogGamma(O))); }
// Update is called once per frame void Update() { if (Inputs.pressed("a")) { if (Title.instance.gameObject.activeSelf) { if (selectedOption == 3) { SoundManager.instance.PlayABSound(); Inputs.instance.DisableForSeconds("a", 0.2f); Title.instance.currentMenu = Title.instance.HasData ? Title.instance.datamenu : Title.instance.nodatamenu; this.gameObject.SetActive(false); } } else if (MainMenu.instance.currentmenu == MainMenu.instance.optionsmenu) { if (selectedOption == 3) { SoundManager.instance.PlayABSound(); Inputs.Enable("start"); MainMenu.instance.currentmenu = MainMenu.instance.thismenu; this.gameObject.SetActive(false); } } } if (Inputs.pressed("b")) { if (Title.instance.gameObject.activeSelf) { SoundManager.instance.PlayABSound(); this.gameObject.SetActive(false); } else if (MainMenu.instance.currentmenu == MainMenu.instance.optionsmenu) { SoundManager.instance.PlayABSound(); Inputs.Enable("start"); MainMenu.instance.currentmenu = MainMenu.instance.thismenu; this.gameObject.SetActive(false); } } if (Inputs.pressed("left")) { if (selectedOption == 0) { GameData.instance.textChoice--; MathE.Clamp(ref GameData.instance.textChoice, 0, 2); UpdateCursorPosition(); } if (selectedOption == 1) { GameData.instance.animationChoice--; MathE.Clamp(ref GameData.instance.animationChoice, 0, 1); UpdateCursorPosition(); } if (selectedOption == 2) { GameData.instance.battleChoice--; MathE.Clamp(ref GameData.instance.battleChoice, 0, 1); UpdateCursorPosition(); } } if (Inputs.pressed("right")) { if (selectedOption == 0) { GameData.instance.textChoice++; MathE.Clamp(ref GameData.instance.textChoice, 0, 2); UpdateCursorPosition(); } if (selectedOption == 1) { GameData.instance.animationChoice++; MathE.Clamp(ref GameData.instance.animationChoice, 0, 1); UpdateCursorPosition(); } if (selectedOption == 2) { GameData.instance.battleChoice++; MathE.Clamp(ref GameData.instance.battleChoice, 0, 1); UpdateCursorPosition(); } } if (Inputs.pressed("down")) { selectedOption++; MathE.Clamp(ref selectedOption, 0, 3); UpdateCursorPosition(); } if (Inputs.pressed("up")) { selectedOption--; MathE.Clamp(ref selectedOption, 0, 3); UpdateCursorPosition(); } }
private void MainWindow_Resize(object sender, EventArgs e) { GL.Viewport(0, 0, ClientSize.Width, ClientSize.Height); _projectionMatrix = Matrix4.CreatePerspectiveFieldOfView(MathE.ToRad(45), ClientSize.Width / (float)ClientSize.Height, 0.1f, 100); _viewMatrix = Matrix4.LookAt(_camera, _target, new Vector3(0, 1, 0)); }
void Update() { if (currentMenu == switchstats) { if (Inputs.pressed("down")) { selectedOption++; MathE.Clamp(ref selectedOption, 0, 2 + switchMenuOffset); UpdateSwitch(); } if (Inputs.pressed("up")) { selectedOption--; MathE.Clamp(ref selectedOption, 0, 2 + switchMenuOffset); UpdateSwitch(); } } if (currentMenu == mainwindow) { highlightedmon = GameData.instance.party[selectedOption]; partyAnimTimer += 1; float hpratio = (float)highlightedmon.currentHP / (float)highlightedmon.maxHP; float animLoopTime = hpratio > .5f ? 10 : hpratio > .21f ? 32 : 64; //the animation takes 10,32, or 64 frames if (partyAnimTimer == animLoopTime) { partyAnimTimer = 0; } foreach (Pokemon pokemon in GameData.instance.party) { Transform slottransform = partyslots[GameData.instance.party.IndexOf(pokemon)].transform; if (GameData.instance.party.IndexOf(pokemon) != selectedOption) { slottransform.GetChild(0).GetComponent <Image>().sprite = partyanims[PokemonData.PokemonPartySprite[pokemon.name]].anim[0]; } else { slottransform.GetChild(0).GetComponent <Image>().sprite = partyanims[PokemonData.PokemonPartySprite[pokemon.name]].anim[Mathf.FloorToInt(2f * partyAnimTimer / animLoopTime)]; } } cursor.SetPosition(0, 128 - 16 * selectedOption); if (Dialogue.instance.finishedText || selectingPokemon) { if (Inputs.pressed("down")) { selectedOption++; MathE.Clamp(ref selectedOption, 0, numberofPokemon - 1); } if (Inputs.pressed("up")) { selectedOption--; MathE.Clamp(ref selectedOption, 0, numberofPokemon - 1); } } } if (Inputs.pressed("b") && Dialogue.instance.finishedText) { SoundManager.instance.PlayABSound(); if (currentMenu == mainwindow) { Inputs.instance.DisableForSeconds("b", 0.2f); Dialogue.instance.fastText = false; Dialogue.instance.Deactivate(); Inputs.Enable("start"); moon.currentmenu = moon.thismenu; this.gameObject.SetActive(false); } else if (currentMenu == switchstats) { selectedOption = selectedMon; currentMenu = mainwindow; UpdateMainMenu(); } } if (Inputs.pressed("a") && Dialogue.instance.finishedText) { SoundManager.instance.PlayABSound(); if (currentMenu == mainwindow) { if (!switching) { int textOffsetLength = 4; switchMenuOffsetX = 0; switchMenuOffset = 0; int numberOfFieldMoves = 0; int selectedMenu = 0; selectedMon = selectedOption; Pokemon selectedPokemon = GameData.instance.party[selectedMon]; for (int i = 0; i < 4; i++) { fieldMoveNames[i] = ""; fieldMoveObj[i].SetActive(false); } for (int i = 0; i < 4; i++) { if (selectedPokemon.slotHasMove(i)) { Move move = selectedPokemon.moves[i]; if (isFieldMove(move)) { numberOfFieldMoves++; if (move.name.Length > 6 && selectedMenu != 8) { selectedMenu = 4; textOffsetLength = 2; } if (move.name.Length > 8) { selectedMenu = 8; textOffsetLength = 0; } fieldMoveNames[switchMenuOffset] = move.name; fieldMoveObj[3 - switchMenuOffset].SetActive(true); for (int j = 0; j < textOffsetLength; j++) { fieldMoveText[3 - switchMenuOffset].text += " "; } switchMenuOffset++; } } } for (int i = 0; i < numberOfFieldMoves; i++) { fieldMoveText[(4 - switchMenuOffset) + i].text += fieldMoveNames[i].ToUpper(); } switchMenuOffsetX = selectedMenu / 4; selectedMenu += switchMenuOffset; switchMenuImage.sprite = switchMenuSprites[selectedMenu]; selectedOption = 0; currentMenu = switchstats; UpdateSwitch(); } else { Dialogue.instance.Deactivate(); StartCoroutine(Switch()); UpdateScreen(); StartCoroutine(Dialogue.instance.text("Choose a POKéMON.")); Dialogue.instance.finishedText = true; switching = false; } } else if (currentMenu == switchstats) { if (selectedOption < switchMenuOffset) { StartCoroutine(UseFieldMove(fieldMoveNames[selectedOption])); } if (selectedOption == switchMenuOffset) { SoundManager.instance.SetMusicLow(); SoundManager.instance.PlayCry(PokemonData.MonToID(GameData.instance.party[selectedMon].name) - 1); Dialogue.instance.Deactivate(); currentMenu = stats1; UpdateStats1(); } else if (selectedOption == switchMenuOffset + 1) { switching = true; selectedOption = selectedMon; currentMenu = mainwindow; StartCoroutine(Dialogue.instance.text("Move #MON\\lwhere?")); Dialogue.instance.finishedText = true; UpdateMainMenu(); } else if (selectedOption == switchMenuOffset + 2) { selectedOption = selectedMon; currentMenu = mainwindow; UpdateMainMenu(); } } else if (currentMenu == stats1) { currentMenu = stats2; UpdateStats2(); } else if (currentMenu == stats2) { SoundManager.instance.SetMusicNormal(); Dialogue.instance.Deactivate(); Dialogue.instance.fastText = true; Dialogue.instance.keepTextOnScreen = true; Dialogue.instance.needButtonPress = false; StartCoroutine(Dialogue.instance.text("Choose a POKéMON.")); Dialogue.instance.finishedText = true; selectedOption = selectedMon; currentMenu = mainwindow; UpdateMainMenu(); } } }
private void UpdateDeathScreenStats() { int scoreHighScore = StatController.Singleton.GetSetScoreHighScore(score); float timeAliveHighScore = StatController.Singleton.GetSetTimeAliveHighScore(timeAlive); float distanceTraveledHighScore = StatController.Singleton.GetSetDistanceTraveledHighScore(distanceTraveled); scoreFinalText.text = string.Format("score: {0} ({1})", score, score > scoreHighScore ? "RECORD!" : "record is " + scoreHighScore); timeAliveFinalText.text = string.Format("time alive: {0} ({1})", MathE.FormatTimeAlive(timeAlive).ToLower(), timeAlive > timeAliveHighScore ? "RECORD!" : "record is " + MathE.FormatTimeAlive(timeAliveHighScore).ToLower()); distanceTraveledFinalText.text = string.Format("distance traveled: {0} m ({1})", distanceTraveled.ToString("F0"), distanceTraveled > distanceTraveledHighScore ? "RECORD!" : "record is " + distanceTraveledHighScore.ToString("F0") + " m"); foreach (var statRecord in statRecords) { statRecord.StatRecordText.text = statRecordTypes[statRecord.StatRecordType].ToString("F0") + " " + statRecord.Postfix; } }
// Update is called once per frame void Update() { if ((currentmenu == rednamemenu || currentmenu == garynamemenu) && currentmenu != nameselectionmenu) { if (Inputs.pressed("down")) { selectedOption++; MathE.Clamp(ref selectedOption, 0, 3); cursor.SetPosition(8, 120 - 16 * selectedOption); } if (Inputs.pressed("up")) { selectedOption--; MathE.Clamp(ref selectedOption, 0, 3); cursor.SetPosition(8, 120 - 16 * selectedOption); } } foreach (GameObject menu in allmenus) { if (menu != currentmenu) { menu.SetActive(false); } else { menu.SetActive(true); } } if (Inputs.pressed("a")) { if (currentmenu == rednamemenu) { if (selectedOption == 0) { currentmenu = nameselectionmenu; nameselectionmenu.SetActive(true); names.futureName = ""; } else { currentmenu = null; switch (VersionManager.instance.version) { case Version.Red: switch (selectedOption) { case 1: GameData.instance.playerName = "RED"; break; case 2: GameData.instance.playerName = "ASH"; break; case 3: GameData.instance.playerName = "JACK"; break; } break; case Version.Blue: switch (selectedOption) { case 1: GameData.instance.playerName = "BLUE"; break; case 2: GameData.instance.playerName = "GARY"; break; case 3: GameData.instance.playerName = "JOHN"; break; } break; } tutanim.SetTrigger("transition"); Dialogue.instance.enabled = true; givingRedAName = false; cursor.SetActive(false); } } if (currentmenu == garynamemenu) { if (selectedOption == 0) { currentmenu = nameselectionmenu; nameselectionmenu.SetActive(true); names.futureName = ""; } else { currentmenu = null; switch (GameData.instance.version) { case Version.Blue: switch (selectedOption) { case 1: GameData.instance.rivalName = "RED"; break; case 2: GameData.instance.rivalName = "ASH"; break; case 3: GameData.instance.rivalName = "JACK"; break; } break; case Version.Red: switch (selectedOption) { case 1: GameData.instance.rivalName = "BLUE"; break; case 2: GameData.instance.rivalName = "GARY"; break; case 3: GameData.instance.rivalName = "JOHN"; break; } break; } tutanim.SetTrigger("transition"); Dialogue.instance.enabled = true; givingRedAName = false; cursor.SetActive(false); } } } }
IEnumerator MainUpdate() { if (currentBagPosition == 0) { offscreenindexup = -1; offscreenindexdown = 3; } amountText.text = amountToTask.ToString(); if (currentMenu == quantitymenu && Dialogue.instance.finishedText) { if (Inputs.pressed("down")) { amountToTask--; } if (Inputs.pressed("up")) { amountToTask++; } if (amountToTask < 1) { amountToTask = maximumItem; } if (amountToTask > maximumItem) { amountToTask = 1; } } if (currentMenu == itemwindow && Dialogue.instance.finishedText) { if (Inputs.pressed("down")) { currentBagPosition++; if (currentBagPosition == offscreenindexdown && currentBagPosition <= Items.instance.items.Count && Items.instance.items.Count > 3) { offscreenindexup++; offscreenindexdown++; } MathE.Clamp(ref currentBagPosition, 0, Items.instance.items.Count); UpdateBagScreen(); } if (Inputs.pressed("up")) { currentBagPosition--; if (currentBagPosition == offscreenindexup && offscreenindexup > -1) { offscreenindexup--; offscreenindexdown--; } MathE.Clamp(ref currentBagPosition, 0, Items.instance.items.Count); UpdateBagScreen(); } if (currentBagPosition != Items.instance.items.Count) { maximumItem = Items.instance.items [currentBagPosition].quantity; } else { maximumItem = 0; } } if (currentMenu == null && (currentMenu != quantitymenu || currentMenu != itemwindow)) { } else { if (currentMenu == usetossmenu && Dialogue.instance.finishedText) { if (Inputs.pressed("down")) { selectedOption++; MathE.Clamp(ref selectedOption, 0, 1); UpdateUseTossScreen(); } if (Inputs.pressed("up")) { selectedOption--; MathE.Clamp(ref selectedOption, 0, 1); UpdateUseTossScreen(); } } } if (Inputs.pressed("select") && Dialogue.instance.finishedText && currentBagPosition != Items.instance.items.Count) { if (!switching) { switching = true; selectCursor.gameObject.SetActive(true); selectBag = currentBagPosition; UpdateBagScreen(); } else { //our Bag selectCursor.gameObject.SetActive(false); Item item = Items.instance.items[selectBag]; Items.instance.items[selectBag] = Items.instance.items[currentBagPosition]; Items.instance.items[currentBagPosition] = item; switching = false; UpdateBagScreen(); } } if (Dialogue.instance.finishedText) { if (Inputs.pressed("a")) { SoundManager.instance.PlayABSound(); if (currentMenu == itemwindow) { if (currentBagPosition == Items.instance.items.Count) { MainMenu.instance.selectedOption = 0; MainMenu.instance.currentmenu = MainMenu.instance.thismenu; this.gameObject.SetActive(false); } else { amountToTask = 1; usetossmenu.SetActive(true); UpdateUseTossScreen(); switching = false; selectCursor.gameObject.SetActive(true); cursor.SetActive(true); currentMenu = usetossmenu; } } else if (currentMenu == usetossmenu) { if (selectedOption == 0) { if (Items.instance.items.Count > 0) { ItemMode1(); Player.instance.UseItem(Items.instance.items [currentBagPosition].name); } } if (selectedOption == 1) { if (Items.instance.items.Count > 0) { ItemMode2(); quantitymenu.SetActive(true); currentMenu = quantitymenu; } } } else if (currentMenu == quantitymenu) { if (ItemMode == 1) { //use item } if (ItemMode == 2) { if (!Items.instance.items[currentBagPosition].isKeyItem) { yield return(Dialogue.instance.text("Is it OK to toss \\l" + Items.instance.items[currentBagPosition].name + "?")); yield return(StartCoroutine(Dialogue.instance.prompt())); if (Dialogue.instance.selectedOption == 0) { yield return(Dialogue.instance.text("Threw away " + Items.instance.items[currentBagPosition].name + ".")); StartCoroutine(TossItem()); } else { Dialogue.instance.Deactivate(); UpdateBagScreen(); cursor.SetActive(true); currentMenu = itemwindow; } } else { StartCoroutine(TooImportantToToss()); } } } } if (Inputs.pressed("b")) { SoundManager.instance.PlayABSound(); if (currentMenu == itemwindow) { switching = false; selectCursor.gameObject.SetActive(false); MainMenu.instance.currentmenu = MainMenu.instance.thismenu; Inputs.Enable("start"); this.gameObject.SetActive(false); } else if (currentMenu == usetossmenu) { currentMenu = itemwindow; selectCursor.gameObject.SetActive(false); UpdateBagScreen(); } else if (currentMenu == quantitymenu) { if (ItemMode == 2) { selectCursor.gameObject.SetActive(false); UpdateBagScreen(); currentMenu = itemwindow; } } } foreach (GameObject menu in allMenus) { if (menu != currentMenu) { menu.SetActive(false); } else { menu.SetActive(true); } if (menu == usetossmenu && (currentMenu == quantitymenu)) { menu.SetActive(true); } if (menu == quantitymenu && (currentMenu == itemwindow)) { menu.SetActive(false); } if (menu == itemwindow && (currentMenu == quantitymenu || currentMenu == usetossmenu)) { menu.SetActive(true); } if (currentMenu == null) { indicator.SetActive(false); } } } }
public void Process() { Output = MathE.Sigmoid(Input + Bias); }
private void UpdateModel(int[][] Obs) { int N = states; int M = observationSymbols; int K = Obs.GetLength(0); Dictionary <int, double[, ]> alphas = new Dictionary <int, double[, ]>(); Dictionary <int, double[, ]> betas = new Dictionary <int, double[, ]>(); Dictionary <int, double[, ]> gammas = new Dictionary <int, double[, ]>(); Dictionary <int, double[, , ]> etas = new Dictionary <int, double[, , ]>(); for (int k = 0; k < K; k++) { int[] O = Obs[k]; int T = O.Length; var logAlpha = LogSpaceForward(O); var logBeta = LogSpaceBackward(O); var logGamma = LogSpaceGamma(O, logAlpha, logBeta); var logEta = LogSpaceEta(O, logAlpha, logBeta); alphas[k] = logAlpha; betas[k] = logBeta; gammas[k] = logGamma; etas[k] = logEta; } #region Re-estimation of parameters // re-sestimate pi for (int i = 0; i < N; i++) { double logpi = MathE.LOGZERO; for (int k = 0; k < K; k++) { var logGamma = gammas[k]; int T = Obs[k].Length; logpi = MathE.elnsum(logpi, logGamma[0, i]); } logPi[i] = MathE.elnproduct(logpi, -K); } // re-estimate A for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { double numer = MathE.LOGZERO; double denom = MathE.LOGZERO; for (int k = 0; k < K; k++) { var logEta = etas[k]; var logGamma = gammas[k]; int T = Obs[k].Length; for (int t = 0; t < T - 1; t++) { numer = MathE.elnsum(numer, logEta[t, i, j]); denom = MathE.elnsum(denom, logGamma[t, i]); } } logTransition[i, j] = MathE.elnproduct(numer, -denom); } } // re-estimate B for (int j = 0; j < N; j++) { for (int ki = 0; ki < M; ki++) { double numer = MathE.LOGZERO; double denom = MathE.LOGZERO; for (int k = 0; k < K; k++) { var logEta = etas[k]; var logGamma = gammas[k]; int T = Obs[k].Length; for (int t = 0; t < T; t++) { if (Obs[k][t] == ki) { numer = MathE.elnsum(numer, logGamma[t, j]); } denom = MathE.elnsum(denom, logGamma[t, j]); } } logEmission[j, ki] = MathE.elnproduct(numer, -denom); } } #endregion }
// Update is called once per frame void Update() { pricetext.text = "$" + fullPrice.ToString(); moneytext.text = "$" + GameData.instance.money.ToString(); if (currentMenu == quantitymenu) { if (ItemMode == 1) { itemPrice = ItemsToBuy[currentBagPosition - offscreenindexup - 1].intPrice; maximumItem = 99; } if (ItemMode == 2) { //Set the selling price of the selected item. itemPrice = PokemonData.itemPrices[Items.instance.items[currentBagPosition].name] / 2; maximumItem = Items.instance.items[currentBagPosition].quantity; } } if (Dialogue.instance.finishedText) { if (currentMenu == quantitymenu) { fullPrice = amountToTask * itemPrice; if (Inputs.pressed("down")) { amountToTask--; MathE.Wrap(ref amountToTask, 1, maximumItem); UpdateQuantityScreen(); } if (Inputs.pressed("up")) { amountToTask++; MathE.Wrap(ref amountToTask, 1, maximumItem); UpdateQuantityScreen(); } } if (currentMenu == martwindow) { if (Inputs.pressed("down")) { currentBagPosition++; if (currentBagPosition == offscreenindexdown && offscreenindexdown != martlist.Count + 1) { offscreenindexup++; offscreenindexdown++; } MathE.Clamp(ref currentBagPosition, 0, martlist.Count); UpdateBuyScreen(); } if (Inputs.pressed("up")) { currentBagPosition--; if (currentBagPosition == offscreenindexup && offscreenindexup > -1) { offscreenindexup--; offscreenindexdown--; } MathE.Clamp(ref currentBagPosition, 0, martlist.Count); UpdateBuyScreen(); } } if (currentMenu == itemwindow) { if (Inputs.pressed("down")) { currentBagPosition++; if (currentBagPosition == offscreenindexdown && offscreenindexdown != Items.instance.items.Count + 1) { offscreenindexup++; offscreenindexdown++; } MathE.Clamp(ref currentBagPosition, 0, Items.instance.items.Count); UpdateSellScreen(); } if (Inputs.pressed("up")) { currentBagPosition--; if (currentBagPosition == offscreenindexup && offscreenindexup > -1) { offscreenindexup--; offscreenindexdown--; } MathE.Clamp(ref currentBagPosition, 0, Items.instance.items.Count); UpdateSellScreen(); } if (currentBagPosition != Items.instance.items.Count) { maximumItem = Items.instance.items[currentBagPosition].quantity; } else { maximumItem = 0; } } if (currentMenu == buysellwindow) { cursor.SetPosition(8, 128 - 16 * selectedOption); cursor.SetActive(true); if (Inputs.pressed("down")) { selectedOption++; MathE.Clamp(ref selectedOption, 0, 2); } if (Inputs.pressed("up")) { selectedOption--; MathE.Clamp(ref selectedOption, 0, 2); } if (Inputs.pressed("b")) { play.menuActive = false; cursor.SetActive(false); Inputs.Enable("start"); this.gameObject.SetActive(false); } } if (Inputs.pressed("select")) { if (currentMenu == itemwindow) { if (!switching) { switching = true; selectBag = currentBagPosition; } else if (currentBagPosition != Items.instance.items.Count) { //our Bag Item item = Items.instance.items[selectBag]; Items.instance.items[selectBag] = Items.instance.items[currentBagPosition]; Items.instance.items[currentBagPosition] = item; switching = false; selectCursor.gameObject.SetActive(false); UpdateSellScreen(); } } } if (Inputs.pressed("a")) { SoundManager.instance.PlayABSound(); if (currentMenu == buysellwindow) { if (selectedOption == 0) { currentBagPosition = 0; currentMenu = martwindow; UpdateBuyScreen(); } if (selectedOption == 1) { currentBagPosition = 0; currentMenu = itemwindow; UpdateSellScreen(); } if (selectedOption == 2) { play.menuActive = false; Inputs.Enable("start"); cursor.SetActive(false); this.gameObject.SetActive(false); return; } } else if (currentMenu == martwindow) { if (currentBagPosition == martlist.Count) { UpdateBuySellScreen(); currentMenu = buysellwindow; } else { amountToTask = 1; UpdateQuantityScreen(); cursor.SetActive(false); currentMenu = quantitymenu; ItemMode1(); } } else if (currentMenu == itemwindow) { if (currentBagPosition == Items.instance.items.Count) { UpdateBuySellScreen(); switching = false; selectCursor.gameObject.SetActive(false); currentMenu = buysellwindow; } else { if (!Items.instance.items[currentBagPosition].isKeyItem && PokemonData.itemPrices[Items.instance.items[currentBagPosition].name] > 0) { amountToTask = 1; UpdateQuantityScreen(); cursor.SetActive(false); currentMenu = quantitymenu; ItemMode2(); } else { switching = false; StartCoroutine(UnsellableItem()); } } } else if (currentMenu == quantitymenu) { if (ItemMode == 2) { if (!Items.instance.items[currentBagPosition].isKeyItem) { GameData.instance.money += fullPrice; Items.instance.RemoveItem(amountToTask, currentBagPosition); currentMenu = itemwindow; cursor.SetActive(true); selectCursor.gameObject.SetActive(false); UpdateSellScreen(); } } if (ItemMode == 1) { if (GameData.instance.money >= fullPrice) { GameData.instance.money -= fullPrice; Items.instance.AddItem(martlist[currentBagPosition], amountToTask); currentMenu = martwindow; cursor.SetActive(true); selectCursor.gameObject.SetActive(false); UpdateBuyScreen(); } else { StartCoroutine(NotEnoughMoney()); } } } } if (Inputs.pressed("b")) { SoundManager.instance.PlayABSound(); if (currentMenu == martwindow) { UpdateBuySellScreen(); currentMenu = buysellwindow; } else if (currentMenu == itemwindow) { switching = false; UpdateBuySellScreen(); selectCursor.gameObject.SetActive(false); currentMenu = buysellwindow; } else if (currentMenu == quantitymenu) { if (ItemMode == 1) { selectBag = -1; cursor.SetActive(true); selectCursor.gameObject.SetActive(false); currentMenu = martwindow; } if (ItemMode == 2) { selectBag = -1; cursor.SetActive(true); selectCursor.gameObject.SetActive(false); currentMenu = itemwindow; } } } } foreach (GameObject menu in allMenus) { if (menu != currentMenu) { menu.SetActive(false); } else { menu.SetActive(true); } if (menu == martwindow && (currentMenu == quantitymenu && ItemMode == 1)) { menu.SetActive(true); } if (menu == itemwindow && (currentMenu == quantitymenu && ItemMode == 2)) { menu.SetActive(true); } if (menu == quantitymenu && (currentMenu == itemwindow || currentMenu == martwindow)) { menu.SetActive(false); } if (menu == buysellwindow && (currentMenu == quantitymenu || currentMenu == itemwindow || currentMenu == martwindow)) { menu.SetActive(true); } } }
public double DerivateProcess(double value) { return(MathE.SigmoidDerived(value)); }
public int[] PredictObservationSequence(int T) { var emission = MathE.eexpify(logEmission); var transition = MathE.eexpify(logTransition); var pi = MathE.eexpify(logPi); List <int> O = new List <int>(); Random rand = new Random(); int[] states_ = new int[states]; for (int j = 0; j < states; j++) { states_[j] = j; } int state = RouletteSelection <int>(states_, pi, rand); for (int t = 0; t < T; t++) { // Get next observation state double[] probabilities = new double[observationSymbols]; int[] observations = new int[observationSymbols]; bool stop = true; for (int j = 0; j < observationSymbols; j++) { probabilities[j] = emission[state, j]; observations[j] = j; if (probabilities[j] > 0) { stop = false; } } if (stop) { break; } int winner = RouletteSelection <int>(observations, probabilities, rand); O.Add(winner); stop = true; // Proceed to next hidden state probabilities = new double[states]; int[] nextStates = new int[states]; for (int j = 0; j < states; j++) { probabilities[j] = transition[state, j]; nextStates[j] = j; if (probabilities[j] > 0) { stop = false; } } if (stop) { break; } winner = RouletteSelection <int>(nextStates, probabilities, rand); state = winner; } return(O.ToArray()); }
ulong MapDegToRot(double deg) { return((ulong)MathE.ReMap( deg, 0.0, 360.0, 0.0, ulong.MaxValue)); }
IEnumerator MainUpdate() { numberOfItems = ItemMode == 2 ? Items.instance.items.Count : Items.instance.pcItems.Count; if (currentBagPosition == 0) { offscreenindexup = -1; offscreenindexdown = 3; } if (currentMenu == quantitymenu) { if (Inputs.pressed("down")) { amountToTask--; MathE.Wrap(ref amountToTask, 1, maximumItem); UpdateQuantityScreen(); } if (Inputs.pressed("up")) { amountToTask++; MathE.Wrap(ref amountToTask, 1, maximumItem); UpdateQuantityScreen(); } } if (currentMenu == itemwindow) { if (Inputs.pressed("down")) { currentBagPosition++; if (currentBagPosition == offscreenindexdown && currentBagPosition <= numberOfItems && numberOfItems > 3) { offscreenindexup++; offscreenindexdown++; } MathE.Clamp(ref currentBagPosition, 0, numberOfItems); UpdateBagScreen(); } if (Inputs.pressed("up")) { currentBagPosition--; if (currentBagPosition == offscreenindexup && offscreenindexup > -1) { offscreenindexup--; offscreenindexdown--; } MathE.Clamp(ref currentBagPosition, 0, numberOfItems); UpdateBagScreen(); } } if (currentMenu == mainwindow) { if (Inputs.pressed("down")) { selectedOption++; MathE.Clamp(ref selectedOption, 0, 3); UpdateMainScreen(); } if (Inputs.pressed("up")) { selectedOption--; MathE.Clamp(ref selectedOption, 0, 3); UpdateMainScreen(); } } if (Inputs.pressed("select")) { if (currentMenu == itemwindow) { if (!switching) { switching = true; selectCursor.gameObject.SetActive(true); selectBag = currentBagPosition; UpdateBagScreen(); } else if (currentBagPosition != numberOfItems) { //our bag if (ItemMode == 2) { selectCursor.gameObject.SetActive(false); Item item = Items.instance.items[selectBag]; Items.instance.items[selectBag] = Items.instance.items[currentBagPosition]; Items.instance.items[currentBagPosition] = item; switching = false; } if (ItemMode == 1 || ItemMode == 3) { Item item = Items.instance.pcItems[selectBag]; Items.instance.pcItems[selectBag] = Items.instance.pcItems[currentBagPosition]; Items.instance.pcItems[currentBagPosition] = item; switching = false; } UpdateBagScreen(); } } } if (Inputs.pressed("a")) { SoundManager.instance.PlayABSound(); if (currentMenu == itemwindow) { if (currentBagPosition == numberOfItems) { Dialogue.instance.Deactivate(); Dialogue.instance.fastText = true; switching = false; selectCursor.gameObject.SetActive(false); Dialogue.instance.keepTextOnScreen = true; Dialogue.instance.needButtonPress = false; yield return(Dialogue.instance.text("What do you want\\lto do?")); currentMenu = mainwindow; UpdateMainScreen(); } else { if (!itemSlots[currentBagPosition - offscreenindexup - 1].isKeyItem && ItemMode != 3) { amountToTask = 1; Dialogue.instance.Deactivate(); Dialogue.instance.fastText = true; Dialogue.instance.keepTextOnScreen = true; Dialogue.instance.needButtonPress = false; yield return(Dialogue.instance.text("How much?")); currentMenu = quantitymenu; UpdateQuantityScreen(); } else if (itemSlots[currentBagPosition - offscreenindexup - 1].isKeyItem) { switch (ItemMode) { case 1: StartCoroutine(WithdrawItem()); break; case 2: StartCoroutine(DepositItem()); break; } } else if (ItemMode == 3) { amountToTask = 1; Dialogue.instance.Deactivate(); Dialogue.instance.fastText = true; Dialogue.instance.keepTextOnScreen = true; Dialogue.instance.needButtonPress = false; yield return(Dialogue.instance.text("How much?")); currentMenu = quantitymenu; UpdateQuantityScreen(); } } if (currentBagPosition != numberOfItems && itemSlots[currentBagPosition - offscreenindexup - 1].isKeyItem && ItemMode == 3) { StartCoroutine(TooImportantToToss()); } } else if (currentMenu == mainwindow) { if (selectedOption == 0) { UpdateBagScreen(); StartCoroutine(ItemMode1()); } if (selectedOption == 1) { UpdateBagScreen(); StartCoroutine(ItemMode2()); } if (selectedOption == 2) { UpdateBagScreen(); StartCoroutine(ItemMode3()); } if (selectedOption == 3) { Close(); } } else if (currentMenu == quantitymenu) { if (ItemMode == 3) { if (!itemSlots[currentBagPosition - offscreenindexup - 1].isKeyItem) { StartCoroutine(TossItem()); } } if (ItemMode == 1) { StartCoroutine(WithdrawItem()); } if (ItemMode == 2) { StartCoroutine(DepositItem()); } } } if (Inputs.pressed("b")) { SoundManager.instance.PlayABSound(); if (currentMenu == mainwindow) { Close(); } else if (currentMenu == itemwindow) { switching = false; selectCursor.gameObject.SetActive(false); StartCoroutine(WhatDoText()); currentMenu = mainwindow; UpdateMainScreen(); } else if (currentMenu == quantitymenu) { if (ItemMode == 1) { currentBagPosition = 0; selectBag = -1; StartCoroutine(WhatWithdrawText()); currentMenu = itemwindow; } if (ItemMode == 2) { currentBagPosition = 0; selectBag = -1; StartCoroutine(WhatDepositText()); currentMenu = itemwindow; } if (ItemMode == 3) { currentBagPosition = 0; selectBag = -1; StartCoroutine(WhatTossText()); currentMenu = itemwindow; } } } foreach (GameObject menu in allMenus) { if (menu != currentMenu) { menu.SetActive(false); } else { menu.SetActive(true); } if (menu == mainwindow && (currentMenu == itemwindow || currentMenu == quantitymenu)) { menu.SetActive(true); } if (menu == quantitymenu && (currentMenu == itemwindow || currentMenu == mainwindow)) { menu.SetActive(false); } if (menu == itemwindow && currentMenu == quantitymenu) { menu.SetActive(true); } } yield return(0); }
public double ToDeg() { return(MathE.ReMap( rot, 0, ulong.MaxValue, 0, 360)); }
// Use this for initialization // Update is called once per frame void Update() { if (deactivated && !Player.disabled) { Player.disabled = true; } buycoinstext [0].text = GameData.instance.money.ToString(); buycoinstext [1].text = GameData.instance.coins.ToString(); if (!finishedThePrompt) { if (Inputs.pressed("a")) { finishedThePrompt = true; StopAllCoroutines(); Inputs.dialogueCheck = false; dialoguetext.text = ""; cursor.SetActive(false); } if (Inputs.pressed("b")) { switch (taskType) { case 0: selectedOption = 1; break; case 1: selectedOption = 3; break; } StopAllCoroutines(); Inputs.dialogueCheck = false; dialoguetext.text = ""; cursor.SetActive(false); finishedThePrompt = true; } if (Inputs.pressed("down")) { selectedOption++; switch (taskType) { case 0: MathE.Clamp(ref selectedOption, 0, 1); cursor.SetPosition(120, 72 - 16 * selectedOption); break; case 1: MathE.Clamp(ref selectedOption, 0, 2); cursor.SetPosition(120, 40 - 16 * selectedOption); break; } } if (Inputs.pressed("up")) { selectedOption--; switch (taskType) { case 0: MathE.Clamp(ref selectedOption, 0, 1); cursor.SetPosition(120, 72 - 16 * selectedOption); break; case 1: MathE.Clamp(ref selectedOption, 0, 2); cursor.SetPosition(120, 40 - 16 * selectedOption); break; } } } if (GameData.instance.textChoice == 2) { scrollequation = 3 * 0.016f; } if (GameData.instance.textChoice == 1) { scrollequation = 2f * 0.016f; } if (GameData.instance.textChoice == 0) { scrollequation = 1f * 0.016f; } }
public double ToRad() { return(MathE.ReMap( rot, 0, ulong.MaxValue, 0, (double)MathE.TAU)); }
// Use this for initialization // Update is called once per frame void Update() { if (isLowerCase) { nameselectscreen.sprite = lowercase; } else { nameselectscreen.sprite = uppercase; } displaytext.text = futureName; if (BeginHandler.instance.givingRedAName || BeginHandler.instance.givingGaryAName) { maxNameSize = 7; } else { maxNameSize = 10; } if (currentYselection == 5) { currentXselection = 0; } cursor.SetPosition(8 + 16 * currentXselection, 96 - 16 * currentYselection); if (Inputs.pressed("right")) { if (currentYselection != 5) { currentXselection++; } } if (Inputs.pressed("left")) { if (currentYselection != 5) { currentXselection--; } } if (Inputs.pressed("up")) { currentYselection--; } if (Inputs.pressed("down")) { currentYselection++; } MathE.Wrap(ref currentXselection, 0, 8); MathE.Wrap(ref currentYselection, 0, 5); if (Inputs.pressed("b")) { if (futureName.Length > 0) { futureName = futureName.Remove(futureName.Length - 1); } } if (Inputs.pressed("start")) { if (futureName.Length != 0) { if (BeginHandler.instance.givingRedAName) { GameData.instance.playerName = futureName; BeginHandler.instance.tutanim.SetTrigger("transition"); Dialogue.instance.enabled = true; BeginHandler.instance.givingRedAName = false; this.gameObject.SetActive(false); } if (BeginHandler.instance.givingGaryAName) { GameData.instance.rivalName = futureName; BeginHandler.instance.tutanim.SetTrigger("transition"); Dialogue.instance.enabled = true; BeginHandler.instance.givingGaryAName = false; this.gameObject.SetActive(false); } BeginHandler.instance.currentmenu = null; } } if (Inputs.pressed("a")) { if (currentXselection == 8 && currentYselection == 4) { if (futureName.Length != 0) { if (BeginHandler.instance.givingRedAName) { GameData.instance.playerName = futureName; BeginHandler.instance.tutanim.SetTrigger("transition"); Dialogue.instance.enabled = true; BeginHandler.instance.givingRedAName = false; cursor.SetActive(false); this.gameObject.SetActive(false); } if (BeginHandler.instance.givingGaryAName) { GameData.instance.rivalName = futureName; BeginHandler.instance.tutanim.SetTrigger("transition"); Dialogue.instance.enabled = true; BeginHandler.instance.givingGaryAName = false; cursor.SetActive(false); this.gameObject.SetActive(false); } BeginHandler.instance.currentmenu = null; } } else { if (currentXselection == 0 && currentYselection == 5) { isLowerCase = !isLowerCase; } else if (futureName.Length == maxNameSize) { return; } else { futureName += currentYselection < 3 && isLowerCase ? characters[currentYselection, currentXselection].ToLower() : characters[currentYselection, currentXselection]; } } } }
public static void UpdateFrequency(object sender, ImageType imageType, FrequencyType frequencyType, ref ThemeOptions ThemeOptions) { double input = 0; TextBox sourceTextBox = sender as TextBox; // Process the Input try { string inputText = sourceTextBox.Text; if (inputText.Contains('%')) { inputText = inputText.Substring(0, inputText.IndexOf('%')); // removes % from input if it was left } if (frequencyType == FrequencyType.Relative) { input = Math.Max(0, double.Parse(inputText)); } else if (frequencyType == FrequencyType.Exact) { input = MathE.Clamp(double.Parse(inputText), 0, 100); } } catch (Exception exception) { Debug.WriteLine(exception); // incorrect value entered, end update and reset text (reset externally) return; } // Update a Frequency if (frequencyType == FrequencyType.Relative) // set the relative chance & recalculate exact chances to represent said change { Debug.WriteLine("Relative"); if (input == 0) { int zeroCount = 0; if (ThemeOptions.RelativeFrequency[ImageType.Static] == 0) { zeroCount++; } if (ThemeOptions.RelativeFrequency[ImageType.GIF] == 0) { zeroCount++; } if (ThemeOptions.RelativeFrequency[ImageType.Video] == 0) { zeroCount++; } if (zeroCount >= 2) // attempted to make all frequencies 0%, cancel this change { Debug.WriteLine("Cannot have 0% probability across all entries. Change cancelled"); return; } } ThemeOptions.RelativeFrequency[imageType] = input / 100; // the actual value is a percentage RecalculateExactFrequency(ref ThemeOptions); } else if (frequencyType == FrequencyType.Exact) // set a new exact chance, recalculating the remaining exact chances & also the relative chances to represent this change { Debug.WriteLine("Exact"); ThemeOptions.ExactFrequency[imageType] = input / 100; // the actual value is a percentage if (input < 100 && input > 0) { CalculateExactFrequency(imageType, ref ThemeOptions); RecalculateRelativeFrequency(imageType, false, ref ThemeOptions); } else if (input >= 100) // exact chance of 1, set everything else to 0 { if (imageType != ImageType.Static) { ThemeOptions.ExactFrequency[ImageType.Static] = 0; } if (imageType != ImageType.GIF) { ThemeOptions.ExactFrequency[ImageType.GIF] = 0; } if (imageType != ImageType.Video) { ThemeOptions.ExactFrequency[ImageType.Video] = 0; } RecalculateRelativeFrequency(imageType, true, ref ThemeOptions); } else if (input <= 0) // exact chance of 0, set everything else to 0.5 { if (imageType != ImageType.Static) { ThemeOptions.ExactFrequency[ImageType.Static] = 0.5; } if (imageType != ImageType.GIF) { ThemeOptions.ExactFrequency[ImageType.GIF] = 0.5; } if (imageType != ImageType.Video) { ThemeOptions.ExactFrequency[ImageType.Video] = 0.5; } RecalculateRelativeFrequency(imageType, true, ref ThemeOptions); } } }