protected override void OnNavigatedTo(NavigationEventArgs e) { ScrollViewer.SetVerticalScrollMode(CategoryPageGridView, ScrollMode.Disabled); CategoryPageViewModel categoryPageViewModel = (CategoryPageViewModel)Resources["CategoryPageViewModel"]; NavigationItem navigationItem = e.Parameter as NavigationItem; var task = Task.Factory.StartNew(async () => { var bundle = await DownloadNavigationItem(navigationItem.ReferralId); var navigationItems = await DownloadNavigationItemsAsync(); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { categoryPageViewModel.Content = bundle.Content[0]; var items = new List<Content>(bundle.Content); items.RemoveAt(0); bundle.Content = items.ToArray(); categoryPageViewModel.Bundle = bundle; categoryPageViewModel.NavigationItems = navigationItems; LoadingGrid.Visibility = Visibility.Collapsed; MySplitView.Visibility = Visibility.Visible; } ); }); base.OnNavigatedTo(e); }
/// <summary> /// Metoda zwracająca listę okresów notowań połączonych, jeżeli mają ten sam kierunek trendu. Metoda ta rozpoczyna wyznaczanie od parametru periodsEndDate i zmierza ku przeszłości. /// </summary> /// <param name="DesiredNumberOfPeriods">Oczekiwana liczba okresów.</param> /// <param name="periodsEndDate">Ostatnia data okresów.</param> /// <param name="periodsStartDate">Data będąca granicą wyznaczania kolejnych okresów.</param> /// <param name="daysInterval">Liczba określająca długość okresu w dniach.</param> /// <returns>Lista okresów notowań połaczonych, jeżeli mają ten sam kierunek trendu.</returns> public List<ExchangePeriod> GetExchangePeriodsMergedByMovementDirectoryFromEndDate(int DesiredNumberOfPeriods, DateTime periodsEndDate, DateTime periodsStartDate, int daysInterval) { DateTime iterationDate = periodsEndDate.Date; string dataPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\data\\"; List<ExchangePeriod> periodList = new List<ExchangePeriod>(); while (iterationDate >= periodsStartDate) { DateTime periodStart; if (iterationDate.AddDays(-daysInterval) > periodsStartDate) { periodStart = iterationDate.AddDays(-daysInterval); } else { periodStart = periodsStartDate.Date; } ExchangePeriod period = GetExchangePeriod(periodStart, iterationDate); if (period != null) { period.PublicTrading -= GetExchangeDay(period.PeriodStart).PublicTrading; if (periodList.Count != 0) { periodList.First().OpenRate = period.CloseRate; //If percentage changes have the same sign. if ((periodList.First().PercentageChange * period.PercentageChange) > 0 || periodList.First().PeriodStart == periodList.First().PeriodEnd) { periodList.First().PublicTrading += period.PublicTrading; if (period.PeriodEnd != periodList.First().PeriodStart) { periodList.First().PublicTrading += GetExchangeDay(periodList.First().PeriodStart).PublicTrading; } periodList.First().PeriodStart = period.PeriodStart; if ((periodList.Count > 1) && ((periodList[0].PercentageChange * periodList[1].PercentageChange) > 0)) { periodList[1].OpenRate = periodList[0].OpenRate; periodList[1].PeriodStart = periodList[0].PeriodStart; periodList[1].PublicTrading += periodList[0].PublicTrading + GetExchangeDay(periodList[1].PeriodStart).PublicTrading; periodList.RemoveAt(0); } } else { if (periodList.Count == DesiredNumberOfPeriods + 1) { periodList.RemoveAt(0); break; } periodList.Insert(0, period); } } else { periodList.Add(period); } } iterationDate = iterationDate.AddDays(-daysInterval); } return periodList; }
private string getRandomTopicIds(int count, List<int> list) { string result = ""; List<int> cloneList = new List<int>(list); if (count >= cloneList.Count) { foreach (int id in cloneList) { result += id + ","; } } else { Random random = new Random(); for (int i = 0; i< count; i++) { int r = random.Next(cloneList.Count); result += cloneList[r] + ","; cloneList.RemoveAt(r); } } //if (result != "") //{ // result = result.Substring(0, result.Length - 1); //} return result; }
private void UpOrder(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count > 0) { listOrder = dataGridView.DataSource as List<SearchOrder>; int index = dataGridView.SelectedRows[0].Index; if (index >= 1) { var temp = listOrder[index]; listOrder.RemoveAt(index); listOrder.Insert(index - 1, temp); dataGridView.ClearSelection(); dataGridView.Rows[index - 1].Selected = true; dataGridView.Refresh(); } } }
/// <summary> /// Metoda tworzenia i uczenia sieci neuronowych. /// </summary> /// <param name="maxMaxEpochs">Maksymalna liczba epok.</param> /// <param name="minMaxEpochs">Minimalna liczba epok.</param> /// <param name="maxEpochsMultiplierStep">Krok mnożący liczby epok dla kolejnego rodzaju sieci. </param> /// <param name="minHiddenLayersMultiplier">Minimalny mnożnik dla warstw ukrytych.</param> /// <param name="maxHiddenLayersMultiplier">Maksymalny mnożnik dla wartw ukrytych.</param> /// <param name="hiddenLayersMultiplierStep">Krok dodający dla mnożnika warstw ukrytych.</param> /// <param name="methodProgressPart">Wartość (0 - 100) określająca jaka część postępu inicjalizacji należy do tej metody.</param> private void CreateNetworks( string path, string trainDataFolder, string testDataFolder, int maxMaxEpochs, int minMaxEpochs, double maxEpochsMultiplierStep, double minHiddenLayersMultiplier, double maxHiddenLayersMultiplier, double hiddenLayersMultiplierStep, double methodProgressPart, double desiredMSE ) { double methodStartProgress = this.InitializationProgress; List<TrainingDataFileParameters> fileList = DataProvider.Instance.GetTrainingDataFilesParameters(trainDataFolder); List<NeuralNetworkParameters> parameters = new List<NeuralNetworkParameters>(); foreach (TrainingDataFileParameters file in fileList) { for (double i = minMaxEpochs; i <= maxMaxEpochs; i *= maxEpochsMultiplierStep) { for (double j = minHiddenLayersMultiplier; j <= maxHiddenLayersMultiplier; j += hiddenLayersMultiplierStep) { parameters.Add(new NeuralNetworkParameters() { fileParameters = file, hiddenLayersMultiplier = j, maxEpochs = (uint)i }); } } } int numberOfNetworksToCreate = parameters.Count; int numberOfCreatedNetworks = 0; NetworkMSE lowestNetworkMSE = null; try { StringReader reader = new StringReader(File.ReadAllText(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + path + "LowestMSENetwork.xml")); XmlSerializer serializer = new XmlSerializer(typeof(NetworkMSE)); lowestNetworkMSE = (NetworkMSE)serializer.Deserialize(reader); } catch { lowestNetworkMSE = null; } //small hack if (lowestNetworkMSE != null && lowestNetworkMSE.MSE < desiredMSE) { this.InitializationProgress = 100; return; } string[] testFiles = Directory.GetFiles(testDataFolder); List<TrainingData> testDataList = new List<TrainingData>(); foreach (string testFile in testFiles) { TrainingData td = new TrainingData(); //if (td.ReadTrainFromFile(testDataFolder + "\\" + Path.GetFileName(testFile))) if (td.ReadTrainFromFile(testFile)) { testDataList.Add(td); } } List<TrainingData> trainingDataList = new List<TrainingData>(); foreach (TrainingDataFileParameters file in fileList) { TrainingData td = new TrainingData(); if (td.ReadTrainFromFile(trainDataFolder.Split('\\').Last() + "\\" + file.FileName)) { trainingDataList.Add(td); } } string initStatus = this.InitializationStatus; Directory.CreateDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + path); List<Task> taskList = new List<Task>(); NeuralNet.CallbackType[] callbacksArray = new NeuralNet.CallbackType[this.MaxComputingThreads]; Semaphore threadProgressSemaphore = new Semaphore(1, 1); Semaphore allSem = new Semaphore(1, 1); TrainingData[] threadDataVars = new TrainingData[this.MaxComputingThreads]; for (int i = 1; i <= this.MaxComputingThreads; i++) { int taskNumber = i; threadDataVars[i - 1] = new TrainingData(); Task t = new Task((Action)( () => { while (true) { allSem.WaitOne(); if (parameters.Count == 0) { this.InitializationStatus = initStatus + " " + numberOfNetworksToCreate.ToString() + " / " + numberOfNetworksToCreate.ToString(); this.InitializationProgress = 100; break; } else { NeuralNetworkParameters usedParameters = parameters.First(); parameters.RemoveAt(0); if (!File.Exists(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + path + usedParameters.FileName)) { NeuralNet net = new NeuralNet(); List<uint> layers = new List<uint>(); layers.Add((uint)((usedParameters.fileParameters.NumberOfPeriods * 2) - 1)); // inputs layers.Add((uint)(layers[0] * usedParameters.hiddenLayersMultiplier)); // hidden layers.Add(3); // output net.CreateStandardArray(layers.ToArray()); net.SetLearningRate((float)0.7); net.SetActivationFunctionHidden(ActivationFunction.SigmoidSymmetric); net.SetActivationFunctionOutput(ActivationFunction.SigmoidSymmetric); net.Callback += callbacksArray[taskNumber - 1]; threadDataVars[taskNumber - 1] = trainingDataList.Find((e) => ((e.NumInputTrainData == layers[0]) && (e.Input.Length == usedParameters.fileParameters.NumberOfPatterns))); allSem.Release(); net.TrainOnData(threadDataVars[taskNumber - 1], usedParameters.maxEpochs, // max iterations 0,// iterations between report 0 //desired error ); allSem.WaitOne(); net.TestData(testDataList.Find((e) => e.NumInputTrainData == layers[0])); double mse = net.GetMSE(); if (lowestNetworkMSE == null || lowestNetworkMSE.MSE > mse) { lowestNetworkMSE = new NetworkMSE() { MSE = mse, NetworkFileName = usedParameters.FileName }; StringWriter writer = new StringWriter(); XmlSerializer serializer = new XmlSerializer(typeof(NetworkMSE)); serializer.Serialize(writer, lowestNetworkMSE); File.WriteAllText(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + path + "LowestMSENetwork.xml", writer.ToString()); } net.Save(path + usedParameters.FileName); } this.InitializationStatus = initStatus + " " + numberOfCreatedNetworks.ToString() + " / " + numberOfNetworksToCreate.ToString(); numberOfCreatedNetworks++; this.InitializationProgress = (numberOfCreatedNetworks * methodProgressPart / numberOfNetworksToCreate) + methodStartProgress; } allSem.Release(); } } ), TaskCreationOptions.LongRunning ); taskList.Add(t); } foreach (Task t in taskList) { t.Start(); } }
public static void DrawOperation(OpenGL gl, Project testProject, Vector rotation, List<List<double[]>> detailCache) { var bill = testProject.Settings; gl.Translate(bill.Length / 2, bill.Height / 2, bill.Width / 2);//высчитывается из размера заготовки gl.Rotate((float)rotation.Y, (float)rotation.X, 0); // вращение с зажатой средней кнопкой мыши gl.Translate(-bill.Length / 2, -bill.Height / 2, -bill.Width / 2); //var Bill = this.testProject.Settings; Billet.Draw(gl, bill.Height, bill.Length, bill.Width); // заготовка var operations = testProject.Operations;//колличество операций var boltReg = new Regex("BoltHole"); var pocketReg = new Regex("Pocket"); if (detailCache.Count != operations.Count) detailCache.Clear(); for (var i = 0; i < operations.Count; i++)//главный цикл отрисовки { var shapeName = operations[i].Shape.Name; if (boltReg.IsMatch(shapeName)) { var bolt = (Model.Primitives.BoltHole)operations[i].Shape; var boltlocation = operations[i].Location.LocationsList.GetEnumerator(); while (boltlocation.MoveNext()) { if (bolt.Modified || boltlocation.Current.Modified || detailCache.Count<=i) { try { detailCache.RemoveAt(i); } catch{} var location = new Point(boltlocation.Current.X, boltlocation.Current.Y); detailCache.Insert(i, BoltHole.ReCalc(bolt, 0.5, location)); //здесь уже всё ок, кроме величины шага boltlocation.Current.IsDrawn(); bolt.IsDrawn();//значит в кэше лежит актуальная информация } else { var location = new Point(boltlocation.Current.X, boltlocation.Current.Y); BoltHole.Draw(gl, detailCache[i]); //здесь уже всё ок, кроме величины шага } } } if (!pocketReg.IsMatch(shapeName)) continue; var poc = (Model.Primitives.Pocket)operations[i].Shape; var poclocation = operations[i].Location.LocationsList.GetEnumerator(); while (poclocation.MoveNext()) { if (poc.Modified || poclocation.Current.Modified || detailCache.Count <= i) { try { detailCache.RemoveAt(i); } catch { } var location = new Point(poclocation.Current.X, poclocation.Current.Y); var p = Pocket.ReCalc(poc, 0.5, location); detailCache.Insert(i, p); //здесь уже всё ок, кроме величины шага poclocation.Current.IsDrawn(); poc.IsDrawn();//значит в кэше лежит актуальная информация } else { var location = new Point(poclocation.Current.X, poclocation.Current.Y); Pocket.Draw(gl, detailCache[i]); //здесь уже всё ок, кроме величины шага } } } //отрисовщик траекторий gl.Begin(OpenGL.GL_LINE_STRIP); gl.Color(1f, 0, 0); var trajectorys = GCodeGenerator.TrajectoryStor.GetTrajectorys(); foreach (var point in trajectorys.SelectMany(operation => operation)) { gl.Vertex(point.GetCoordinates()); } }