private void btStartExperiment_Click(object sender, EventArgs e) { if (lbSequencesFolderPath.Text != "" && lbModelsFolderPath.Text != "" && tbExperimentSegmentsLength.Text != "" && tbExperimentSequencesLength.Text != "") { int segmentSize = Int32.Parse(tbExperimentSegmentsLength.Text); //добавить проверку int sequenceLength = Int32.Parse(tbExperimentSequencesLength.Text); //добавить проверку if (segmentSize <= sequenceLength) { CrossModelComputationPreparator preparator = new CrossModelComputationPreparator(lbModelsFolderPath.Text, lbSequencesFolderPath.Text); List <ModelObject> modelsList = preparator.getModelsList(); List <SequenceObject> sequencesList = preparator.getSequencesList(sequenceLength); CrossModelComputation computor = new CrossModelComputation(modelsList, sequencesList, segmentSize); List <CrossModelComputationResultItem> probabilities = computor.compute(); string[,] matr = CrossModelComputation.computationResultsAsMatrix(probabilities); string s = ""; for (int i = 0; i < matr.GetLength(0); i++) { for (int j = 0; j < matr.GetLength(1); j++) { s += matr[i, j] + ","; } s += "\r\n"; } List <CrossModelComputationResultItem> mmis = computor.computeMaximumMutialInformationDistances(probabilities); string[,] matr2 = CrossModelComputation.computationResultsAsMatrix(mmis); string s2 = "\r\n"; for (int i = 0; i < matr2.GetLength(0); i++) { for (int j = 0; j < matr2.GetLength(1); j++) { s2 += matr2[i, j] + ","; } s2 += "\r\n"; } OutStreamer os = new OutStreamer("sas.txt", FileOpenMode.RewriteMode); os.StringToFile(s + s2); if (saveFileDialogExperiment.ShowDialog() == DialogResult.OK) { StreamReader f = File.OpenText("sas.txt"); string Buf = f.ReadToEnd(); StreamWriter sw = new StreamWriter(File.Create(saveFileDialogExperiment.FileName)); sw.Write(Buf); sw.Close(); f.Close(); } } else { MessageBox.Show("Размер сегмента разбиения не должен превышать длину последовательности"); } } else { MessageBox.Show("Не все параметры заданы"); } }
private void btOMCCalculateProbability_Click(object sender, EventArgs e) { if (lbOMCModelPath.Text != "" && lbOMCSequencePath.Text != "" && tbOMCSegmentLength.Text != "" && tbOMCSequenceLength.Text != "") { int segmentSize = Int32.Parse(tbOMCSegmentLength.Text); //добавить проверку int sequenceLength = Int32.Parse(tbOMCSequenceLength.Text); //добавить проверку HMM_QPN Model = new HMM_QPN(lbOMCModelPath.Text); if (Model.IsCorrect() == 1) { int[] res = new int[sequenceLength + 1]; try { res = HMM_PSM.GetOutputSequence(lbOMCSequencePath.Text, sequenceLength); } catch (Exception) { MessageBox.Show("Желаемая длина последовательности превышает размер файла"); return; } ModelObject model = new ModelObject(lbOMCModelPath.Text, Model); SequenceObject sequence = new SequenceObject(lbOMCSequencePath.Text, res); OneModelComputation computor = new OneModelComputation(model, sequence, segmentSize, sequenceLength); List <double> probabilities = computor.compute(); string s = "Model: " + model.ModelName + "\r\n Sequence: " + sequence.SequenceName + "\r\n Sequence length: " + sequenceLength + "\r\n Segment size: " + segmentSize + "\r\n"; for (int i = 0; i < probabilities.Count(); i++) { s += probabilities.ElementAt(i) + ","; } OutStreamer os = new OutStreamer("omc.txt", FileOpenMode.RewriteMode); os.StringToFile(s); if (saveFileDialogExperiment.ShowDialog() == DialogResult.OK) { StreamReader f = File.OpenText("omc.txt"); string Buf = f.ReadToEnd(); StreamWriter sw = new StreamWriter(File.Create(saveFileDialogExperiment.FileName)); sw.Write(Buf); sw.Close(); f.Close(); } } else { MessageBox.Show("Модель некорректна"); } } else { MessageBox.Show("Не все параметры заданы"); } }
public void StartGenerator(int count, Mode mode, PRNGMode rngMode) //будет вызываться от созданного экземпляра и запускать процесс генерации последовательности наблюдений { int n = A.GetLength(0); int state_number = ProbabilityMethod(Pi, rngMode); double[] Farr = ProbabilityFromDistribution(F[state_number]); int period_length = F[state_number][ProbabilityMethod(Farr, rngMode)].value; int stop = (count - period_length >= 0) ? period_length : count; if (File.Exists("res.txt")) { File.Delete("res.txt"); } if (mode == HSMPQApplication.Mode.Test) { if (File.Exists("sost.txt")) { File.Delete("sost.txt"); } if (File.Exists("sostdur.txt")) { File.Delete("sostdur.txt"); //тут будут пары (состояние длительность) } } PQN_Method(state_number, period_length, stop, mode, rngMode); OutStreamer OutStream = new OutStreamer("sostdur.txt"); OutStream.StringToFile(state_number + ";" + period_length); for (int counter = period_length; counter < count; counter++)// counter = period_length { double[] StolbecP = new double[n]; StolbecP = MatrToArr(A, state_number); state_number = ProbabilityMethod(StolbecP, rngMode); Farr = ProbabilityFromDistribution(F[state_number]); period_length = F[state_number][ProbabilityMethod(Farr, rngMode)].value; stop = (count - period_length - counter >= 0) ? period_length : count - counter; OutStream = new OutStreamer("sostdur.txt"); OutStream.StringToFile(state_number + ";" + period_length); PQN_Method(state_number, period_length, stop, mode, rngMode); counter += period_length - 1; } }