/// <summary> /// Compute psudo hessian matrix and its gradient /// </summary> /// <param name="info">NetworkInfo - information about neural network</param> /// <param name="inp">Input - input data patterns used for learn</param> /// <param name="dout">Output - output data patterns used for learn</param> /// <param name="topo">Topography - neural network topography</param> /// <param name="ww">Weights - weights</param> /// <param name="act">Activation - activation function selection</param> /// <param name="gain">Gain - neuron gain</param> /// <param name="iw">Index - topography indexes</param> public void Compute(ref NetworkInfo info, ref Input inp, ref Output dout, ref Topography topo, Weights ww, ref Activation act, ref Gain gain, ref Index iw) { GradientMat = MatrixMB.Zeros(info.nw, 1); HessianMat = MatrixMB.Zeros(info.nw, info.nw); np = info.np;//number of patterns ni = info.ni;//number of inputs no = info.no;//number of outputs nw = info.nw;//number of weights nn = info.nn;//number of neurons nio = nn + ni - no; zeros = ni.Zeros(); delo = MatrixMB.Zeros(1, nio + 1); J = MatrixMB.Zeros(1, nw); for (p = 0; p < np; p++) { node.Clear(); node.AddRange(inp.Data[p]); CalculateFunctionValuesAndDerivates(ref ww, ref iw, ref topo, ref act, ref gain); for (k = 0; k < no; k++) { o = nio + k; error = dout.Data[p][k] - node[o]; J.ClearWithZeros(); s = iw.Pos(o - ni); J.Data[0][s] = -derivates[o]; delo.ClearWithZeros(); CalculateJacobian(ref ww, ref iw, ref topo); CalculateForHiddenLayer(ref iw, ref topo, ref ww); if (dout[p, 0] > 0.5) J = J * ratio; var JT = J.Transposed; GradientMat = GradientMat + JT * error; HessianMat = HessianMat + JT * J; } } }
/// <summary> /// Total error calculation /// </summary> /// <param name="info">NetworkInfo</param> /// <param name="inp">ref Input - input data patterns</param> /// <param name="dout">ref Output - output data</param> /// <param name="topo">ref Topography - topo is network topology in the form of one vector</param> /// <param name="ww">ref Weights weights</param> /// <param name="act">ref Activation - type of activation function</param> /// <param name="gain">ref Gain - strengthening the activation function</param> /// <param name="iw">ref WeightsPointers - index pointers used for network topology stored in top in the form of one vector</param> /// <remarks>Network error will be overriden so please save it</remarks> public double CalculateError(ref NetworkInfo info, ref Input inp, ref Output dout, ref Topography topo, Weights ww, ref Activation act, ref Gain gain, ref Index iw) { try { Error = 0; for (p = 0; p < info.np; p++) { node.Clear(); node.AddRange(inp.Data[p]); for (n = 0; n < info.nn; n++) { net = ww[iw.Pos(n)]; int from = iw.Pos(n) + 1; int to = iw.Pos(n + 1) - 1; for (i = from; i <= to; i++) { net += node[(int)topo[i]] * ww[i]; } node.Add(ActivationFunction.computeFunction(ref n, ref net, ref act, ref gain)); } for (k = 0; k < info.no; k++) { Error += System.Math.Pow((dout.Data[p][k] - node[info.nio + k]), 2); } } return Error; } catch (System.Exception ex) { throw new NeuralNetworkError("Błąd uaktualnienia błędu sieci neuronowej. " + ex.Message, ex); } }
public void UpdateWeights([FromBody] Weights weights, int id) { weights.Id = id; _storage.UpdateWeightsTask(weights); }
public override void Compute(List <Node> allNodes) { Moves.FillArray(Move); Weights.FillArray(Weight); }
public T Calc() { if (LayerIndex == 0) { T temp = WeightingFunction(OwnerNet.Input.First(), Weights.First()); for (int i = 1; i < OwnerNet.Input.Length; i++) { temp = AdderFunction(temp, WeightingFunction(OwnerNet.Input[i], Weights[i])); } return(ActivationFunction(temp)); } else { T temp = WeightingFunction(OwnerNet.Neurons[LayerIndex - 1].First().Calc(), Weights.First()); for (int i = 1; i < Weights.Count; i++) { temp = AdderFunction(temp, WeightingFunction(OwnerNet.Neurons[LayerIndex - 1][i].Calc(), Weights[i])); } return(ActivationFunction(temp)); } }
public double[,] GetWeights() { return(Weights.ToArray()); }
private void CalculateFunctionValuesAndDerivates(ref Weights ww, ref Index iw, ref Topography topo, ref Activation act, ref Gain gain) { derivates.Clear(); derivates.AddRange(node.Count.Zeros()); for (int n = 0; n < nn; n++)//for each neuron in network { net = ww[iw[n]];//calculate net sum for (i = iw[n] + 1; i <= iw[n + 1] - 1; i++) { net += (node[topo[i]] * ww[i]); } var res = ActivationFunction.computeFunctionDervative(ref n, ref net, ref act, ref gain);//and function value and its derivative node.Add(res.FunctionResult);//save function value for output signal from neuron derivates.Add(res.FunctionDerivative);//save function derivative value for output signal from neuron } }
protected override void AddToMenu() { var ultimateMenu = _ultimate.AddToMenu(Menu); ultimateMenu.AddItem( new MenuItem(ultimateMenu.Name + ".range", "Range").SetValue(new Slider((int)R.Range, 500, 1200))) .ValueChanged += delegate(object sender, OnValueChangeEventArgs args) { R.Range = args.GetNewValue <Slider>().Value; }; R.Range = Menu.Item(Menu.Name + ".ultimate.range").GetValue <Slider>().Value; ultimateMenu.AddItem( new MenuItem(ultimateMenu.Name + ".radius", "Spread Radius").SetValue(new Slider(450, 100, 600))) .ValueChanged += delegate(object sender, OnValueChangeEventArgs args) { _rSpreadRadius = args.GetNewValue <Slider>().Value; }; _rSpreadRadius = Menu.Item(Menu.Name + ".ultimate.radius").GetValue <Slider>().Value; var comboMenu = Menu.AddSubMenu(new Menu("Combo", Menu.Name + ".combo")); HitchanceManager.AddToMenu( comboMenu.AddSubMenu(new Menu("Hitchance", comboMenu.Name + ".hitchance")), "combo", new Dictionary <string, HitChance> { { "Q", HitChance.VeryHigh }, { "E", HitChance.High }, { "R", HitChance.VeryHigh } }); var comboQMenu = comboMenu.AddSubMenu(new Menu("Q Settings", comboMenu.Name + ".q-settings")); comboQMenu.AddItem(new MenuItem(comboQMenu.Name + ".always", "Cast Always").SetValue(true)); comboQMenu.AddItem( new MenuItem(comboQMenu.Name + ".fast-cast-min", "Fast Cast Health <= %").SetValue(new Slider(20))); comboQMenu.AddItem(new MenuItem(comboQMenu.Name + ".separator", string.Empty)); comboQMenu.AddItem(new MenuItem(comboQMenu.Name + ".stacks", "Min. Stacks")).SetValue(new Slider(3, 1, 3)); comboQMenu.AddItem(new MenuItem(comboQMenu.Name + ".or", "OR")); comboQMenu.AddItem(new MenuItem(comboQMenu.Name + ".min", "Min. Hits").SetValue(new Slider(2, 1, 5))); var comboEMenu = comboMenu.AddSubMenu(new Menu("E Settings", comboMenu.Name + ".e-settings")); comboEMenu.AddItem(new MenuItem(comboEMenu.Name + ".always", "Cast Always").SetValue(false)); comboEMenu.AddItem(new MenuItem(comboEMenu.Name + ".separator", string.Empty)); comboEMenu.AddItem(new MenuItem(comboEMenu.Name + ".stacks", "Min. Stacks")).SetValue(new Slider(3, 1, 3)); comboEMenu.AddItem(new MenuItem(comboEMenu.Name + ".or", "OR")); comboEMenu.AddItem(new MenuItem(comboEMenu.Name + ".min", "Min. Hits").SetValue(new Slider(3, 1, 5))); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".q", "Use Q").SetValue(true)); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".e", "Use E").SetValue(true)); var harassMenu = Menu.AddSubMenu(new Menu("Harass", Menu.Name + ".harass")); HitchanceManager.AddToMenu( harassMenu.AddSubMenu(new Menu("Hitchance", harassMenu.Name + ".hitchance")), "harass", new Dictionary <string, HitChance> { { "Q", HitChance.High }, { "E", HitChance.High } }); ResourceManager.AddToMenu( harassMenu, new ResourceManagerArgs( "harass", ResourceType.Mana, ResourceValueType.Percent, ResourceCheckType.Minimum) { DefaultValue = 30 }); var harassQMenu = harassMenu.AddSubMenu(new Menu("Q Settings", harassMenu.Name + ".q-settings")); harassQMenu.AddItem(new MenuItem(harassQMenu.Name + ".always", "Cast Always").SetValue(true)); harassQMenu.AddItem( new MenuItem(harassQMenu.Name + ".fast-cast-min", "Fast Cast Health <= %").SetValue(new Slider(25))); harassQMenu.AddItem(new MenuItem(harassQMenu.Name + ".separator", string.Empty)); harassQMenu.AddItem(new MenuItem(harassQMenu.Name + ".stacks", "Min. Stacks")).SetValue(new Slider(3, 1, 3)); harassQMenu.AddItem(new MenuItem(harassQMenu.Name + ".or", "OR")); harassQMenu.AddItem(new MenuItem(harassQMenu.Name + ".min", "Min. Hits").SetValue(new Slider(2, 1, 5))); var harassEMenu = harassMenu.AddSubMenu(new Menu("E Settings", harassMenu.Name + ".e-settings")); harassEMenu.AddItem(new MenuItem(harassEMenu.Name + ".always", "Cast Always").SetValue(true)); harassEMenu.AddItem(new MenuItem(harassEMenu.Name + ".separator", string.Empty)); harassEMenu.AddItem(new MenuItem(harassEMenu.Name + ".stacks", "Min. Stacks")).SetValue(new Slider(2, 1, 3)); harassEMenu.AddItem(new MenuItem(harassEMenu.Name + ".or", "OR")); harassEMenu.AddItem(new MenuItem(harassEMenu.Name + ".min", "Min. Hits").SetValue(new Slider(3, 1, 5))); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".q", "Use Q").SetValue(true)); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".e", "Use E").SetValue(true)); var laneclearMenu = Menu.AddSubMenu(new Menu("Lane Clear", Menu.Name + ".lane-clear")); ResourceManager.AddToMenu( laneclearMenu, new ResourceManagerArgs( "lane-clear-q", ResourceType.Mana, ResourceValueType.Percent, ResourceCheckType.Minimum) { Prefix = "Q", Advanced = true, MaxValue = 101, LevelRanges = new SortedList <int, int> { { 1, 6 }, { 6, 12 }, { 12, 18 } }, DefaultValues = new List <int> { 50, 30, 30 } }); ResourceManager.AddToMenu( laneclearMenu, new ResourceManagerArgs( "lane-clear-e", ResourceType.Mana, ResourceValueType.Percent, ResourceCheckType.Minimum) { Prefix = "E", Advanced = true, MaxValue = 101, LevelRanges = new SortedList <int, int> { { 1, 6 }, { 6, 12 }, { 12, 18 } }, DefaultValues = new List <int> { 50, 30, 30 } }); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".q", "Use Q").SetValue(true)); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".e", "Use E").SetValue(true)); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".min", "Min. Hits").SetValue(new Slider(3, 1, 5))); var fleeMenu = Menu.AddSubMenu(new Menu("Flee", Menu.Name + ".flee")); fleeMenu.AddItem(new MenuItem(fleeMenu.Name + ".e", "Use E").SetValue(true)); var killstealMenu = Menu.AddSubMenu(new Menu("Killsteal", Menu.Name + ".killsteal")); killstealMenu.AddItem(new MenuItem(killstealMenu.Name + ".q", "Use Q").SetValue(true)); var miscMenu = Menu.AddSubMenu(new Menu("Misc", Menu.Name + ".miscellaneous")); var eGapcloserMenu = miscMenu.AddSubMenu(new Menu("E Gapcloser", miscMenu.Name + "e-gapcloser")); GapcloserManager.AddToMenu( eGapcloserMenu, new HeroListManagerArgs("e-gapcloser") { IsWhitelist = false, Allies = false, Enemies = true, DefaultValue = false }, true); BestTargetOnlyManager.AddToMenu(eGapcloserMenu, "e-gapcloser"); Weights.AddItem(new Weights.Item("w-stacks", "W Stacks", 5, false, t => GetWStacks(t) + 1)); IndicatorManager.AddToMenu(DrawingManager.Menu, true); IndicatorManager.Add("Q", hero => Q.IsReady() ? Q.GetDamage(hero, 1) : 0); IndicatorManager.Add(E); IndicatorManager.Add(R); IndicatorManager.Finale(); _wStacks = DrawingManager.Add("W Stacks", true); }
protected override void AddToMenu() { var ultimateMenu = Menu.AddSubMenu(new Menu("Ultimate", Menu.Name + ".ultimate")); var blitzMenu = ultimateMenu.AddSubMenu(new Menu("Blitzcrank", ultimateMenu.Name + ".blitzcrank")); HeroListManager.AddToMenu( blitzMenu.AddSubMenu(new Menu("Blacklist", blitzMenu.Name + ".blacklist")), "blitzcrank", false, false, true, false); blitzMenu.AddItem(new MenuItem(blitzMenu.Name + ".r", "Use R").SetValue(true)); var tahmMenu = ultimateMenu.AddSubMenu(new Menu("Tahm Kench", ultimateMenu.Name + ".tahm-kench")); HeroListManager.AddToMenu( tahmMenu.AddSubMenu(new Menu("Blacklist", tahmMenu.Name + ".blacklist")), "tahm-kench", false, false, true, false); tahmMenu.AddItem(new MenuItem(tahmMenu.Name + ".r", "Use R").SetValue(true)); ultimateMenu.AddItem(new MenuItem(ultimateMenu.Name + ".save", "Save Soulbound").SetValue(true)); var comboMenu = Menu.AddSubMenu(new Menu("Combo", Menu.Name + ".combo")); HitchanceManager.AddToMenu( comboMenu.AddSubMenu(new Menu("Hitchance", comboMenu.Name + ".hitchance")), "combo", new Dictionary <string, HitChance> { { "Q", HitChance.VeryHigh } }); ManaManager.AddToMenu(comboMenu, "combo-q", ManaCheckType.Minimum, ManaValueType.Percent, "Q", 10); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".q", "Use Q").SetValue(true)); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".e", "Use E").SetValue(true)); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".e-min", "E Fleeing Min.").SetValue(new Slider(8, 1, 20))); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".minions", "Attack Minions").SetValue(false)); var harassMenu = Menu.AddSubMenu(new Menu("Harass", Menu.Name + ".harass")); HitchanceManager.AddToMenu( harassMenu.AddSubMenu(new Menu("Hitchance", harassMenu.Name + ".hitchance")), "harass", new Dictionary <string, HitChance> { { "Q", HitChance.High } }); ManaManager.AddToMenu(harassMenu, "harass-q", ManaCheckType.Minimum, ManaValueType.Percent, "Q"); ManaManager.AddToMenu(harassMenu, "harass-e", ManaCheckType.Minimum, ManaValueType.Percent, "E"); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".q", "Use Q").SetValue(true)); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".e", "Use E").SetValue(true)); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".e-min", "E Min.").SetValue(new Slider(4, 1, 20))); var laneclearMenu = Menu.AddSubMenu(new Menu("Lane Clear", Menu.Name + ".lane-clear")); ManaManager.AddToMenu(laneclearMenu, "lane-clear", ManaCheckType.Minimum, ManaValueType.Percent); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".q", "Use Q").SetValue(false)); laneclearMenu.AddItem( new MenuItem(laneclearMenu.Name + ".q-min-1", "Q Min." + " <= 4").SetValue(new Slider(2, 1, 5))); laneclearMenu.AddItem( new MenuItem(laneclearMenu.Name + ".q-min-2", "Q Min." + " <= 7").SetValue(new Slider(3, 1, 5))); laneclearMenu.AddItem( new MenuItem(laneclearMenu.Name + ".q-min-3", "Q Min." + " >= 10").SetValue(new Slider(5, 1, 5))); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".e", "Use E").SetValue(true)); var lasthitMenu = Menu.AddSubMenu(new Menu("Last Hit", Menu.Name + ".lasthit")); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e-jungle", "E Jungle").SetValue(true)); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e-big", "E Dragon/Baron").SetValue(true)); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".separator", string.Empty)); ManaManager.AddToMenu(lasthitMenu, "lasthit", ManaCheckType.Minimum, ManaValueType.Percent); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e-siege", "E Siege Minion").SetValue(true)); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e-unkillable", "E Unkillable").SetValue(true)); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e-turret", "E Under Turret").SetValue(true)); var killstealMenu = Menu.AddSubMenu(new Menu("Killsteal", Menu.Name + ".killsteal")); killstealMenu.AddItem(new MenuItem(killstealMenu.Name + ".e", "Use E").SetValue(true)); var miscMenu = Menu.AddSubMenu(new Menu("Misc", Menu.Name + ".miscellaneous")); ManaManager.AddToMenu(miscMenu, "misc", ManaCheckType.Minimum, ManaValueType.Percent, "E"); miscMenu.AddItem(new MenuItem(miscMenu.Name + ".e-reset", "E Harass Reset").SetValue(true)); miscMenu.AddItem( new MenuItem(miscMenu.Name + ".w-baron", "Hotkey W Baron").SetValue(new KeyBind('J', KeyBindType.Press))); miscMenu.AddItem( new MenuItem(miscMenu.Name + ".w-dragon", "Hotkey W Dragon").SetValue( new KeyBind('K', KeyBindType.Press))); IndicatorManager.AddToMenu(DrawingManager.Menu, true); IndicatorManager.Add(Q, true, false); IndicatorManager.Add(W, true, false); IndicatorManager.Add("E", Rend.GetDamage); IndicatorManager.Finale(); Weights.GetItem("low-health").GetValueFunc = hero => hero.Health - Rend.GetDamage(hero); Weights.AddItem( new Weights.Item( "w-stack", "W Stack", 10, false, hero => hero.HasBuff("kalistacoopstrikemarkally") ? 10 : 0)); }
public Patient(HL7.Patient patient) { Random rand = new Random(); ID = patient.Id; FirstName = patient.Name.ElementAt(0).Given.ElementAt(0); LastName = patient.Name.ElementAt(0).Family.ElementAt(0); MiddleName = ""; Sex = patient.GenderElement.Value.ToString(); Ethnicity = ethnicities[rand.Next(0, ethnicities.Length)]; Insurance_Type = "Unknown"; Date_Of_Birth = Convert.ToDateTime(patient.BirthDate); Add_Address(patient.Address.ElementAt(0).Line.ElementAt(0), patient.Address.ElementAt(0).City, patient.Address.ElementAt(0).State, patient.Address.ElementAt(0).PostalCode, patient.Address.ElementAt(0).District); //if there isn't a saved practitioner generate and add it to the list, otherwise uses the provided one if (patient.CareProvider.Count == 0) { PractitionerIDs.Add(rand.Next(1, 5)); } else { foreach (var practitionerRef in patient.CareProvider) { PractitionerIDs.Add(Int32.Parse(practitionerRef.Reference.Replace("Practitioner/", ""))); } } //default hypertension Has_HyperTension = false; HypertensionClass = HypertensionClassification.Normal; //default bmi BMIClass = BMIClassification.Normal; foreach (Data_Holder dh in Patient_Data.PatientInfo(ID)) { switch (dh.Type) { case "BMI": BMIs.Add(new BMI(dh.Date, dh.Measurement)); break; case "WEIGHT": Weights.Add(new Weight(dh.Date, dh.Measurement)); break; case "HEIGHT": Heights.Add(new Height(dh.Date, dh.Measurement)); break; case "HEMOGLOBIN": Hemoglobins.Add(new Hemoglobin(dh.Date, dh.Measurement)); HemoglobinClass = (dh.Measurement < (decimal)0.057) ? HemoglobinClassification.Normal : HemoglobinClassification.High; break; case "HYPERTENSION": Has_HyperTension = true; HypertensionClass = HypertensionClassification.Diagnosed; break; } } }
/// <summary> /// Run NBN training and its test - this is the first version /// </summary> /// <param name="trials">int - number of learning trials</param> /// <returns>LearnResult</returns>R private LearnResult RunFirstVersion(int trials) { backupSettings = new NeuralNetworkSettings(); backupSettings.MaxError = settings.MaxError; backupSettings.MaxIterations = settings.MaxIterations; backupSettings.MU = settings.MU; backupSettings.MUH = settings.MUH; backupSettings.MUL = settings.MUL; backupSettings.Scale = settings.Scale; Trials = trials; LearnResult result = new LearnResult(); result.Filename = Filename; if (MatLabCompareDataFolder.Length > 0) { result.Filename = string.Format("{0}\\{1}.dat", MatLabCompareDataFolder, Path.GetFileNameWithoutExtension(Directory.GetFiles(MatLabCompareDataFolder, "*.dat")[0])); } if (!loadInputData(Filename)) { updateErrorNBN("Dane nie zostały wczytane."); return result; } if (OnDebug != null) debug("Data loaded from file: " + Filename); var tmp = new System.Collections.Generic.List<int>(); tmp.Add(inputLearn.Cols); //setting number of hidden neurons for (int i = 0; i < Handle; i++) { tmp.Add(1); } tmp.Add(1); var vh = new VectorHorizontal(tmp.Count); for (int i = 0; i < vh.Length; i++) { vh[i] = tmp[i]; } switch (NBN_Topography) { case 0: { topo = Topography.Generate(TopographyType.BMLP, vh); } break; case 1: { topo = Topography.Generate(TopographyType.MLP, vh); } break; } result.Topo = topo.Data[0]; if (OnDebug != null) debug(topo.ToString()); if (topo == null) { updateErrorNBN("Topologia sieci nie została utworzona."); return result; } info = this.checkInputs(ref inputLearn, ref outputLearn, ref topo, out indexes);//here are set indexes result.TopoIndex = indexes.Data[0]; result.Info = info; if (OnDebug != null) { debug(indexes.ToString()); debug(info.ToString()); } Activation act = new Activation(info.nn); act.FillWithNumber(NBN_Activation); act.setValue(info.nn - 1, 0); result.ActivationFunction = act.Data[0]; Gain gain = new Gain(info.nn); gain.FillWithNumber(NBN_Gain); result.GainValue = gain.Data[0]; result.Settings = this.settings; for (trial = 0; trial < trials; trial++) { Weights initialWeights = new Weights(info.nw); if (MatLabCompareDataFolder.Length > 0) { initialWeights = MatrixMB.Load(string.Format("{0}\\poczatkowe_wagi_proba_{1}.txt", MatLabCompareDataFolder, trial + 1)).ToWeights(); } else { initialWeights = Weights.Generate(info.nw); } if (IsResearchMode) { string initialWeightsFile = String.Format("{0}\\{1}{2}_initial_weights.dat", _reasearch_folder, trial, Path.GetFileNameWithoutExtension(result.Filename)); initialWeights.Store(initialWeightsFile); } initialWeights.Name = "Initial"; if (OnDebug != null) { debug(String.Format("\r\nTrial {0} from {1}\r\n", trial + 1, trials)); debug(initialWeights.ToString()); } settings = null; settings = NeuralNetworkSettings.Default(); settings.MaxError = backupSettings.MaxError; settings.MaxIterations = backupSettings.MaxIterations; settings.MU = backupSettings.MU; settings.MUH = backupSettings.MUH; settings.MUL = backupSettings.MUL; settings.Scale = backupSettings.Scale; I = MatrixMB.Eye(info.nw); tic();//learn time measure start var tr = Train(ref this.settings, ref this.info, ref this.inputLearn, ref this.outputLearn, ref this.topo, initialWeights, ref act, ref gain, ref indexes); String LearnExecutionTime = toc();//learn time measure stop LearnTimeList = time.ElapsedTicks;//learn time measure save result.Add(tr.weights.Data[0], SSE.ToDoubleArray(), RMSE.ToDoubleArray()); result.LearnRMSE = (double)RMSE[RMSE.Count]; LearnRmseList = LastRMSE; if (OnDebug != null) { debug(tr.weights.ToString()); debug("\r\nLearn execution time: " + LearnExecutionTime + "(hours:minutes:seconds:miliseconds)\r\n"); debug("\r\nLearn SSE: " + tr.sse.ToString() + "\r\n"); debug("\r\nLearn RMSE: " + result.LearnRMSE.ToString() + "\r\n"); } updateError(result.LearnRMSE); NetworkInfo infoTest = info.Copy(); infoTest.np = inputTest.Rows; tic(); error.CalculateError(ref infoTest, ref inputTest, ref outputTest, ref topo, tr.weights, ref act, ref gain, ref indexes); var TestExecutionTime = toc(); TestTimeList = time.ElapsedTicks; result.TestRMSE = Math.Sqrt(error.Error / infoTest.np); TestRmseList = result.TestRMSE; result.TestingRmseList.Add(result.TestRMSE); if (OnDebug != null) { debug("\r\nTest execution time: " + TestExecutionTime + "(hours:minutes:seconds:miliseconds)\r\n"); debug("\r\nTest SSE: " + error.Error.ToString() + "\r\n"); debug("\r\nTest RMSE: " + result.TestRMSE.ToString() + "\r\n"); } //if (result.LearnRMSE < Threshold) IsTrainOK++; if (result.SSE[trial][result.SSE[trial].Length - 1] < Threshold) IsTrainOK++; } result.LearnRMSE = AverageLearnRMSE; result.TestRMSE = AverageTestRMSE; result.setStatisticsData(LearnRMSE, TestRMSE, LearnTime, TestTime, Trials); result.SuccessRate = (double)IsTrainOK / Trials; if (IsResearchMode)//save research { try { string filename = extractionFolder + "\\research result.pdf"; PDFGenerate data = new PDFGenerate(); data.Filename = filename; data.Result = result; data.ChartFilename = GeneratePlot(result.RMSE, Path.GetFileNameWithoutExtension(result.Filename)); HistoryPDF pdf = new HistoryPDF(data.Result, data.ChartFilename, true); pdf.Save(data.Filename); } catch { } } return result; }
/// <summary> /// Train neural netowrk /// </summary> /// <param name="setting">NeuralNetworkSettings</param> /// <param name="info">NetworkInfo</param> /// <param name="inp">Input</param> /// <param name="dout">Output</param> /// <param name="topo">Topography</param> /// <param name="initialWeights">Weights</param> /// <param name="act">Activation</param> /// <param name="gain">Gain</param> /// <param name="iw">Index</param> public TrainResult Train(ref NeuralNetworkSettings setting, ref NetworkInfo info, ref Input inp, ref Output dout, ref Topography topo, Weights initialWeights, ref Activation act, ref Gain gain, ref Index iw) { TrainResult result = new TrainResult(); result.weights = new Weights(initialWeights.Length); result.iterations = 0; result.sse = 0; try { if (OnDebug != null) { debug(setting.ToString()); debug(act.ToString()); debug(gain.ToString()); } result.weights = initialWeights.Backup(); error.CalculateError(ref info, ref inp, ref dout, ref topo, result.weights, ref act, ref gain, ref iw); if (OnDebug != null) { debug("\r\nFirst error value: " + error.Error.ToString() + "\r\n"); } SSE.Clear(); RMSE.Clear(); SSE[0] = result.sse = error.Error; hessians.Clear(); var hessian = new Hessian(ref info); Input ii = inp.Copy().ToInput(); Output oo = dout.Copy().ToOutput(); for (result.iterations = 1; result.iterations < setting.MaxIterations; result.iterations++) { hessian.Compute(ref info, ref inp, ref dout, ref topo, result.weights, ref act, ref gain, ref iw); if (OnDebug != null) debug(hessian.ToString()); hessians.Add(hessian.HessianMat); Weights ww_backup = result.weights.Backup(); for (int jw = 0; jw < 30; jw++) { var diff = (hessian.HessianMat + (I * setting.MU)).SolveEquatation(hessian.GradientMat).Transposed; if (OnDebug != null) { debug("\r\nOdejmuję"); debug(diff.MatrixToString()); } result.weights = ww_backup - diff.ToWeights(); result.weights.Name = "Weights nr " + jw.ToString(); if (OnDebug != null) { bool areSame = result.weights.IsEqual(ww_backup); debug("\r\nWeights are same as previously backed up"); debug(result.weights.ToString()); } SSE[result.iterations] = result.sse = error.CalculateError(ref info, ref inp, ref dout, ref topo, result.weights, ref act, ref gain, ref iw); if (OnDebug != null) debug("\r\nSSE[" + result.iterations.ToString() + "] = " + error.Error.ToString()); if (SSE.CurrentSSE() <= SSE.PreviousSSE(result.iterations)) { if (setting.MU > setting.MUL) { setting.MU /= setting.Scale; } break; } if (setting.MU < setting.MUH) { setting.MU *= setting.Scale; } } double rmse = Math.Sqrt((SSE.CurrentSSE()) / inp.Rows); RMSE[result.iterations] = rmse; updateChart(result.iterations, rmse); if ((double)SSE[result.iterations] < setting.MaxError) { break; } if (OnDebug != null) debug("Błąd: " + rmse.ToString()); if ( (SSE.PreviousSSE(result.iterations) - ((double)SSE[result.iterations])) / SSE.PreviousSSE(result.iterations) < NetworkError.DesiredError//0.000000000000001 ) { break; } } } catch (Exception ex) { throw new NeuralNetworkError("Błąd uczenia sieci. " + ex.Message, ex); } return result; }
public void Hessian___Gradient___Calculation___Test() { int accuracy = 15; /* function obliczanie_hesjan_gradient() clear(); inp = [-1 -1;-1 1; 1 -1]; dout = [1;0;0]; topo = [3 1 2 4 1 2 3]; ww = [1 1 1 1 1 1 1]; act = [2 0]; gain = [1 1]; param = [3 2 1 7 2]; iw = [1 4 8]; format long; [gradient,hessian] = Hessian(inp,dout,topo,ww,act,gain,param,iw); fprintf('Otrzymany gradient:\n'); disp(gradient); fprintf('\nOtrzymany hesjan:\n'); disp(hessian); % To jest otrzymywane % Otrzymany gradient: % -0.839948683228052 % 2.319597374905329 % 2.319597374905329 % -2.000000000000000 % 5.523188311911530 % 5.523188311911531 % 6.889667569278484 % % % Otrzymany hesjan: % Columns 1 through 6 % % 1.058270685684809 -0.705513790456539 -0.705513790456539 2.519846049684157 -1.679897366456105 -1.679897366456105 % -0.705513790456539 1.058270685684809 0.352756895228269 -1.679897366456105 2.519846049684157 0.839948683228052 % -0.705513790456539 0.352756895228269 1.058270685684809 -1.679897366456105 0.839948683228052 2.519846049684157 % 2.519846049684157 -1.679897366456105 -1.679897366456105 6.000000000000000 -4.000000000000000 -4.000000000000000 % -1.679897366456105 2.519846049684157 0.839948683228052 -4.000000000000000 6.000000000000000 2.000000000000000 % -1.679897366456105 0.839948683228052 2.519846049684157 -4.000000000000000 2.000000000000000 6.000000000000000 % -0.639700008449225 1.279400016898449 1.279400016898449 -1.523188311911530 3.046376623823059 3.046376623823059 % % Column 7 % % -0.639700008449225 % 1.279400016898449 % 1.279400016898449 % -1.523188311911530 % 3.046376623823059 % 3.046376623823059 % 3.480153950315843 end */ Input input = new Input(3, 2);//inp = [-1 -1;-1 1; 1 -1]; input[0, 0] = -1; input[0, 1] = -1; input[1, 0] = -1; input[1, 1] = 1; input[2, 0] = 1; input[2, 1] = -1; Output output = new Output(3, 1);//dout = [1;0;0]; output[0, 0] = 1; output[1, 0] = 0; output[2, 0] = 0; NetworkInfo info = new NetworkInfo();//param = [3 2 1 7 2]; info.ni = 2; info.nn = 2; info.no = 1; info.np = 3; info.nw = 7; VectorHorizontal vh = new VectorHorizontal(3); vh[0, 0] = 2; vh[0, 1] = 1; vh[0, 2] = 1; Topography topo = Topography.Generate(TopographyType.BMLP, vh);//topo = [3 1 2 4 1 2 3]; //w C# indeksy są od zera a nie od 1 więc wszystko o 1 w dół przestawione jest Assert.AreEqual(2, topo[0]); Assert.AreEqual(0, topo[1]); Assert.AreEqual(1, topo[2]); Assert.AreEqual(3, topo[3]); Assert.AreEqual(0, topo[4]); Assert.AreEqual(1, topo[5]); Assert.AreEqual(2, topo[6]); Weights weights = new Weights(info.nw);//w = [1 1 1 1 1 1 1]; weights.FillWithNumber(1);//załatwione Activation act = new Activation(2);//act = [2 0]; act[0] = 2; act[1] = 0; Gain gain = new Gain(2);//gain = [1 1]; gain[0] = 1; gain[1] = 1; Index iw = Index.Find(ref topo);//iw = [1 4 8]; //ta sama sytuacja, indeksy od 0 startują Assert.AreEqual(0, iw[0]); Assert.AreEqual(3, iw[1]); Assert.AreEqual(7, iw[2]); Console.WriteLine("Testowanie obliczania gradientu i macierzy hesjana"); Console.WriteLine("Użyte dane:"); Console.WriteLine("\nDane wejściowe:"); Console.WriteLine(input.MatrixToString()); Console.WriteLine("\nDane wyjściowe:"); Console.WriteLine(output.MatrixToString()); Console.WriteLine("\nWagi;"); Console.WriteLine(weights.MatrixToString()); Console.WriteLine("\nTopologia:"); Console.WriteLine(topo.MatrixToString()); Console.WriteLine("\nIndeksy topologii:"); Console.WriteLine(iw.MatrixToString()); Console.WriteLine("\nFunkcje aktywacji:"); Console.WriteLine(act.MatrixToString()); Console.WriteLine("\nWzmocnienia (gains):"); Console.WriteLine(gain.MatrixToString()); Console.WriteLine("\nParametry (param):"); Console.WriteLine(info.ToString()); Hessian hess = new Hessian(ref info); hess.Compute(ref info, ref input, ref output, ref topo, weights, ref act, ref gain, ref iw); var g = hess.GradientMat; var h = hess.HessianMat; Console.WriteLine("\nSprawdzanie gradientu z dokładnością do 15 miejsc po przecinku"); var matG = new double[] { -0.839948683228052, 2.319597374905329, 2.319597374905329, -2.000000000000000, 5.523188311911530, 5.523188311911531, 6.889667569278484 }; /* % Otrzymany gradient: % -0.839948683228052 % 2.319597374905329 % 2.319597374905329 % -2.000000000000000 % 5.523188311911530 % 5.523188311911531 % 6.889667569278484 */ for (int i = 0; i < matG.Length; i++) { Console.WriteLine(string.Format("NBN C#: {0}\tMatLab NBN: {1}\t{2}", Math.Round(g[i, 0], accuracy), matG[i], Math.Round(g[i, 0], accuracy) == matG[i] ? "OK" : "źle")); } Assert.AreEqual(-0.839948683228052, Math.Round(g[0, 0], accuracy)); Assert.AreEqual(2.319597374905329, Math.Round(g[1, 0], accuracy)); Assert.AreEqual(2.319597374905329, Math.Round(g[2, 0], accuracy)); Assert.AreEqual(-2.000000000000000, Math.Round(g[3, 0], accuracy)); Assert.AreEqual(5.523188311911530, Math.Round(g[4, 0], accuracy)); Assert.AreEqual(5.523188311911531, Math.Round(g[5, 0], accuracy)); Assert.AreEqual(6.889667569278484, Math.Round(g[6, 0], accuracy)); Console.WriteLine("\nSprawdzanie macierzy hesjana\nPorównania z dokładnością do 15 miejsc po przecinku"); MatrixMB matH = new MatrixMB(7, 7); //col 1 matH[0, 0] = 1.058270685684809; matH[1, 0] = -0.705513790456539; matH[2, 0] = -0.705513790456539; matH[3, 0] = 2.519846049684157; matH[4, 0] = -1.679897366456105; matH[5, 0] = -1.679897366456105; matH[6, 0] = -0.639700008449225; //col 2 matH[0, 1] = -0.705513790456539; matH[1, 1] = 1.058270685684809; matH[2, 1] = 0.352756895228269; matH[3, 1] = -1.679897366456105; matH[4, 1] = 2.519846049684157; matH[5, 1] = 0.839948683228052; matH[6, 1] = 1.279400016898449; //col 3 matH[0, 2] = -0.705513790456539; matH[1, 2] = 0.352756895228269; matH[2, 2] = 1.058270685684809; matH[3, 2] = -1.679897366456105; matH[4, 2] = 0.839948683228052; matH[5, 2] = 2.519846049684157; matH[6, 2] = 1.279400016898449; //col 4 matH[0, 3] = 2.519846049684157; matH[1, 3] = -1.679897366456105; matH[2, 3] = -1.679897366456105; matH[3, 3] = 6.000000000000000; matH[4, 3] = -4.000000000000000; matH[5, 3] = -4.000000000000000; matH[6, 3] = -1.523188311911530; //col 5 matH[0, 4] = -1.679897366456105; matH[1, 4] = 2.519846049684157; matH[2, 4] = 0.839948683228052; matH[3, 4] = -4.000000000000000; matH[4, 4] = 6.000000000000000; matH[5, 4] = 2.000000000000000; matH[6, 4] = 3.046376623823059; //col 6 matH[0, 5] = -1.679897366456105; matH[1, 5] = 0.839948683228052; matH[2, 5] = 2.519846049684157; matH[3, 5] = -4.000000000000000; matH[4, 5] = 2.000000000000000; matH[5, 5] = 6.000000000000000; matH[6, 5] = 3.046376623823059; //col 7 matH[0, 6] = -0.639700008449225; matH[1, 6] = 1.279400016898449; matH[2, 6] = 1.279400016898449; matH[3, 6] = -1.523188311911530; matH[4, 6] = 3.046376623823059; matH[5, 6] = 3.046376623823059; matH[6, 6] = 3.480153950315843; for (int k = 0; k < h.Cols; k++) { Console.WriteLine(string.Format("Kolumna {0}", k + 1)); for (int w = 0; w < h.Rows; w++) { decimal dh = Math.Round((decimal)h[w, k], accuracy); decimal dmh = Math.Round((decimal)matH[w, k], accuracy); Console.WriteLine(string.Format("NBN C#: {0}\tMatLab NBN: {1}\t{2}", dh, dmh, dh == dmh ? "OK" : "źle")); } Console.WriteLine(""); } for (int k = 0; k < h.Cols; k++) { for (int w = 0; w < h.Rows; w++) { decimal dh = Math.Round((decimal)h[w, k], accuracy); decimal dmh = Math.Round((decimal)matH[w, k], accuracy); Assert.AreEqual(dmh, dh); } } /* % Otrzymany hesjan: % Columns 1 through 6 % % 1.058270685684809 -0.705513790456539 -0.705513790456539 2.519846049684157 -1.679897366456105 -1.679897366456105 % -0.705513790456539 1.058270685684809 0.352756895228269 -1.679897366456105 2.519846049684157 0.839948683228052 % -0.705513790456539 0.352756895228269 1.058270685684809 -1.679897366456105 0.839948683228052 2.519846049684157 % 2.519846049684157 -1.679897366456105 -1.679897366456105 6.000000000000000 -4.000000000000000 -4.000000000000000 % -1.679897366456105 2.519846049684157 0.839948683228052 -4.000000000000000 6.000000000000000 2.000000000000000 % -1.679897366456105 0.839948683228052 2.519846049684157 -4.000000000000000 2.000000000000000 6.000000000000000 % -0.639700008449225 1.279400016898449 1.279400016898449 -1.523188311911530 3.046376623823059 3.046376623823059 % % Column 7 % % -0.639700008449225 % 1.279400016898449 % 1.279400016898449 % -1.523188311911530 % 3.046376623823059 % 3.046376623823059 % 3.480153950315843 */ }
private void CalculateJacobian(ref Weights ww, ref Index iw, ref Topography topo) { for (i = s + 1; i <= iw[o + 1 - ni] - 1; i++) { J[0, i] = node[topo[i]] * J[0, s]; delo[0, topo[i]] -= ww[i] * J[0, s]; } }
public override string ToString() { return(string.Format("CI={0}; Weights={1}", ConsistencyIndex, Weights.ToMathematicaString())); }
public void Dispose() { LastDependentJobHandle.Complete(); Weights.Dispose(); }
public IActionResult WarMembers(string id, int warNo) { logger.LogInformation("WarMembers {0}", id); var tag = Utils.LinkIdToTag(id); var maxPrepDate = Constants.MaxVisibleSearchTime; if (warNo <= 0) { warNo = 1; } var warId = db.Wars.Where(w => w.ClanTag == tag && w.PreparationStartTime < maxPrepDate).OrderByDescending(w => w.EndTime).Skip(warNo - 1).Select(w => w.ID).FirstOrDefault(); var opponent = db.Wars.Where(w => w.ID == warId).Select(w => new { Tag = w.OpponentTag, Name = w.OpponentName }).FirstOrDefault(); var members = from m in db.WarMembers where m.WarID == warId && m.IsOpponent == false join p in db.Players on m.Tag equals p.Tag join iw in db.Weights on m.Tag equals iw.Tag into Weights from w in Weights.DefaultIfEmpty() orderby m.MapPosition select new { Member = m, Player = p, Weight = w }; var data = new WarMembers(); foreach (var row in members) { data.Add(new WarMemberModel { Position = row.Member.MapPosition, Name = row.Member.Name, Tag = row.Member.Tag, TownHall = row.Player.TownHallLevel, Weight = row.Weight != null ? row.Weight.WarWeight : 0, Attacks = 0, OpponentTag = opponent.Tag, OpponentName = opponent.Name }); } var attacks = from a in db.WarAttacks where a.WarID == warId && a.IsOpponent == false join o in db.WarMembers.Where(m => m.WarID == warId && m.IsOpponent == true) on a.DefenderTag equals o.Tag orderby a.Order select new { Attack = a, Opponent = o }; foreach (var row in attacks) { var member = data.Where(d => d.Tag == row.Attack.AttackerTag).FirstOrDefault(); if (member != null) { member.Attacks++; if (member.Attacks == 1) { member.Defender1Tag = row.Opponent.Tag; member.Defender1Name = row.Opponent.Name; member.Defender1Position = row.Opponent.MapPosition; member.Defender1TownHall = row.Opponent.TownHallLevel; member.Stars1 = row.Attack.Stars; member.DestructionPercentage1 = row.Attack.DestructionPercentage; } else if (member.Attacks == 2) { member.Defender2Tag = row.Opponent.Tag; member.Defender2Name = row.Opponent.Name; member.Defender2Position = row.Opponent.MapPosition; member.Defender2TownHall = row.Opponent.TownHallLevel; member.Stars2 = row.Attack.Stars; member.DestructionPercentage2 = row.Attack.DestructionPercentage; } } } return(Ok(data)); }
/// <summary> /// Computes the weights to apply at each pixel when resizing. /// </summary> /// <param name="destinationSize">The destination section size.</param> /// <param name="sourceSize">The source section size.</param> /// <returns> /// The <see cref="T:Weights[]"/>. /// </returns> protected Weights[] PrecomputeWeights(int destinationSize, int sourceSize) { IResampler sampler = this.Sampler; float ratio = sourceSize / (float)destinationSize; float scale = ratio; // When shrinking, broaden the effective kernel support so that we still // visit every source pixel. if (scale < 1) { scale = 1; } float scaledRadius = (float)Math.Ceiling(scale * sampler.Radius); Weights[] result = new Weights[destinationSize]; // Make the weights slices, one source for each column or row. Parallel.For( 0, destinationSize, i => { float center = ((i + .5f) * ratio) - 0.5f; int start = (int)Math.Ceiling(center - scaledRadius); if (start < 0) { start = 0; } int end = (int)Math.Floor(center + scaledRadius); if (end > sourceSize) { end = sourceSize; if (end < start) { end = start; } } float sum = 0; result[i] = new Weights(); List<Weight> builder = new List<Weight>(); for (int a = start; a < end; a++) { float w = sampler.GetValue((a - center) / scale); if (w < 0 || w > 0) { sum += w; builder.Add(new Weight(a, w)); } } // Normalise the values if (sum > 0 || sum < 0) { builder.ForEach(w => w.Value /= sum); } result[i].Values = builder.ToArray(); result[i].Sum = sum; }); return result; }
protected override void AddToMenu() { DrawingManager.Add("R Flash", R.Range + SummonerManager.Flash.Range); var ultimateMenu = UltimateManager.AddToMenu(Menu, true, true, false, true, false, true, true, true, true); ultimateMenu.AddItem( new MenuItem(ultimateMenu.Name + ".range", "Range").SetValue(new Slider(700, 400, 825))).ValueChanged += delegate(object sender, OnValueChangeEventArgs args) { R.Range = args.GetNewValue <Slider>().Value; DrawingManager.Update("R Flash", args.GetNewValue <Slider>().Value + SummonerManager.Flash.Range); }; var comboMenu = Menu.AddSubMenu(new Menu("Combo", Menu.Name + ".combo")); HitchanceManager.AddToMenu( comboMenu.AddSubMenu(new Menu("Hitchance", comboMenu.Name + ".hitchance")), "combo", new Dictionary <string, HitChance> { { "Q", HitChance.VeryHigh }, { "W", HitChance.High }, { "R", HitChance.VeryHigh } }); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".q", "Use Q").SetValue(true)); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".w", "Use W").SetValue(true)); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".e", "Use E").SetValue(true)); var harassMenu = Menu.AddSubMenu(new Menu("Harass", Menu.Name + ".harass")); HitchanceManager.AddToMenu( harassMenu.AddSubMenu(new Menu("Hitchance", harassMenu.Name + ".hitchance")), "harass", new Dictionary <string, HitChance> { { "Q", HitChance.VeryHigh }, { "W", HitChance.High } }); ManaManager.AddToMenu( harassMenu, "harass", ManaCheckType.Minimum, ManaValueType.Total, string.Empty, 70, 0, 750); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".q", "Use Q").SetValue(true)); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".w", "Use W").SetValue(true)); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".e", "Use E").SetValue(true)); var laneclearMenu = Menu.AddSubMenu(new Menu("Lane Clear", Menu.Name + ".lane-clear")); ManaManager.AddToMenu( laneclearMenu, "lane-clear", ManaCheckType.Minimum, ManaValueType.Total, string.Empty, 90, 0, 750); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".aa", "Use AutoAttacks").SetValue(true)); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".q", "Use Q").SetValue(true)); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".w", "Use W").SetValue(true)); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".e", "Use E").SetValue(true)); var lasthitMenu = Menu.AddSubMenu(new Menu("Last Hit", Menu.Name + ".lasthit")); ManaManager.AddToMenu( lasthitMenu, "lasthit", ManaCheckType.Maximum, ManaValueType.Percent, string.Empty, 70); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e", "Use E").SetValue(true)); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e-poison", "Use E Poison").SetValue(true)); var fleeMenu = Menu.AddSubMenu(new Menu("Flee", Menu.Name + ".flee")); fleeMenu.AddItem(new MenuItem(fleeMenu.Name + ".w", "Use W").SetValue(true)); var killstealMenu = Menu.AddSubMenu(new Menu("Killsteal", Menu.Name + ".killsteal")); killstealMenu.AddItem(new MenuItem(killstealMenu.Name + ".e", "Use E").SetValue(true)); killstealMenu.AddItem(new MenuItem(killstealMenu.Name + ".e-poison", "Use E Poison").SetValue(true)); var miscMenu = Menu.AddSubMenu(new Menu("Misc", Menu.Name + ".miscellaneous")); DelayManager.AddToMenu(miscMenu, "e-delay", "E", 250, 0, 1000); HeroListManager.AddToMenu( miscMenu.AddSubMenu(new Menu("Q Gapcloser", miscMenu.Name + "q-gapcloser")), "q-gapcloser", false, false, true, false); HeroListManager.AddToMenu( miscMenu.AddSubMenu(new Menu("Q " + "Fleeing", miscMenu.Name + "q-fleeing")), "q-fleeing", false, false, true, false); HeroListManager.AddToMenu( miscMenu.AddSubMenu(new Menu("W Gapcloser", miscMenu.Name + "w-gapcloser")), "w-gapcloser", false, false, true, false); HeroListManager.AddToMenu( miscMenu.AddSubMenu(new Menu("W Immobile", miscMenu.Name + "w-immobile")), "w-immobile", false, false, true, false); HeroListManager.AddToMenu( miscMenu.AddSubMenu(new Menu("W " + "Fleeing", miscMenu.Name + "w-fleeing")), "w-fleeing", false, false, true, false); R.Range = Menu.Item(Menu.Name + ".ultimate.range").GetValue <Slider>().Value; DrawingManager.Update( "R Flash", Menu.Item(Menu.Name + ".ultimate.range").GetValue <Slider>().Value + SummonerManager.Flash.Range); IndicatorManager.AddToMenu(DrawingManager.Menu, true); IndicatorManager.Add(Q); IndicatorManager.Add(W); IndicatorManager.Add("E", hero => E.GetDamage(hero) * 5); IndicatorManager.Add(R); IndicatorManager.Finale(); Weights.AddItem( new Weights.Item("poison-time", "Poison Time", 10, true, hero => GetPoisonBuffEndTime(hero) + 1)); }
/// <summary> /// Convert MatrixMB to Weights /// </summary> /// <param name="mat">MatrixMB</param> /// <returns>Weights</returns> public static Weights ToWeights(this MatrixMB mat) { Weights weights = new Weights(mat.Cols); for (int col = 0; col < mat.Cols; col++) { weights.Data[0][col] = mat.Data[0][col]; } return weights; }
public void Test___Error___Calculation___Test() { /* * * Kod testowy matlaba * function obliczanie_bledu() inp = [-1 -1;-1 1; 1 -1]; dout = [1;0;0]; topo = [3 1 2 4 1 2 3]; w = [1 1 1 1 1 1 1]; act = [2 0]; gain = [1 1]; param = [3 2 1 7 2]; iw = [1 4 8]; format long; error = calculate_error(inp,dout,topo,w,act,gain,param,iw); fprintf('Obliczanie błędu uczenia sieci\nBłąd wynosi: %.20f\n', error); %Otrzymany wynik %Obliczanie błędu uczenia sieci %Błąd wynosi: 13.83283022280404000000 end * * */ Input input = new Input(3, 2);//inp = [-1 -1;-1 1; 1 -1]; input[0, 0] = -1; input[0, 1] = -1; input[1, 0] = -1; input[1, 1] = 1; input[2, 0] = 1; input[2, 1] = -1; Output output = new Output(3, 1);//dout = [1;0;0]; output[0, 0] = 1; output[1, 0] = 0; output[2, 0] = 0; NetworkInfo info = new NetworkInfo();//param = [3 2 1 7 2]; info.ni = 2; info.nn = 2; info.no = 1; info.np = 3; info.nw = 7; VectorHorizontal vh = new VectorHorizontal(3); vh[0, 0] = 2; vh[0, 1] = 1; vh[0, 2] = 1; Topography topo = Topography.Generate(TopographyType.BMLP, vh);//topo = [3 1 2 4 1 2 3]; //w C# indeksy są od zera a nie od 1 więc wszystko o 1 w dół przestawione jest Assert.AreEqual(2, topo[0]); Assert.AreEqual(0, topo[1]); Assert.AreEqual(1, topo[2]); Assert.AreEqual(3, topo[3]); Assert.AreEqual(0, topo[4]); Assert.AreEqual(1, topo[5]); Assert.AreEqual(2, topo[6]); Weights weights = new Weights(info.nw);//w = [1 1 1 1 1 1 1]; weights.FillWithNumber(1);//załatwione Activation act = new Activation(2);//act = [2 0]; act[0] = 2; act[1] = 0; Gain gain = new Gain(2);//gain = [1 1]; gain[0] = 1; gain[1] = 1; Index iw = Index.Find(ref topo);//iw = [1 4 8]; //ta sama sytuacja, indeksy od 0 startują Assert.AreEqual(0, iw[0]); Assert.AreEqual(3, iw[1]); Assert.AreEqual(7, iw[2]); NetworkError ne = new NetworkError(); var error = ne.CalculateError(ref info, ref input, ref output, ref topo, weights, ref act, ref gain, ref iw); double errorFromMatLab = 13.83283022280404000000; Console.WriteLine("Testowanie obliczania błędu"); Console.WriteLine("Użyte dane:"); Console.WriteLine("\nDane wejściowe:"); Console.WriteLine(input.MatrixToString()); Console.WriteLine("\nDane wyjściowe:"); Console.WriteLine(output.MatrixToString()); Console.WriteLine("\nWagi;"); Console.WriteLine(weights.MatrixToString()); Console.WriteLine("\nTopologia:"); Console.WriteLine(topo.MatrixToString()); Console.WriteLine("\nIndeksy topologii:"); Console.WriteLine(iw.MatrixToString()); Console.WriteLine("\nFunkcje aktywacji:"); Console.WriteLine(act.MatrixToString()); Console.WriteLine("\nWzmocnienia (gains):"); Console.WriteLine(gain.MatrixToString()); Console.WriteLine("\nParametry (param):"); Console.WriteLine(info.ToString()); Assert.AreEqual(errorFromMatLab, error); Console.WriteLine(string.Format("{0} - wynik NBN C#",error)); Console.WriteLine(string.Format("{0} - wynik NBN w MatLabie",errorFromMatLab)); }
public new void SetWeights(Array array) { base.SetWeights(array); Weights.ToArray().ForEach((q, i, j) => _weightOptimizers[i, j].SetValue(q)); }
public void CopyTo(Neuron other) { other.Bias = Bias; Weights.CopyTo(other.Weights, 0); //other.ActivationFunc = ActivationFunc; }
protected override void AddToMenu() { DrawingManager.Add("R Flash", R.Range + SummonerManager.Flash.Range); var ultimateMenu = _ultimate.AddToMenu(Menu); ultimateMenu.AddItem( new MenuItem(ultimateMenu.Name + ".range", "Range").SetValue(new Slider(700, 400, 825))).ValueChanged += delegate(object sender, OnValueChangeEventArgs args) { R.Range = args.GetNewValue <Slider>().Value; DrawingManager.Update("R Flash", args.GetNewValue <Slider>().Value + SummonerManager.Flash.Range); }; ultimateMenu.AddItem(new MenuItem(ultimateMenu.Name + ".backwards", "Backwards Flash").SetValue(true)); var comboMenu = Menu.AddSubMenu(new Menu("Combo", Menu.Name + ".combo")); HitchanceManager.AddToMenu( comboMenu.AddSubMenu(new Menu("Hitchance", comboMenu.Name + ".hitchance")), "combo", new Dictionary <string, HitChance> { { "Q", HitChance.High }, { "W", HitChance.High }, { "R", HitChance.High } }); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".aa", "Use AutoAttacks").SetValue(false)); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".q", "Use Q").SetValue(true)); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".w", "Use W").SetValue(true)); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".e", "Use E").SetValue(true)); var harassMenu = Menu.AddSubMenu(new Menu("Harass", Menu.Name + ".harass")); HitchanceManager.AddToMenu( harassMenu.AddSubMenu(new Menu("Hitchance", harassMenu.Name + ".hitchance")), "harass", new Dictionary <string, HitChance> { { "Q", HitChance.VeryHigh }, { "W", HitChance.High } }); ResourceManager.AddToMenu( harassMenu, new ResourceManagerArgs( "harass", ResourceType.Mana, ResourceValueType.Percent, ResourceCheckType.Minimum) { DefaultValue = 30 }); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".aa", "Use AutoAttacks").SetValue(false)); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".q", "Use Q").SetValue(true)); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".w", "Use W").SetValue(true)); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".e", "Use E").SetValue(true)); var laneclearMenu = Menu.AddSubMenu(new Menu("Lane Clear", Menu.Name + ".lane-clear")); ResourceManager.AddToMenu( laneclearMenu, new ResourceManagerArgs( "lane-clear", ResourceType.Mana, ResourceValueType.Percent, ResourceCheckType.Minimum) { Advanced = true, MaxValue = 101, LevelRanges = new SortedList <int, int> { { 1, 6 }, { 6, 12 }, { 12, 18 } }, DefaultValues = new List <int> { 50, 30, 30 }, IgnoreJungleOption = true }); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".aa", "Use AutoAttacks").SetValue(true)); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".q", "Use Q").SetValue(true)); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".w", "Use W").SetValue(true)); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".e", "Use E").SetValue(true)); var lasthitMenu = Menu.AddSubMenu(new Menu("Last Hit", Menu.Name + ".lasthit")); ResourceManager.AddToMenu( lasthitMenu, new ResourceManagerArgs( "lasthit", ResourceType.Mana, ResourceValueType.Percent, ResourceCheckType.Maximum) { Advanced = true, MaxValue = 101, LevelRanges = new SortedList <int, int> { { 1, 6 }, { 6, 12 }, { 12, 18 } }, DefaultValues = new List <int> { 90, 70, 70 } }); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e", "Use E").SetValue(true)); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e-poison", "Use E Poison").SetValue(true)); var fleeMenu = Menu.AddSubMenu(new Menu("Flee", Menu.Name + ".flee")); fleeMenu.AddItem(new MenuItem(fleeMenu.Name + ".w", "Use W").SetValue(true)); var killstealMenu = Menu.AddSubMenu(new Menu("Killsteal", Menu.Name + ".killsteal")); killstealMenu.AddItem(new MenuItem(killstealMenu.Name + ".e", "Use E").SetValue(true)); killstealMenu.AddItem(new MenuItem(killstealMenu.Name + ".e-poison", "Use E Poison Only").SetValue(true)); var miscMenu = Menu.AddSubMenu(new Menu("Misc", Menu.Name + ".miscellaneous")); DelayManager.AddToMenu(miscMenu, "e-delay", "E", 420, 0, 1000); var qGapcloserMenu = miscMenu.AddSubMenu(new Menu("Q Gapcloser", miscMenu.Name + "q-gapcloser")); GapcloserManager.AddToMenu( qGapcloserMenu, new HeroListManagerArgs("q-gapcloser") { IsWhitelist = false, Allies = false, Enemies = true, DefaultValue = false }); BestTargetOnlyManager.AddToMenu(qGapcloserMenu, "q-gapcloser", true); var qFleeingMenu = miscMenu.AddSubMenu(new Menu("Q Fleeing", miscMenu.Name + "q-fleeing")); HeroListManager.AddToMenu( qFleeingMenu, new HeroListManagerArgs("q-fleeing") { IsWhitelist = false, Allies = false, Enemies = true, DefaultValue = false }); BestTargetOnlyManager.AddToMenu(qFleeingMenu, "q-fleeing", true); var wGapcloserMenu = miscMenu.AddSubMenu(new Menu("W Gapcloser", miscMenu.Name + "w-gapcloser")); GapcloserManager.AddToMenu( wGapcloserMenu, new HeroListManagerArgs("w-gapcloser") { IsWhitelist = false, Allies = false, Enemies = true, DefaultValue = false }, true); BestTargetOnlyManager.AddToMenu(wGapcloserMenu, "w-gapcloser"); var wImmobileMenu = miscMenu.AddSubMenu(new Menu("W Immobile", miscMenu.Name + "w-immobile")); HeroListManager.AddToMenu( wImmobileMenu, new HeroListManagerArgs("w-immobile") { IsWhitelist = false, Allies = false, Enemies = true, DefaultValue = false }); BestTargetOnlyManager.AddToMenu(wImmobileMenu, "w-immobile", true); var wFleeingMenu = miscMenu.AddSubMenu(new Menu("W Fleeing", miscMenu.Name + "w-fleeing")); HeroListManager.AddToMenu( wFleeingMenu, new HeroListManagerArgs("w-fleeing") { IsWhitelist = false, Allies = false, Enemies = true, DefaultValue = false }); BestTargetOnlyManager.AddToMenu(wFleeingMenu, "w-fleeing", true); R.Range = Menu.Item(Menu.Name + ".ultimate.range").GetValue <Slider>().Value; DrawingManager.Update( "R Flash", Menu.Item(Menu.Name + ".ultimate.range").GetValue <Slider>().Value + SummonerManager.Flash.Range); IndicatorManager.AddToMenu(DrawingManager.Menu, true); IndicatorManager.Add(Q); IndicatorManager.Add(W); IndicatorManager.Add("E", hero => E.GetDamage(hero) * 3); IndicatorManager.Add(R); IndicatorManager.Finale(); Weights.AddItem( new Weights.Item("poison-time", "Poison Time", 5, false, hero => GetPoisonBuffEndTime(hero) + 1)); }
protected StockCar() { Tires = new Tires(); Weights = new Weights(); }
public void Weigths___Correction___Test() { var gradient = new MatrixMB(7, 1); //gradient = [-0.839948683228052; 2.319597374905329; 2.319597374905329; -2.000000000000000; 5.523188311911530; 5.523188311911531; 6.889667569278484]; gradient[0, 0] = -0.839948683228052; gradient[1, 0] = 2.319597374905329; gradient[2, 0] = 2.319597374905329; gradient[3, 0] = -2.000000000000000; gradient[4, 0] = 5.523188311911530; gradient[5, 0] = 5.523188311911531; gradient[6, 0] = 6.889667569278484; /* * hessian = [ * 1.058270685684809 -0.705513790456539 -0.705513790456539 2.519846049684157 -1.679897366456105 -1.679897366456105 -0.639700008449225; * -0.705513790456539 1.058270685684809 0.352756895228269 -1.679897366456105 2.519846049684157 0.839948683228052 1.279400016898449; * -0.705513790456539 0.352756895228269 1.058270685684809 -1.679897366456105 0.839948683228052 2.519846049684157 1.279400016898449; * 2.519846049684157 -1.679897366456105 -1.679897366456105 6.000000000000000 -4.000000000000000 -4.000000000000000 -1.523188311911530; * -1.679897366456105 2.519846049684157 0.839948683228052 -4.000000000000000 6.000000000000000 2.000000000000000 3.046376623823059; * -1.679897366456105 0.839948683228052 2.519846049684157 -4.000000000000000 2.000000000000000 6.000000000000000 3.046376623823059; * -0.639700008449225 1.279400016898449 1.279400016898449 -1.523188311911530 3.046376623823059 3.046376623823059 3.480153950315843 * ]; */ MatrixMB hessian = new MatrixMB(7, 7); //col 1 hessian[0, 0] = 1.058270685684809; hessian[1, 0] = -0.705513790456539; hessian[2, 0] = -0.705513790456539; hessian[3, 0] = 2.519846049684157; hessian[4, 0] = -1.679897366456105; hessian[5, 0] = -1.679897366456105; hessian[6, 0] = -0.639700008449225; //col 2 hessian[0, 1] = -0.705513790456539; hessian[1, 1] = 1.058270685684809; hessian[2, 1] = 0.352756895228269; hessian[3, 1] = -1.679897366456105; hessian[4, 1] = 2.519846049684157; hessian[5, 1] = 0.839948683228052; hessian[6, 1] = 1.279400016898449; //col 3 hessian[0, 2] = -0.705513790456539; hessian[1, 2] = 0.352756895228269; hessian[2, 2] = 1.058270685684809; hessian[3, 2] = -1.679897366456105; hessian[4, 2] = 0.839948683228052; hessian[5, 2] = 2.519846049684157; hessian[6, 2] = 1.279400016898449; //col 4 hessian[0, 3] = 2.519846049684157; hessian[1, 3] = -1.679897366456105; hessian[2, 3] = -1.679897366456105; hessian[3, 3] = 6.000000000000000; hessian[4, 3] = -4.000000000000000; hessian[5, 3] = -4.000000000000000; hessian[6, 3] = -1.523188311911530; //col 5 hessian[0, 4] = -1.679897366456105; hessian[1, 4] = 2.519846049684157; hessian[2, 4] = 0.839948683228052; hessian[3, 4] = -4.000000000000000; hessian[4, 4] = 6.000000000000000; hessian[5, 4] = 2.000000000000000; hessian[6, 4] = 3.046376623823059; //col 6 hessian[0, 5] = -1.679897366456105; hessian[1, 5] = 0.839948683228052; hessian[2, 5] = 2.519846049684157; hessian[3, 5] = -4.000000000000000; hessian[4, 5] = 2.000000000000000; hessian[5, 5] = 6.000000000000000; hessian[6, 5] = 3.046376623823059; //col 7 hessian[0, 6] = -0.639700008449225; hessian[1, 6] = 1.279400016898449; hessian[2, 6] = 1.279400016898449; hessian[3, 6] = -1.523188311911530; hessian[4, 6] = 3.046376623823059; hessian[5, 6] = 3.046376623823059; hessian[6, 6] = 3.480153950315843; Weights weights = new Weights(7); weights.FillWithNumber(1); double mu = 0.01; var I = MatrixMB.Eye(weights.Length); Console.WriteLine("Testowanie obliczania korekty wag"); Console.WriteLine("Hesjan:"); Console.WriteLine(hessian.MatrixToString()); Console.WriteLine("Gradient:"); Console.WriteLine(gradient.MatrixToString()); Console.WriteLine("Wagi początkowe:"); Console.WriteLine(weights.MatrixToString()); Console.WriteLine("MU = " + mu.ToString()); Console.WriteLine("Macierz I"); Console.WriteLine(I.MatrixToString()); //korekta_wag = ((hessian+mu*I)\gradient)'; /* * Lewa strona * Columns 1 through 6 * * 1.068270685684809 -0.705513790456539 -0.705513790456539 2.519846049684157 -1.679897366456105 -1.679897366456105 * -0.705513790456539 1.068270685684809 0.352756895228269 -1.679897366456105 2.519846049684157 0.839948683228052 * -0.705513790456539 0.352756895228269 1.068270685684809 -1.679897366456105 0.839948683228052 2.519846049684157 * 2.519846049684157 -1.679897366456105 -1.679897366456105 6.010000000000000 -4.000000000000000 -4.000000000000000 * -1.679897366456105 2.519846049684157 0.839948683228052 -4.000000000000000 6.010000000000000 2.000000000000000 * -1.679897366456105 0.839948683228052 2.519846049684157 -4.000000000000000 2.000000000000000 6.010000000000000 * -0.639700008449225 1.279400016898449 1.279400016898449 -1.523188311911530 3.046376623823059 3.046376623823059 * * Column 7 * * -0.639700008449225 * 1.279400016898449 * 1.279400016898449 * -1.523188311911530 * 3.046376623823059 * 3.046376623823059 * 3.490153950315843 */ var lewa_strona_matlab = new MatrixMB(7, 7); lewa_strona_matlab[0, 0] = 1.06827068568480900000; lewa_strona_matlab[0, 1] = -0.70551379045653895000; lewa_strona_matlab[0, 2] = -0.70551379045653895000; lewa_strona_matlab[0, 3] = 2.51984604968415700000; lewa_strona_matlab[0, 4] = -1.67989736645610500000; lewa_strona_matlab[0, 5] = -1.67989736645610500000; lewa_strona_matlab[0, 6] = -0.63970000844922503000; lewa_strona_matlab[1, 0] = -0.70551379045653895000; lewa_strona_matlab[1, 1] = 1.06827068568480900000; lewa_strona_matlab[1, 2] = 0.35275689522826897000; lewa_strona_matlab[1, 3] = -1.67989736645610500000; lewa_strona_matlab[1, 4] = 2.51984604968415700000; lewa_strona_matlab[1, 5] = 0.83994868322805205000; lewa_strona_matlab[1, 6] = 1.27940001689844900000; lewa_strona_matlab[2, 0] = -0.70551379045653895000; lewa_strona_matlab[2, 1] = 0.35275689522826897000; lewa_strona_matlab[2, 2] = 1.06827068568480900000; lewa_strona_matlab[2, 3] = -1.67989736645610500000; lewa_strona_matlab[2, 4] = 0.83994868322805205000; lewa_strona_matlab[2, 5] = 2.51984604968415700000; lewa_strona_matlab[2, 6] = 1.27940001689844900000; lewa_strona_matlab[3, 0] = 2.51984604968415700000; lewa_strona_matlab[3, 1] = -1.67989736645610500000; lewa_strona_matlab[3, 2] = -1.67989736645610500000; lewa_strona_matlab[3, 3] = 6.00999999999999980000; lewa_strona_matlab[3, 4] = -4.00000000000000000000; lewa_strona_matlab[3, 5] = -4.00000000000000000000; lewa_strona_matlab[3, 6] = -1.52318831191152990000; lewa_strona_matlab[4, 0] = -1.67989736645610500000; lewa_strona_matlab[4, 1] = 2.51984604968415700000; lewa_strona_matlab[4, 2] = 0.83994868322805205000; lewa_strona_matlab[4, 3] = -4.00000000000000000000; lewa_strona_matlab[4, 4] = 6.00999999999999980000; lewa_strona_matlab[4, 5] = 2.00000000000000000000; lewa_strona_matlab[4, 6] = 3.04637662382305900000; lewa_strona_matlab[5, 0] = -1.67989736645610500000; lewa_strona_matlab[5, 1] = 0.83994868322805205000; lewa_strona_matlab[5, 2] = 2.51984604968415700000; lewa_strona_matlab[5, 3] = -4.00000000000000000000; lewa_strona_matlab[5, 4] = 2.00000000000000000000; lewa_strona_matlab[5, 5] = 6.00999999999999980000; lewa_strona_matlab[5, 6] = 3.04637662382305900000; lewa_strona_matlab[6, 0] = -0.63970000844922503000; lewa_strona_matlab[6, 1] = 1.27940001689844900000; lewa_strona_matlab[6, 2] = 1.27940001689844900000; lewa_strona_matlab[6, 3] = -1.52318831191152990000; lewa_strona_matlab[6, 4] = 3.04637662382305900000; lewa_strona_matlab[6, 5] = 3.04637662382305900000; lewa_strona_matlab[6, 6] = 3.49015395031584270000; var lewa_strona_csharp = hessian + (I * mu); Console.WriteLine("Lewa strona dzielenia - obliczanie korekty wag => (hessian+mu*I)"); for (int i = 0; i < lewa_strona_csharp.Rows; i++) { for (int j = 0; j < lewa_strona_csharp.Cols; j++) { var result = Math.Round(((decimal)lewa_strona_csharp[i, j]), 15); var expected = Math.Round(((decimal)lewa_strona_matlab[i, j]), 15); Console.WriteLine(string.Format("Poz[{0},{1}] => NBN C#: {2}\tMatLab NBN: {3}\t{4}", i, j, result, expected, result == expected ? "OK" : "źle")); } } for (int i = 0; i < lewa_strona_csharp.Rows; i++) { for (int j = 0; j < lewa_strona_csharp.Cols; j++) { var result = Math.Round(((decimal)lewa_strona_csharp[i, j]), 15); var expected = Math.Round(((decimal)lewa_strona_matlab[i, j]), 15); Assert.AreEqual(expected, result); } } var diff = ((hessian + (I * mu)).Inverted * gradient).Transposed; /* * Expected weights diff * % Otrzymana korekta wag: * % * % 0.27954017281149085000 * % 0.21238647096009383000 * % 0.21238647096010940000 * % 0.66561250322368737000 * % 0.50571296842532187000 * % 0.50571296842531543000 * % 1.27722267527372440000 * % Koniec * */ var diffMatLab = new double[] { 0.27954017281149085000, 0.21238647096009383000, 0.21238647096010940000, 0.66561250322368737000, 0.50571296842532187000, 0.50571296842531543000, 1.27722267527372440000 }; /* * Test matlabowy * function obliczanie_korekty_wag() * %ww = ww_backup - ((hessian+mu*I)\gradient)'; * clear(); * ww = [1 1 1 1 1 1 1]; * mu = 0.01; * I = eye(size(ww,2));%tyle co wag * format long; * gradient = [-0.839948683228052; 2.319597374905329; 2.319597374905329; -2.000000000000000; 5.523188311911530; 5.523188311911531; 6.889667569278484]; * hessian = [ * 1.058270685684809 -0.705513790456539 -0.705513790456539 2.519846049684157 -1.679897366456105 -1.679897366456105 -0.639700008449225; * -0.705513790456539 1.058270685684809 0.352756895228269 -1.679897366456105 2.519846049684157 0.839948683228052 1.279400016898449; * -0.705513790456539 0.352756895228269 1.058270685684809 -1.679897366456105 0.839948683228052 2.519846049684157 1.279400016898449; * 2.519846049684157 -1.679897366456105 -1.679897366456105 6.000000000000000 -4.000000000000000 -4.000000000000000 -1.523188311911530; * -1.679897366456105 2.519846049684157 0.839948683228052 -4.000000000000000 6.000000000000000 2.000000000000000 3.046376623823059; * -1.679897366456105 0.839948683228052 2.519846049684157 -4.000000000000000 2.000000000000000 6.000000000000000 3.046376623823059; * -0.639700008449225 1.279400016898449 1.279400016898449 -1.523188311911530 3.046376623823059 3.046376623823059 3.480153950315843 * ]; * * korekta_wag = ((hessian+mu*I)\gradient)'; * fprintf('\nOtrzymana korekta wag:\n'); * for i=1:size(ww,2) * fprintf('\n%.20f',korekta_wag(i)); * end * fprintf('\nKoniec\n'); * end * * % Otrzymana korekta wag: * % * % 0.27954017281149085000 * % 0.21238647096009383000 * % 0.21238647096010940000 * % 0.66561250322368737000 * % 0.50571296842532187000 * % 0.50571296842531543000 * % 1.27722267527372440000 * % Koniec * */ Console.WriteLine("Korekta wag:"); int accuracy = 15; for (int i = 0; i < diffMatLab.Length; i++) { decimal result = (decimal)diff[0, i]; decimal expected = (decimal)diffMatLab[i]; result = Math.Round(result, accuracy); expected = Math.Round(expected, accuracy); Console.WriteLine(string.Format("NBN C#: {0}\tMatLab NBN: {1}\t {2}", result, expected, result == expected ? "OK" : "źle")); } for (int i = 0; i < diffMatLab.Length; i++) { decimal result = (decimal)diff[0, i]; decimal expected = (decimal)diffMatLab[i]; result = Math.Round(result, accuracy); expected = Math.Round(expected, accuracy); Assert.AreEqual(expected, result); } }
private void Delete(object obj) { Weights.Remove((IWeightViewModel)obj); }
public void AddWeightsTask([FromBody] Weights weights) { _storage.AddAWeights(weights); }
public void AutoFixMechDef(MechDef mechDef) { if (!AutoFixerFeature.settings.MechDefEngine) { return; } //DumpAllAsTable(); if (mechDef.Inventory.Any(c => c.Def.GetComponent <EngineCoreDef>() != null)) { return; } Control.mod.Logger.Log($"Auto fixing mechDef={mechDef.Description.Id} chassisDef={mechDef.Chassis.Description.Id}"); ArmorStructureRatioFeature.Shared.AutoFixMechDef(mechDef); var builder = new MechDefBuilder(mechDef.Chassis, mechDef.Inventory.ToList()); var standardHeatSinkDef = mechDef.DataManager.GetDefaultEngineHeatSinkDef(); var engineHeatSinkDef = builder.Inventory .Select(r => r.Def.GetComponent <CoolingDef>()) .Where(d => d != null) .Select(d => mechDef.DataManager.HeatSinkDefs.Get(d.HeatSinkDefId)) .Where(d => d != null) .Select(d => d.GetComponent <EngineHeatSinkDef>()) .FirstOrDefault() ?? standardHeatSinkDef; float freeTonnage; { float currentTotalTonnage = 0, maxValue = 0; MechStatisticsRules.CalculateTonnage(mechDef, ref currentTotalTonnage, ref maxValue); var maxFreeTonnage = mechDef.Chassis.Tonnage - currentTotalTonnage; var initialTonnage = mechDef.Chassis.InitialTonnage; var originalInitialTonnage = ChassisHandler.GetOriginalInitialTonnage(mechDef.Chassis) ?? initialTonnage; var initialTonnageGain = Mathf.Max(0, originalInitialTonnage - initialTonnage); if (AutoFixerFeature.settings.MechDefAutoFixAgainstMaxFreeTonnage.Contains(mechDef.Description.Id)) { freeTonnage = maxFreeTonnage; } else { var freeTonnageThreshold = AutoFixerFeature.settings.MechDefAutoFixInitialTonnageDiffThreshold; freeTonnage = Mathf.Min(maxFreeTonnage, initialTonnageGain + freeTonnageThreshold); } Control.mod.Logger.LogDebug($"freeTonnage={freeTonnage}" + $" currentTotalTonnage={currentTotalTonnage}" + $" maxFreeTonnage={maxFreeTonnage}" + $" initialTonnageGain={initialTonnageGain}" + $" initialGainSmaller={initialTonnageGain < maxFreeTonnage}"); } //Control.mod.Logger.LogDebug("C maxEngineTonnage=" + maxEngineTonnage); var standardWeights = new Weights(); // use default gyro and weights var standardHeatBlock = mechDef.DataManager.HeatSinkDefs.Get(AutoFixerFeature.settings.MechDefHeatBlockDef).GetComponent <EngineHeatBlockDef>(); var standardCooling = mechDef.DataManager.HeatSinkDefs.Get(AutoFixerFeature.settings.MechDefCoolingDef).GetComponent <CoolingDef>(); var engineCoreDefs = mechDef.DataManager.HeatSinkDefs .Select(hs => hs.Value) .Select(hs => hs.GetComponent <EngineCoreDef>()) .Where(c => c != null) .OrderByDescending(x => x.Rating); Engine maxEngine = null; { //var heatSinks = builder.Inventory.Where(x => x.ComponentDefType == ComponentType.HeatSink && x.Def.Is<EngineHeatSinkDef>()).ToList(); var jumpJetList = builder.Inventory.Where(x => x.ComponentDefType == ComponentType.JumpJet).ToList(); var engines = new LinkedList <Engine>(); foreach (var coreDef in engineCoreDefs) { { var engine = new Engine(standardCooling, standardHeatBlock, coreDef, standardWeights, new List <MechComponentRef>()); engines.AddFirst(engine); } { // remove superfluous jump jets var maxJetCount = coreDef.GetMovement(mechDef.Chassis.Tonnage).JumpJetCount; //Control.mod.Logger.LogDebug($"before Inventory.Count={builder.Inventory.Count} jumpJetList.Count={jumpJetList.Count} maxJetCount={maxJetCount}"); while (jumpJetList.Count > maxJetCount) { var lastIndex = jumpJetList.Count - 1; var jumpJet = jumpJetList[lastIndex]; freeTonnage += jumpJet.Def.Tonnage; builder.Remove(jumpJet); jumpJetList.Remove(jumpJet); } //Control.mod.Logger.LogDebug($"after Inventory.Count={builder.Inventory.Count} jumpJetList.Count={jumpJetList.Count} maxJetCount={maxJetCount}"); } foreach (var engine in engines) { // Control.mod.Logger.LogDebug($"D engine={engine.CoreDef} engine.TotalTonnage={engine.TotalTonnage} freeTonnage={freeTonnage}"); if (engine.TotalTonnage <= freeTonnage) { maxEngine = engine; } else { break; } } if (maxEngine != null) { break; } } } if (maxEngine == null) { return; } Control.mod.Logger.LogDebug($" maxEngine={maxEngine.CoreDef} freeTonnage={freeTonnage}"); { var dummyCore = builder.Inventory.FirstOrDefault(r => r.ComponentDefID == AutoFixerFeature.settings.MechDefCoreDummy); if (dummyCore != null) { builder.Remove(dummyCore); } } // add engine builder.Add(maxEngine.CoreDef.Def, ChassisLocations.CenterTorso, true); if (!EngineFeature.settings.AllowMixingHeatSinkTypes) { // remove incompatible heat sinks var incompatibleHeatSinks = builder.Inventory .Where(r => r.Def.Is <EngineHeatSinkDef>(out var hs) && hs.HSCategory != engineHeatSinkDef.HSCategory) .ToList(); foreach (var incompatibleHeatSink in incompatibleHeatSinks) { builder.Remove(incompatibleHeatSink); } //Control.mod.Logger.LogDebug($"Inventory.Count={builder.Inventory.Count} incompatibleHeatSinks.Count={incompatibleHeatSinks.Count}"); // add same amount of compatible heat sinks foreach (var unused in incompatibleHeatSinks) { builder.Add(engineHeatSinkDef.Def); } //Control.mod.Logger.LogDebug($"Inventory.Count={builder.Inventory.Count}"); } // add free heatsinks { //var maxFree = maxEngine.CoreDef.ExternalHeatSinksFreeMaxCount; //var current = maxEngine.ExternalHeatSinkCount; var maxFree = maxEngine.HeatSinkExternalFreeMaxCount; var current = 0; //we assume exiting heatsinks on the mech are additional and not free for (var i = current; i < maxFree; i++) { if (!builder.Add(engineHeatSinkDef.Def)) { break; } } //Control.mod.Logger.LogDebug($"Inventory.Count={builder.Inventory.Count} maxFree={maxFree}"); } // find any overused location if (builder.HasOveruseAtAnyLocation()) { // heatsinks, upgrades var itemsToBeReordered = builder.Inventory .Where(IsReorderable) .OrderBy(c => MechDefBuilder.LocationCount(c.Def.AllowedLocations)) .ThenByDescending(c => c.Def.InventorySize) .ThenByDescending(c => { switch (c.ComponentDefType) { case ComponentType.Upgrade: return(2); case ComponentType.AmmunitionBox: return(1); default: return(0); } }) .ToList(); // remove all items that can be reordered: heatsinks, upgrades foreach (var item in itemsToBeReordered) { builder.Remove(item); } // then add most restricting, and then largest items first (probably double head sinks) foreach (var item in itemsToBeReordered) { // couldn't add everything if (!builder.Add(item.Def)) { return; } } } mechDef.SetInventory(builder.Inventory.OrderBy(element => element, new OrderComparer()).ToArray()); //{ // float currentTotalTonnage = 0, maxValue = 0; // MechStatisticsRules.CalculateTonnage(mechDef, ref currentTotalTonnage, ref maxValue); // Control.mod.Logger.LogDebug($" end currentTotalTonnage={currentTotalTonnage} mechDef.Chassis.Tonnage={mechDef.Chassis.Tonnage}"); //} }
private void EnqueueLap(ILap lap, Weights weight) { EnqueueLap(lap.Time, weight); }
internal override void Compute(List <Node> allNodes) { if (LineStarts == null) { return; } Moves.FillArray(Triple.Zero); Weights.FillArray(Weight); int[] moveCounts = new int[NodeCount]; for (int j = 0; j < LineStarts.Count; j++) { Triple s = LineStarts[j]; Triple e = LineEnds[j]; Triple d = e - s; float lineLength = d.Length; d /= lineLength; for (int i = 0; i < NodeIndices.Length; i++) { Triple c = allNodes[NodeIndices[i]].Position; float r = Radii[i]; Triple v = c - s; float shadow = v.Dot(d); if (0f < shadow && shadow < lineLength) { Triple move = v - d * shadow; float distance = move.Length; if (distance < r) { Moves[i] += move * (r - distance) / distance; } moveCounts[i]++; } else { if (shadow >= lineLength) { v = c - e; } float vLength = v.Length; if (vLength < r) { Moves[i] += v * (r - vLength) / vLength; moveCounts[i]++; } } } } for (int i = 0; i < NodeIndices.Length; i++) { if (moveCounts[i] != 0) { Moves[i] /= moveCounts[i]; } } }
protected override void AddToMenu() { var ultimateMenu = Menu.AddSubMenu(new Menu("Ultimate", Menu.Name + ".ultimate")); var blitzMenu = ultimateMenu.AddSubMenu(new Menu("Blitzcrank", ultimateMenu.Name + ".blitzcrank")); HeroListManager.AddToMenu( blitzMenu.AddSubMenu(new Menu("Blacklist", blitzMenu.Name + ".blacklist")), new HeroListManagerArgs("blitzcrank") { IsWhitelist = false, Allies = false, Enemies = true, DefaultValue = false, EnabledButton = false }); blitzMenu.AddItem(new MenuItem(blitzMenu.Name + ".r", "Enabled").SetValue(true)); var tahmMenu = ultimateMenu.AddSubMenu(new Menu("Tahm Kench", ultimateMenu.Name + ".tahm-kench")); HeroListManager.AddToMenu( tahmMenu.AddSubMenu(new Menu("Blacklist", tahmMenu.Name + ".blacklist")), new HeroListManagerArgs("tahm-kench") { IsWhitelist = false, Allies = false, Enemies = true, DefaultValue = false, EnabledButton = false }); tahmMenu.AddItem(new MenuItem(tahmMenu.Name + ".r", "Enabled").SetValue(true)); ultimateMenu.AddItem(new MenuItem(ultimateMenu.Name + ".save", "Save Soulbound").SetValue(true)); var comboMenu = Menu.AddSubMenu(new Menu("Combo", Menu.Name + ".combo")); HitchanceManager.AddToMenu( comboMenu.AddSubMenu(new Menu("Hitchance", comboMenu.Name + ".hitchance")), "combo", new Dictionary <string, HitChance> { { "Q", HitChance.VeryHigh } }); ResourceManager.AddToMenu( comboMenu, new ResourceManagerArgs( "combo-q", ResourceType.Mana, ResourceValueType.Percent, ResourceCheckType.Minimum) { Prefix = "Q", DefaultValue = 10 }); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".q", "Use Q").SetValue(true)); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".e", "Use E").SetValue(true)); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".e-min", "E Fleeing Min.").SetValue(new Slider(8, 1, 20))); comboMenu.AddItem(new MenuItem(comboMenu.Name + ".minions", "Attack Minions").SetValue(false)); var harassMenu = Menu.AddSubMenu(new Menu("Harass", Menu.Name + ".harass")); HitchanceManager.AddToMenu( harassMenu.AddSubMenu(new Menu("Hitchance", harassMenu.Name + ".hitchance")), "harass", new Dictionary <string, HitChance> { { "Q", HitChance.High } }); ResourceManager.AddToMenu( harassMenu, new ResourceManagerArgs( "harass-q", ResourceType.Mana, ResourceValueType.Percent, ResourceCheckType.Minimum) { Prefix = "Q", DefaultValue = 30 }); ResourceManager.AddToMenu( harassMenu, new ResourceManagerArgs( "harass-e", ResourceType.Mana, ResourceValueType.Percent, ResourceCheckType.Minimum) { Prefix = "E", DefaultValue = 30 }); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".q", "Use Q").SetValue(true)); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".e", "Use E").SetValue(true)); harassMenu.AddItem(new MenuItem(harassMenu.Name + ".e-min", "E Min.").SetValue(new Slider(4, 1, 20))); var laneclearMenu = Menu.AddSubMenu(new Menu("Lane Clear", Menu.Name + ".lane-clear")); ResourceManager.AddToMenu( laneclearMenu, new ResourceManagerArgs( "lane-clear", ResourceType.Mana, ResourceValueType.Percent, ResourceCheckType.Minimum) { Advanced = true, MaxValue = 101, LevelRanges = new SortedList <int, int> { { 1, 6 }, { 6, 12 }, { 12, 18 } }, DefaultValues = new List <int> { 50, 30, 30 }, IgnoreJungleOption = true }); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".q", "Use Q").SetValue(true)); laneclearMenu.AddItem( new MenuItem(laneclearMenu.Name + ".q-min", "Q Min. Hits").SetValue(new Slider(2, 1, 5))); laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".e", "Use E").SetValue(true)); var lasthitMenu = Menu.AddSubMenu(new Menu("Last Hit", Menu.Name + ".lasthit")); ResourceManager.AddToMenu( lasthitMenu, new ResourceManagerArgs( "lasthit", ResourceType.Mana, ResourceValueType.Percent, ResourceCheckType.Minimum) { Advanced = true, MaxValue = 101, LevelRanges = new SortedList <int, int> { { 1, 6 }, { 6, 12 }, { 12, 18 } }, DefaultValues = new List <int> { 50, 30, 30 } }); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e-siege", "E Siege Minion").SetValue(true)); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e-unkillable", "E Unkillable").SetValue(true)); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e-turret", "E Under Turret").SetValue(true)); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".separator", string.Empty)); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e-jungle", "E Jungle").SetValue(true)); lasthitMenu.AddItem(new MenuItem(lasthitMenu.Name + ".e-big", "E Dragon/Baron").SetValue(true)); var killstealMenu = Menu.AddSubMenu(new Menu("Killsteal", Menu.Name + ".killsteal")); killstealMenu.AddItem(new MenuItem(killstealMenu.Name + ".e", "Use E").SetValue(true)); var miscMenu = Menu.AddSubMenu(new Menu("Misc", Menu.Name + ".miscellaneous")); ResourceManager.AddToMenu( miscMenu, new ResourceManagerArgs("misc", ResourceType.Mana, ResourceValueType.Percent, ResourceCheckType.Minimum) { Prefix = "E", DefaultValue = 30 }); miscMenu.AddItem(new MenuItem(miscMenu.Name + ".e-reset", "E Harass Reset").SetValue(true)); miscMenu.AddItem( new MenuItem(miscMenu.Name + ".w-baron", "Hotkey W Baron").SetValue(new KeyBind('J', KeyBindType.Press))); miscMenu.AddItem( new MenuItem(miscMenu.Name + ".w-dragon", "Hotkey W Dragon").SetValue( new KeyBind('K', KeyBindType.Press))); IndicatorManager.AddToMenu(DrawingManager.Menu, true); IndicatorManager.Add(Q, true, false); IndicatorManager.Add(W, true, false); IndicatorManager.Add("E", Rend.GetDamage); IndicatorManager.Finale(); Weights.GetItem("low-health").GetValueFunc = hero => hero.Health - Rend.GetDamage(hero); Weights.AddItem( new Weights.Item( "w-stack", "W Stack", 10, false, hero => hero.HasBuff("kalistacoopstrikemarkally") ? 10 : 0)); }
public void Generate() { ConcurrentBag <AssociationRule> result = new ConcurrentBag <AssociationRule>(); ConcurrentBag <AlgorithmProgressExecution> algExecution = new ConcurrentBag <AlgorithmProgressExecution>(); ConcurrentBag <Task> tasks = new ConcurrentBag <Task>(); int index = 0; foreach (Row singleRow in InformationSystem.Rows) { decimal gamma = InformationSystem.Gamma; decimal alpha = InformationSystem.Alpha; List <Attribute> attrs = singleRow.Attributes.Where(x => InformationSystem.DecisionAttributes[x.Name] == true).Select(x => x).ToList(); foreach (Attribute decisionAttribute in attrs) { var localCopy = System.Tuple.Create <Row, Attribute>(singleRow, decisionAttribute); Task <AssociationRule> task = Task.Factory.StartNew <AssociationRule>((variables) => { var decAttr = ((System.Tuple <Row, Attribute>)variables).Item2; var row = ((System.Tuple <Row, Attribute>)variables).Item1; #region algorithm body IList <Row> separatedRows; Condition decisionAttributeInResult = new Condition(decAttr); //List<int> deltas = new List<int>(); IList <Condition> conditions = new List <Condition>(); separatedRows = InformationSystem.Rows.GetRowsSeparatedByAttribute(row, decAttr); decimal M = System.Math.Ceiling(separatedRows.Count() * (1 - alpha)); decimal N = System.Math.Ceiling(separatedRows.Count() * (1 - gamma)); IList <Row> separatedRowsCopy = separatedRows; int alreadyCovered = 0; AlgorithmProgressExecution progress = new AlgorithmProgressExecution() { DecisionAttribute = decAttr }; while (alreadyCovered < M) { AlgorithmIteration iteration = new AlgorithmIteration() { IterationNumber = progress.Iterations.Count() + 1, ObjectsToCover = separatedRowsCopy.Count }; IList <Subset> subsets = separatedRowsCopy.CreateSubsets(row, decAttr, false); //here we must calculate for each subset its quotient: w(fj)/min(|U(T,r,d,fj)\D|,N-|D|) //where D is output set, empty at the beginning Dictionary <Subset, decimal> quotients = new Dictionary <Subset, decimal>(); subsets.Where(x => x.Count > 0).ToList().ForEach(subset => { quotients[subset] = System.Convert.ToDecimal(Weights.Where(x => x.Key == subset.Name) .Select(x => x.Value).First()) / System.Math.Min(subset.Rows.Count, N - alreadyCovered); }); string subsetWithMinimumQuotient = quotients .OrderBy(x => x.Value) .Select(x => x.Key) .First() .Name; var elementsQuantityInSelectedSubset = subsets.Where(x => x.Name == subsetWithMinimumQuotient) .Select(x => x.Count).First(); alreadyCovered += elementsQuantityInSelectedSubset; //int elementsQuantityInSelectedSubset = subsets.Where( // x => x.Name == subsetWithMinimumQuotient) // .Select(x => x.Count) // .First(); iteration.ObjectsCovered = elementsQuantityInSelectedSubset; //deltas.Add(elementsQuantityInSelectedSubset); //alreadyCovered += elementsQuantityInSelectedSubset; conditions.Add(new Condition( row.Attributes.Where(x => x.Name == subsetWithMinimumQuotient).First())); separatedRowsCopy = separatedRowsCopy .RemoveElementsFromAlreadyCoveredSubsets(subsets, subsetWithMinimumQuotient); progress.Iterations.Add(iteration); } var rule = new AssociationRule(conditions, decisionAttributeInResult); var supportAndConfidence = rule.CalculateSupportAndConfidence(InformationSystem.Rows); rule.Support = supportAndConfidence.Item1.Round(); rule.Confidence = supportAndConfidence.Item2.Round(); //var upperLowerBound = rule.CalculateUpperAndLowerBound(System.Convert.ToInt32(M), deltas); rule.UpperBound = -1; // upperLowerBound.Item1; rule.LowerBound = -1; //upperLowerBound.Item2; algExecution.Add(progress); #endregion return(rule); }, localCopy, CancellationToken.None, TaskCreationOptions.AttachedToParent, TaskScheduler.Default); task.ContinueWith(x => { if (x.Status == TaskStatus.RanToCompletion) { lock (locker) { result.Add(((Task <AssociationRule>)x).Result); Notify(++index); } } }, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, guiScheduler); tasks.Add(task); } } var finish = Task.Factory.ContinueWhenAll(tasks.ToArray(), x => { SeparatedRows(algExecution); Rules(result); }, CancellationToken.None, TaskContinuationOptions.None, guiScheduler); }
public void AddWeight(float weight, int boneIndex) { Weights.Add(weight); BoneIndices.Add(boneIndex); WeightCount++; }
public void Weigths___Correction___Test() { var gradient = new MatrixMB(7, 1); //gradient = [-0.839948683228052; 2.319597374905329; 2.319597374905329; -2.000000000000000; 5.523188311911530; 5.523188311911531; 6.889667569278484]; gradient[0,0] = -0.839948683228052; gradient[1,0] = 2.319597374905329; gradient[2,0] = 2.319597374905329; gradient[3,0] = -2.000000000000000; gradient[4,0] = 5.523188311911530; gradient[5,0] = 5.523188311911531; gradient[6,0] = 6.889667569278484; /* hessian = [ 1.058270685684809 -0.705513790456539 -0.705513790456539 2.519846049684157 -1.679897366456105 -1.679897366456105 -0.639700008449225; -0.705513790456539 1.058270685684809 0.352756895228269 -1.679897366456105 2.519846049684157 0.839948683228052 1.279400016898449; -0.705513790456539 0.352756895228269 1.058270685684809 -1.679897366456105 0.839948683228052 2.519846049684157 1.279400016898449; 2.519846049684157 -1.679897366456105 -1.679897366456105 6.000000000000000 -4.000000000000000 -4.000000000000000 -1.523188311911530; -1.679897366456105 2.519846049684157 0.839948683228052 -4.000000000000000 6.000000000000000 2.000000000000000 3.046376623823059; -1.679897366456105 0.839948683228052 2.519846049684157 -4.000000000000000 2.000000000000000 6.000000000000000 3.046376623823059; -0.639700008449225 1.279400016898449 1.279400016898449 -1.523188311911530 3.046376623823059 3.046376623823059 3.480153950315843 ]; */ MatrixMB hessian = new MatrixMB(7, 7); //col 1 hessian[0, 0] = 1.058270685684809; hessian[1, 0] = -0.705513790456539; hessian[2, 0] = -0.705513790456539; hessian[3, 0] = 2.519846049684157; hessian[4, 0] = -1.679897366456105; hessian[5, 0] = -1.679897366456105; hessian[6, 0] = -0.639700008449225; //col 2 hessian[0, 1] = -0.705513790456539; hessian[1, 1] = 1.058270685684809; hessian[2, 1] = 0.352756895228269; hessian[3, 1] = -1.679897366456105; hessian[4, 1] = 2.519846049684157; hessian[5, 1] = 0.839948683228052; hessian[6, 1] = 1.279400016898449; //col 3 hessian[0, 2] = -0.705513790456539; hessian[1, 2] = 0.352756895228269; hessian[2, 2] = 1.058270685684809; hessian[3, 2] = -1.679897366456105; hessian[4, 2] = 0.839948683228052; hessian[5, 2] = 2.519846049684157; hessian[6, 2] = 1.279400016898449; //col 4 hessian[0, 3] = 2.519846049684157; hessian[1, 3] = -1.679897366456105; hessian[2, 3] = -1.679897366456105; hessian[3, 3] = 6.000000000000000; hessian[4, 3] = -4.000000000000000; hessian[5, 3] = -4.000000000000000; hessian[6, 3] = -1.523188311911530; //col 5 hessian[0, 4] = -1.679897366456105; hessian[1, 4] = 2.519846049684157; hessian[2, 4] = 0.839948683228052; hessian[3, 4] = -4.000000000000000; hessian[4, 4] = 6.000000000000000; hessian[5, 4] = 2.000000000000000; hessian[6, 4] = 3.046376623823059; //col 6 hessian[0, 5] = -1.679897366456105; hessian[1, 5] = 0.839948683228052; hessian[2, 5] = 2.519846049684157; hessian[3, 5] = -4.000000000000000; hessian[4, 5] = 2.000000000000000; hessian[5, 5] = 6.000000000000000; hessian[6, 5] = 3.046376623823059; //col 7 hessian[0, 6] = -0.639700008449225; hessian[1, 6] = 1.279400016898449; hessian[2, 6] = 1.279400016898449; hessian[3, 6] = -1.523188311911530; hessian[4, 6] = 3.046376623823059; hessian[5, 6] = 3.046376623823059; hessian[6, 6] = 3.480153950315843; Weights weights = new Weights(7); weights.FillWithNumber(1); double mu = 0.01; var I = MatrixMB.Eye(weights.Length); Console.WriteLine("Testowanie obliczania korekty wag"); Console.WriteLine("Hesjan:"); Console.WriteLine(hessian.MatrixToString()); Console.WriteLine("Gradient:"); Console.WriteLine(gradient.MatrixToString()); Console.WriteLine("Wagi początkowe:"); Console.WriteLine(weights.MatrixToString()); Console.WriteLine("MU = " + mu.ToString()); Console.WriteLine("Macierz I"); Console.WriteLine(I.MatrixToString()); //korekta_wag = ((hessian+mu*I)\gradient)'; /* Lewa strona Columns 1 through 6 1.068270685684809 -0.705513790456539 -0.705513790456539 2.519846049684157 -1.679897366456105 -1.679897366456105 -0.705513790456539 1.068270685684809 0.352756895228269 -1.679897366456105 2.519846049684157 0.839948683228052 -0.705513790456539 0.352756895228269 1.068270685684809 -1.679897366456105 0.839948683228052 2.519846049684157 2.519846049684157 -1.679897366456105 -1.679897366456105 6.010000000000000 -4.000000000000000 -4.000000000000000 -1.679897366456105 2.519846049684157 0.839948683228052 -4.000000000000000 6.010000000000000 2.000000000000000 -1.679897366456105 0.839948683228052 2.519846049684157 -4.000000000000000 2.000000000000000 6.010000000000000 -0.639700008449225 1.279400016898449 1.279400016898449 -1.523188311911530 3.046376623823059 3.046376623823059 Column 7 -0.639700008449225 1.279400016898449 1.279400016898449 -1.523188311911530 3.046376623823059 3.046376623823059 3.490153950315843 */ var lewa_strona_matlab = new MatrixMB(7, 7); lewa_strona_matlab[0, 0] = 1.06827068568480900000; lewa_strona_matlab[0, 1] = -0.70551379045653895000; lewa_strona_matlab[0, 2] = -0.70551379045653895000; lewa_strona_matlab[0, 3] = 2.51984604968415700000; lewa_strona_matlab[0, 4] = -1.67989736645610500000; lewa_strona_matlab[0, 5] = -1.67989736645610500000; lewa_strona_matlab[0, 6] = -0.63970000844922503000; lewa_strona_matlab[1, 0] = -0.70551379045653895000; lewa_strona_matlab[1, 1] = 1.06827068568480900000; lewa_strona_matlab[1, 2] = 0.35275689522826897000; lewa_strona_matlab[1, 3] = -1.67989736645610500000; lewa_strona_matlab[1, 4] = 2.51984604968415700000; lewa_strona_matlab[1, 5] = 0.83994868322805205000; lewa_strona_matlab[1, 6] = 1.27940001689844900000; lewa_strona_matlab[2, 0] = -0.70551379045653895000; lewa_strona_matlab[2, 1] = 0.35275689522826897000; lewa_strona_matlab[2, 2] = 1.06827068568480900000; lewa_strona_matlab[2, 3] = -1.67989736645610500000; lewa_strona_matlab[2, 4] = 0.83994868322805205000; lewa_strona_matlab[2, 5] = 2.51984604968415700000; lewa_strona_matlab[2, 6] = 1.27940001689844900000; lewa_strona_matlab[3, 0] = 2.51984604968415700000; lewa_strona_matlab[3, 1] = -1.67989736645610500000; lewa_strona_matlab[3, 2] = -1.67989736645610500000; lewa_strona_matlab[3, 3] = 6.00999999999999980000; lewa_strona_matlab[3, 4] = -4.00000000000000000000; lewa_strona_matlab[3, 5] = -4.00000000000000000000; lewa_strona_matlab[3, 6] = -1.52318831191152990000; lewa_strona_matlab[4, 0] = -1.67989736645610500000; lewa_strona_matlab[4, 1] = 2.51984604968415700000; lewa_strona_matlab[4, 2] = 0.83994868322805205000; lewa_strona_matlab[4, 3] = -4.00000000000000000000; lewa_strona_matlab[4, 4] = 6.00999999999999980000; lewa_strona_matlab[4, 5] = 2.00000000000000000000; lewa_strona_matlab[4, 6] = 3.04637662382305900000; lewa_strona_matlab[5, 0] = -1.67989736645610500000; lewa_strona_matlab[5, 1] = 0.83994868322805205000; lewa_strona_matlab[5, 2] = 2.51984604968415700000; lewa_strona_matlab[5, 3] = -4.00000000000000000000; lewa_strona_matlab[5, 4] = 2.00000000000000000000; lewa_strona_matlab[5, 5] = 6.00999999999999980000; lewa_strona_matlab[5, 6] = 3.04637662382305900000; lewa_strona_matlab[6, 0] = -0.63970000844922503000; lewa_strona_matlab[6, 1] = 1.27940001689844900000; lewa_strona_matlab[6, 2] = 1.27940001689844900000; lewa_strona_matlab[6, 3] = -1.52318831191152990000; lewa_strona_matlab[6, 4] = 3.04637662382305900000; lewa_strona_matlab[6, 5] = 3.04637662382305900000; lewa_strona_matlab[6, 6] = 3.49015395031584270000; var lewa_strona_csharp = hessian + (I * mu); Console.WriteLine("Lewa strona dzielenia - obliczanie korekty wag => (hessian+mu*I)"); for (int i = 0; i < lewa_strona_csharp.Rows; i++) { for (int j = 0; j < lewa_strona_csharp.Cols; j++) { var result = Math.Round(((decimal)lewa_strona_csharp[i, j]), 15); var expected = Math.Round(((decimal)lewa_strona_matlab[i, j]), 15); Console.WriteLine(string.Format("Poz[{0},{1}] => NBN C#: {2}\tMatLab NBN: {3}\t{4}", i,j,result, expected, result == expected ? "OK" : "źle")); } } for (int i = 0; i < lewa_strona_csharp.Rows; i++) { for (int j = 0; j < lewa_strona_csharp.Cols; j++) { var result = Math.Round(((decimal)lewa_strona_csharp[i, j]), 15); var expected = Math.Round(((decimal)lewa_strona_matlab[i, j]), 15); Assert.AreEqual(expected, result); } } var diff = ((hessian + (I * mu)).Inverted * gradient).Transposed; /* Expected weights diff % Otrzymana korekta wag: % % 0.27954017281149085000 % 0.21238647096009383000 % 0.21238647096010940000 % 0.66561250322368737000 % 0.50571296842532187000 % 0.50571296842531543000 % 1.27722267527372440000 % Koniec * */ var diffMatLab = new double[] { 0.27954017281149085000, 0.21238647096009383000, 0.21238647096010940000, 0.66561250322368737000, 0.50571296842532187000, 0.50571296842531543000, 1.27722267527372440000 }; /* Test matlabowy function obliczanie_korekty_wag() %ww = ww_backup - ((hessian+mu*I)\gradient)'; clear(); ww = [1 1 1 1 1 1 1]; mu = 0.01; I = eye(size(ww,2));%tyle co wag format long; gradient = [-0.839948683228052; 2.319597374905329; 2.319597374905329; -2.000000000000000; 5.523188311911530; 5.523188311911531; 6.889667569278484]; hessian = [ 1.058270685684809 -0.705513790456539 -0.705513790456539 2.519846049684157 -1.679897366456105 -1.679897366456105 -0.639700008449225; -0.705513790456539 1.058270685684809 0.352756895228269 -1.679897366456105 2.519846049684157 0.839948683228052 1.279400016898449; -0.705513790456539 0.352756895228269 1.058270685684809 -1.679897366456105 0.839948683228052 2.519846049684157 1.279400016898449; 2.519846049684157 -1.679897366456105 -1.679897366456105 6.000000000000000 -4.000000000000000 -4.000000000000000 -1.523188311911530; -1.679897366456105 2.519846049684157 0.839948683228052 -4.000000000000000 6.000000000000000 2.000000000000000 3.046376623823059; -1.679897366456105 0.839948683228052 2.519846049684157 -4.000000000000000 2.000000000000000 6.000000000000000 3.046376623823059; -0.639700008449225 1.279400016898449 1.279400016898449 -1.523188311911530 3.046376623823059 3.046376623823059 3.480153950315843 ]; korekta_wag = ((hessian+mu*I)\gradient)'; fprintf('\nOtrzymana korekta wag:\n'); for i=1:size(ww,2) fprintf('\n%.20f',korekta_wag(i)); end fprintf('\nKoniec\n'); end % Otrzymana korekta wag: % % 0.27954017281149085000 % 0.21238647096009383000 % 0.21238647096010940000 % 0.66561250322368737000 % 0.50571296842532187000 % 0.50571296842531543000 % 1.27722267527372440000 % Koniec */ Console.WriteLine("Korekta wag:"); int accuracy = 15; for (int i = 0; i < diffMatLab.Length; i++) { decimal result = (decimal)diff[0, i]; decimal expected = (decimal)diffMatLab[i]; result = Math.Round(result, accuracy); expected = Math.Round(expected, accuracy); Console.WriteLine(string.Format("NBN C#: {0}\tMatLab NBN: {1}\t {2}", result, expected, result == expected ? "OK" : "źle")); } for (int i = 0; i < diffMatLab.Length; i++) { decimal result = (decimal)diff[0, i]; decimal expected = (decimal)diffMatLab[i]; result = Math.Round(result, accuracy); expected = Math.Round(expected, accuracy); Assert.AreEqual(expected, result); } }
private void Update() { CharacterStateFlags stateFlags; Weights lastHeadingWeights; Facepunch.Movement.State walk; float lastUnitScale; double deltaTime; this.CalculateVelocity(); Character idMain = base.idMain; bool flag = (bool)idMain; if (flag) { stateFlags = idMain.stateFlags; } else { stateFlags = new CharacterStateFlags(); } bool isJumping = !stateFlags.grounded; bool focus = stateFlags.focus; bool crouch = stateFlags.crouch; lastHeadingWeights.idle = 0f; if (this.movementNormal.x > 0f) { lastHeadingWeights.east = this.movementNormal.x; lastHeadingWeights.west = 0f; } else if (this.movementNormal.x < 0f) { lastHeadingWeights.east = 0f; lastHeadingWeights.west = -this.movementNormal.x; } else { lastHeadingWeights.east = lastHeadingWeights.west = 0f; } if (this.movementNormal.y > 0f) { lastHeadingWeights.north = this.movementNormal.y; lastHeadingWeights.south = 0f; } else if (this.movementNormal.y < 0f) { lastHeadingWeights.north = 0f; lastHeadingWeights.south = -this.movementNormal.y; } else { lastHeadingWeights.north = lastHeadingWeights.south = 0f; } if ((this.movementNormal.y == 0f) && (this.movementNormal.x == 0f)) { lastHeadingWeights = this.lastHeadingWeights; } lastHeadingWeights.idle = 0f; this.lastHeadingWeights = lastHeadingWeights; if (isJumping) { walk = Facepunch.Movement.State.Walk; } else if (crouch) { walk = Facepunch.Movement.State.Crouch; } else if (stateFlags.sprint && (this.speedPrecise >= this.movement.configuration.runSpeed)) { walk = Facepunch.Movement.State.Run; } else { walk = Facepunch.Movement.State.Walk; } string animationGroupName = this.itemHolder.animationGroupName; if (this.idealGroupName != animationGroupName) { this.idealGroupName = animationGroupName; if (animationGroupName != null) { animationGroupName = animationGroupName; } else { animationGroupName = this.animationTrait.defaultGroupName; } int?nullable = this.movement.configuration.GroupIndex(animationGroupName); if (!nullable.HasValue) { Debug.LogWarning("Could not find group name " + this.idealGroupName); this.usingGroupName = this.animationTrait.defaultGroupName; int?nullable2 = this.movement.configuration.GroupIndex(this.usingGroupName); this.usingGroupIndex = !nullable2.HasValue ? 0 : nullable2.Value; } else { this.usingGroupName = this.idealGroupName; this.usingGroupIndex = nullable.Value; } } int usingGroupIndex = this.usingGroupIndex; if (!stateFlags.slipping) { deltaTime = Time.deltaTime; this.movement.state = walk; this.movement.group = usingGroupIndex; lastUnitScale = this.movement.UpdateWeights(Time.deltaTime, isJumping, !flag || stateFlags.movement); } else { deltaTime = -Time.deltaTime; lastUnitScale = this.lastUnitScale; } this.wasAirborne = isJumping; this.lastUnitScale = lastUnitScale; if (!double.IsNaN(this.speedPrecise) && !double.IsInfinity(this.speedPrecise)) { float positionTime = this.positionTime; this.positionTime = (float)((this.positionTime + Math.Abs((double)((lastUnitScale * this.speedPrecise) * deltaTime))) % 1.0); if (this.positionTime < 0f) { this.positionTime++; } else if (float.IsNaN(this.positionTime) || float.IsInfinity(this.positionTime)) { this.positionTime = positionTime; } this.movement.configuration.OffsetTime(this.positionTime, out this.times); } float angle = !flag ? -base.transform.eulerAngles.x : idMain.eyesPitch; this.movement.SetWeights(this.animation, ref lastHeadingWeights, ref this.times, angle); }
protected override void OnPlanning(GraphPlanContext context) { var graph = context.TFGraph; var input = context.TFOutputs[Input.Connection.From]; var weights = Weights.ToHWIO(); var bias = Bias.ToNHWC(); TFOutput y; if (PoolType == K210PoolType.LeftTop) { y = KernelWidth == 1 ? input : graph.SpaceToBatchND(input, graph.Const(new[] { 1, 1 }), graph.Const(new[, ] { { 1, 1 }, { 1, 1 } })); y = Conv2dType == K210Conv2dType.Conv2d ? graph.Conv2D(y, graph.Const(weights), new long[] { 1, 2, 2, 1 }, "VALID") : graph.DepthwiseConv2dNative(y, graph.Const(weights), new long[] { 1, 2, 2, 1 }, "VALID"); } else { y = Conv2dType == K210Conv2dType.Conv2d ? graph.Conv2D(input, graph.Const(weights), new long[] { 1, 1, 1, 1 }, "SAME") : graph.DepthwiseConv2dNative(input, graph.Const(weights), new long[] { 1, 1, 1, 1 }, "SAME"); } y = graph.BiasAdd(y, graph.Const(bias)); context.AdditionalTFOutputs[OutputBeforeActivation] = y; y = AddActivation(graph, y, FusedActivationFunction, NonTrivialActivation); switch (PoolType) { case K210PoolType.MaxPool2x2: y = graph.MaxPool(y, new long[] { 1, 2, 2, 1 }, new long[] { 1, 2, 2, 1 }, "VALID"); break; case K210PoolType.AveragePool2x2: y = graph.AvgPool(y, new long[] { 1, 2, 2, 1 }, new long[] { 1, 2, 2, 1 }, "VALID"); break; case K210PoolType.MaxPool4x4: y = graph.MaxPool(y, new long[] { 1, 4, 4, 1 }, new long[] { 1, 4, 4, 1 }, "VALID"); break; case K210PoolType.AveragePool4x4: y = graph.AvgPool(y, new long[] { 1, 4, 4, 1 }, new long[] { 1, 4, 4, 1 }, "VALID"); break; case K210PoolType.MaxPool2x2Stride1: y = graph.MaxPool(y, new long[] { 1, 2, 2, 1 }, new long[] { 1, 1, 1, 1 }, "SAME"); break; case K210PoolType.AveragePool2x2Stride1: y = graph.AvgPool(y, new long[] { 1, 2, 2, 1 }, new long[] { 1, 1, 1, 1 }, "SAME"); break; default: break; } context.TFOutputs[Output] = y; }
public IControllerValue getGameValues(MainController main, IView view, PipeControllerValue pipeControllerValue, bool isActive, int scoreIncrement, Weights weights = null) { return(new GameControllerValue(main, view, pipeControllerValue, isActive, scoreIncrement, weights)); }
public override string ToString() { return(((Weights != null) ? (Weights.ToString() + "\n") : "") + ((Biases != null) ? Biases.ToString() : "")); }
public void Generate() { decimal gamma = InformationSystem.Gamma; decimal alpha = InformationSystem.Alpha; ConcurrentBag <AssociationRule> result = new ConcurrentBag <AssociationRule>(); foreach (Row row in InformationSystem.Rows) { List <Attribute> attrs = row.Attributes.Where(x => InformationSystem.DecisionAttributes[x.Name] == true).Select(x => x).ToList(); foreach (Attribute decisionAttribute in attrs)// row.Attributes) { Condition decisionAttributeInResult = new Condition(decisionAttribute); IList <Condition> conditions = new List <Condition>(); separatedRows = InformationSystem.Rows.GetRowsSeparatedByAttribute(row, decisionAttribute); decimal M = System.Math.Ceiling(separatedRows.Count() * (1 - alpha)); decimal N = System.Math.Ceiling(separatedRows.Count() * (1 - gamma)); IList <Row> separatedRowsCopy = separatedRows; int alreadyCovered = 0; while (alreadyCovered < M) { IList <Subset> subsets = separatedRowsCopy.CreateSubsets(row, decisionAttribute, false); //here we must calculate for each subset its quotient: w(fj)/min(|U(T,r,d,fj)\D|,N-|D|) //where D is output set, empty at the beginning Dictionary <Subset, decimal> quotients = new Dictionary <Subset, decimal>(); subsets.Where(x => x.Count > 0).ToList().ForEach(subset => { quotients[subset] = System.Convert.ToDecimal(Weights.Where(x => x.Key == subset.Name) .Select(x => x.Value).First()) / System.Math.Min(subset.Rows.Count, N - alreadyCovered); }); string subsetWithMinimumQuotient = quotients .OrderBy(x => x.Value) .Select(x => x.Key) .First() .Name; alreadyCovered += subsets.Where(x => x.Name == subsetWithMinimumQuotient) .Select(x => x.Count).First(); conditions.Add(new Condition( row.Attributes.Where(x => x.Name == subsetWithMinimumQuotient).First())); separatedRowsCopy = separatedRowsCopy .RemoveElementsFromAlreadyCoveredSubsets(subsets, subsetWithMinimumQuotient); } var rule = new AssociationRule(conditions, decisionAttributeInResult); var supportAndConfidence = rule.CalculateSupportAndConfidence(InformationSystem.Rows); rule.Support = supportAndConfidence.Item1.Round(); rule.Confidence = supportAndConfidence.Item2.Round(); result.Add(rule); alreadyCovered = 0; separatedRows = null; } } Rules(result); }
public void ClearWeight() { Weights.Clear(); UnderlyingUserInput.Weights = Weights.ToArray(); }
private void Update() { CharacterStateFlags characterStateFlag; Weights weight = new Weights(); State state; float single; double num; float single1; this.CalculateVelocity(); Character character = base.idMain; bool flag = character; characterStateFlag = (!flag ? new CharacterStateFlags() : character.stateFlags); bool flag1 = !characterStateFlag.grounded; bool flag2 = characterStateFlag.focus; bool flag3 = characterStateFlag.crouch; weight.idle = 0f; if (this.movementNormal.x > 0f) { weight.east = this.movementNormal.x; weight.west = 0f; } else if (this.movementNormal.x >= 0f) { float single2 = 0f; single1 = single2; weight.west = single2; weight.east = single1; } else { weight.east = 0f; weight.west = -this.movementNormal.x; } if (this.movementNormal.y > 0f) { weight.north = this.movementNormal.y; weight.south = 0f; } else if (this.movementNormal.y >= 0f) { float single3 = 0f; single1 = single3; weight.south = single3; weight.north = single1; } else { weight.north = 0f; weight.south = -this.movementNormal.y; } if (this.movementNormal.y == 0f && this.movementNormal.x == 0f) { weight = this.lastHeadingWeights; } weight.idle = 0f; this.lastHeadingWeights = weight; if (flag1) { state = State.Walk; } else if (!flag3) { state = (!characterStateFlag.sprint || this.speedPrecise < (double)this.movement.configuration.runSpeed ? State.Walk : State.Run); } else { state = State.Crouch; } string str = this.itemHolder.animationGroupName; if (this.idealGroupName != str) { this.idealGroupName = str; str = str ?? this.animationTrait.defaultGroupName; int? nullable = this.movement.configuration.GroupIndex(str); if (nullable.HasValue) { this.usingGroupName = this.idealGroupName; this.usingGroupIndex = nullable.Value; } else { Debug.LogWarning(string.Concat("Could not find group name ", this.idealGroupName)); this.usingGroupName = this.animationTrait.defaultGroupName; int? nullable1 = this.movement.configuration.GroupIndex(this.usingGroupName); this.usingGroupIndex = (!nullable1.HasValue ? 0 : nullable1.Value); } } int num1 = this.usingGroupIndex; if (characterStateFlag.slipping) { num = (double)(-Time.deltaTime); single = this.lastUnitScale; } else { num = (double)Time.deltaTime; this.movement.state = state; this.movement.@group = num1; single = this.movement.UpdateWeights(Time.deltaTime, flag1, (!flag ? true : characterStateFlag.movement)); } this.wasAirborne = flag1; this.lastUnitScale = single; if (!double.IsNaN(this.speedPrecise) && !double.IsInfinity(this.speedPrecise)) { float single4 = this.positionTime; this.positionTime = (float)(((double)this.positionTime + Math.Abs((double)single * this.speedPrecise * num)) % 1); if (this.positionTime < 0f) { PlayerAnimation playerAnimation = this; playerAnimation.positionTime = playerAnimation.positionTime + 1f; } else if (float.IsNaN(this.positionTime) || float.IsInfinity(this.positionTime)) { this.positionTime = single4; } this.movement.configuration.OffsetTime(this.positionTime, out this.times); } float single5 = (!flag ? -base.transform.eulerAngles.x : character.eyesPitch); this.movement.SetWeights(this.animation, ref weight, ref this.times, single5); }
private void CalculateForHiddenLayer(ref Index iw, ref Topography topo, ref Weights ww) { for (n = 0; n < nn - no; n++) { j = nio - n - 1; s = iw[j - ni]; J[0, s] = -derivates[j] * delo[0, j]; for (i = s + 1; i <= iw[j - ni + 1] - 1; i++) { J[0, i] = node[topo[i]] * J[0, s]; delo[0, topo[i]] -= ww[i] * J[0, s]; } } }