public void ResetNeuron() { int inputsCnt = Inputs.Count; Inputs.Clear(); PreviousInputs.Clear(); for (int inputNo = 0; inputNo < inputsCnt; inputNo++) { if (LayerNo == 0) { Inputs.Add(new Input() { Value = 0.0, Weight = 1.0, ConnectedWithPreviousLayerNeuronNo = -1 }); PreviousInputs.Add(new Input() { Value = 0.0, Weight = 1.0, ConnectedWithPreviousLayerNeuronNo = -1 }); } else { double weight = new RandomWeight().GenerateRandomWeight(); Inputs.Add(new Input() { Value = IsBias ? BiasValue : 0.0, Weight = weight, ConnectedWithPreviousLayerNeuronNo = inputNo }); PreviousInputs.Add(new Input() { Value = IsBias ? BiasValue : 0.0, Weight = weight, ConnectedWithPreviousLayerNeuronNo = inputNo }); } } }
public void HandleButtons() { // Get the current inputs var input = API.Input.Get(); // Helper for getting the state of a key, making sure it's been released before pressed again bool getKeyState(string name, bool singleInput = true) { if (!input.ContainsKey(name)) { PreviousInputs[name] = false; return(false); } if (PreviousInputs.ContainsKey(name) && PreviousInputs[name] && singleInput) { PreviousInputs[name] = input[name]; return(false); } PreviousInputs[name] = input[name]; return(input[name]); } // Toggle showing the UI if (getKeyState("LeftCtrl", false) && getKeyState("X")) { ToggleShowUI(); } // Don't handle inputs if we're not showing the UI if (!ShowUI) { return; } // Get properties var menu = GetCurrentMenu(); var selectedIndex = GetSelectedMenuItemIndex; var menuItem = menu.ElementAtOrDefault(selectedIndex); // If the user selects the item if (getKeyState("Enter") || getKeyState("Space")) { // If null we go back to the previous menu if (menuItem == null) { SelectedMenuItem.RemoveAt(SelectedMenuItem.Count - 1); return; } // Call handler var r = menuItem.OnSelected?.Invoke(menuItem); // If there are children we navigate to the sub-menu if (menuItem.Children.Any()) { SelectedMenuItem.Add(0); } // Unpause if the action returned true if (r == true) { ToggleShowUI(); return; } } // Menu navigation if (getKeyState("Down")) { if (selectedIndex < menu.Length - (HasBackOption ? 0 : 1)) { SelectedMenuItem[SelectedMenuItem.Count - 1]++; } else { SelectedMenuItem[SelectedMenuItem.Count - 1] = 0; } } if (getKeyState("Up")) { if (selectedIndex > 0) { SelectedMenuItem[SelectedMenuItem.Count - 1]--; } else { SelectedMenuItem[SelectedMenuItem.Count - 1] = menu.Length - (HasBackOption ? 0 : 1); } } // Horizontal menu navigation if (menuItem?.Options.Any() == true) { if (getKeyState("Left") && menuItem.CanDecreaseOptionsIndex) { menuItem.SelectedOption--; } if (getKeyState("Right") && menuItem.CanIncreaseOptionsIndex) { menuItem.SelectedOption++; } } }