private void Button_EarlyArch_Click(object sender, RoutedEventArgs e) { try { int avgSalary = ConvertCount(TextBox_AvgSalary); double[] parameters = new double[] { PERSLevel[ComboBox_PERS.SelectedIndex].Value, RCPXLevel[ComboBox_RCPX.SelectedIndex].Value, RUSELevel[ComboBox_RUSE.SelectedIndex].Value, PDIFLevel[ComboBox_PDIF.SelectedIndex].Value, PREXLevel[ComboBox_PREX.SelectedIndex].Value, FCILLevel[ComboBox_FCIL.SelectedIndex].Value, SCEDLevel[ComboBox_SCED.SelectedIndex].Value, }; double people = Math.Round(parameters.Aggregate((total, next) => total * next) * 2.45 * Math.Pow(this.loc / 1000.0, this.p)); double time = Math.Round(3.0 * Math.Pow(people, 0.33 + 0.2 * (this.p - 1.01))); Label_EarlyArchPeople.Content = $"Трудозатраты(чел/мес): {people}"; Label_EarlyArchTime.Content = $"Время(мес): {time}"; Label_EarlyArchBudget.Content = $"Бюджет: {people * avgSalary}"; } catch (FPTextBlockParseException) { MessageBox.Show("Введите число", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } catch (FPTextBlockValueException) { MessageBox.Show("Количество должно быть >= нуля", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } }
private double MeanSquareValue(double[] input) { double[] inputSquare = new double[input.Length]; for (int i = 0; i < input.Length; i++) { inputSquare[i] = Math.Pow(input[i], 2); } return(inputSquare.Aggregate((a, b) => a + b) / inputSquare.Length); }
private static void Measure(Action action, int n) { var measures = new double[n]; for (var i = 0; i < n; i++) { var sw = Stopwatch.StartNew(); action(); sw.Stop(); measures[i] = sw.Elapsed.TotalSeconds; } var sum = measures.Aggregate(0.0, (a, b) => a + b); var mean = sum / n; var squareSum = measures.Aggregate(0.0, (a, b) => a + b * b); var stdev = Math.Sqrt(squareSum / n - mean * mean); Console.WriteLine($"Elapsed: {mean} ({stdev})"); }
private static double[] QrGenerateColumn([NotNull][ItemNotNull] double[][] source, int row, int column) { double[] result = new double[source.Length - row]; for (int i = row; i < source.Length; i++) { result[i - row] = source[i][row]; source[i][row] = 0.0; } double norm = result.Aggregate(0.0, (current, next) => current + next * next, Math.Sqrt); if (row.Equals(source.Length - 1) || norm.Equals(0.0)) { source[row][column] = -result[0]; result[0] = Root2; return(result); } double scale0 = result[0] < 0.0 ? -1.0 / norm : 1.0 / norm; source[row][column] = -1.0 / scale0; for (int i = 0; i < result.Length; i++) { result[i] *= scale0; } result[0]++; double scale1 = Math.Sqrt(1.0 / result[0]); for (int i = 0; i < result.Length; i++) { result[i] *= scale1; } return(result); }
// ans1:1395553904 // ans2:712691360 private double FindSolution2(List <string> data) { var arr = data.ToArray(); double[] results = new double[5]; int[] indexes = new int[] { 1, 3, 5, 7, 1 }; // Rule 3 chars to right and 1 char down for (int i = 1; i < arr.Length; i++) { if (arr[i][indexes[0]] == '#') { results[0] = results[0] + 1; } if (arr[i][indexes[1]] == '#') { results[1] = results[1] + 1; } if (arr[i][indexes[2]] == '#') { results[2] = results[2] + 1; } if (arr[i][indexes[3]] == '#') { results[3] = results[3] + 1; } indexes[0] = (indexes[0] + 1) % arr[0].Length; indexes[1] = (indexes[1] + 3) % arr[0].Length; indexes[2] = (indexes[2] + 5) % arr[0].Length; indexes[3] = (indexes[3] + 7) % arr[0].Length; if (i % 2 == 0) { if (arr[i][indexes[4]] == '#') { results[4] = results[4] + 1; } indexes[4] = (indexes[4] + 1) % arr[0].Length; } } Console.WriteLine(string.Join(",", results)); return(results.Aggregate((x, y) => x * y)); }
public void ComputeFMeasure(out double micro, out double macro) { FillConfusionMatrix(); double confusionMatrixSum = Program.data.Count; double[] c = new double[cmsize], p = new double[cmsize], t = new double[cmsize]; for (int i = 0; i < cmsize; i++) { for (int j = 0; j < cmsize; j++) { c[i] += ConfusionMatrix[i, j]; p[j] += ConfusionMatrix[i, j]; if (i == j) { t[i] = ConfusionMatrix[i, j]; } } } double rec = confusionMatrixSum != 0 ? t.Aggregate((x, y) => x + y) / confusionMatrixSum : 0; double prec = 0; for (int i = 0; i < cmsize; i++) { prec += p[i] == 0 ? 0 : t[i] * c[i] / p[i]; } prec = confusionMatrixSum == 0 ? 0 : prec / confusionMatrixSum; macro = (rec + prec) == 0 ? 0 : 2.0 * rec * prec / (rec + prec); micro = 0.0; for (int i = 0; i < cmsize; i++) { prec = p[i] == 0 ? 0 : t[i] / p[i]; rec = c[i] == 0 ? 0 : t[i] / c[i]; micro += (rec + prec) == 0 ? 0 : (2 * rec * prec / (prec + rec)) * c[i]; } micro = confusionMatrixSum == 0 ? 0 : micro / confusionMatrixSum; }
public static double[,] MeanNormalizationStandardization(this double[,] values) { int amountTrain = values.Length / values.GetLength(1); int amountValues = values.GetLength(1); double[,] valuesTemp = new double[amountTrain, amountValues]; for (int i = 0; i < amountTrain; i++) { double[] valuesForMean = new double[amountValues]; for (int j = 0; j < amountValues; j++) { valuesForMean[j] = values[i, j]; } for (int j = 0; j < amountValues; j++) { valuesTemp[i, j] = (values[i, j] - (valuesForMean.Aggregate((a, b) => a + b) / valuesForMean.Length)) / (valuesForMean.Max() - valuesForMean.Min()); } } return(valuesTemp); }
public double Score(double[] sample) { if (sample == null) { throw new ArgumentNullException(nameof(sample)); } if (sample.Length < m_dimensions.Length) { throw new ArgumentException("Provided array is shorter than a number of dimensions."); } var a = new double[m_dimensions.Length]; for (int i = 0; i < m_dimensions.Length; i++) { var p = GetProbability(Distributions[i], sample[i]); // we normalize the value to be between [0-1] as we compute the score as a product of individual probabilities: a[i] = 1 / (p / m_pmax[i]); } var s = a.Aggregate((x, y) => x * y); return(s); }
private double VectorMultiplication(double[] array) { int vectorSize = Vector <double> .Count; var accVector = Vector <double> .Zero; int i; for (i = 0; i <= array.Length - vectorSize; i += vectorSize) { var v = new Vector <double>(array, i); accVector = Vector.Multiply(accVector, v); } var tempArray = new double[Vector <double> .Count]; accVector.CopyTo(tempArray); var result = tempArray.Aggregate(1d, (p, d) => p * d); for (; i < array.Length; i++) { result *= array[i]; } return(result); }
public void Antrenare() { if (k == 0) { return; } double eg; double global = 0; double[] output = new double[val.Length]; double[] errors = new double[val.Length]; do { for (int i = 0; i < val.Length - k; i++) { var fer = val.Skip(i).Take(k).ToArray(); var result = fer.Zip(w, (a, b) => a * b).ToArray().Sum(); var err = result - val[i + k]; for (int j = 0; j < k; j++) { w[j] = w[j] - Eta * val[j] * err; } result = fer.Zip(w, (a, b) => a * b).ToArray().Sum(); err = result - val[i + k]; errors[i] = err; output[i] = result; } eg = errors.Aggregate <double, double>(0, (current, error) => current + Math.Abs(error)); global = (global + eg) / 2; Console.WriteLine(global); } while (Math.Abs(eg - global) > 0.1); Write(output, "Output.txt"); Write(errors, "GlobalErrors.txt"); }
int selecionaPresc(ref int[] solucao, int pos) { int prescAntiga = solucao[pos]; if (!minimizar) { double[] probVPL = new double[m]; probVPL = probVPL.Select((p, idx) => Math.Abs(mVPL[pos, idx] - mVPL[pos, prescAntiga])).ToArray(); var soma = probVPL.Aggregate(0.0, (acc, p) => p + acc); probVPL = probVPL.Select(p => p / soma).ToArray(); var r = rand.NextDouble(); soma = 0; for (int j = 0; j < m; j++) { soma += probVPL[j]; if (soma >= r) { return(j); } } return(m - 1); } else { double[] probCustos = new double[m]; probCustos = probCustos.Select((p, idx) => Math.Abs(mCustosMedios[pos, idx] - mCustosMedios[pos, prescAntiga])).ToArray(); var soma = probCustos.Aggregate(0.0, (acc, p) => p + acc); probCustos = probCustos.Select(p => soma - p).ToArray(); soma = probCustos.Aggregate(0.0, (acc, p) => p + acc); probCustos = probCustos.Select(p => p / soma).ToArray(); var r = rand.NextDouble(); soma = 0; for (int j = 0; j < m; j++) { soma += probCustos[j]; if (soma >= r) { return(j); } } return(m - 1); } }
internal static double EapSEM_Calc(double thEst, CATItems it, int[] x, string model, double[] priorPar = null, double D = 1, string priorDist = "norm", double lower = -4, double upper = 4, double nqp = 33) { double res = 0; double[] X = CatRcs.Utils.CommonHelper.Sequence(lower, upper, nqp); double[] Y1 = null; double[] Y2 = null; if (priorPar == null || priorPar.Length < 2) { priorPar = new double[2]; priorPar[0] = 0; priorPar[1] = 1; } if (String.IsNullOrEmpty(model)) // Dichotomous Items { #region "Function 'L' " Func <double, CATItems, int[], double> L = (th, items, x_in) => { double result = 0; double[] pi = Pi.Pi_Calc(th, it, model, D).Pi; double[] x_p = new double[pi.Length]; double[] x_q = new double[pi.Length]; double[] p_q = new double[pi.Length]; for (int ind_p = 0; ind_p < pi.Length; ind_p++) { x_p[ind_p] = Math.Pow(pi[ind_p], x_in[ind_p]);; x_q[ind_p] = Math.Pow(1 - pi[ind_p], 1 - x_in[ind_p]); p_q[ind_p] = x_p[ind_p] * x_q[ind_p]; } result = p_q.Aggregate((acc, val) => acc * val); return(result); }; #endregion #region "Function 'g' " Func <double[], double[]> g = (s) => { double[] resList = new double[s.Length]; for (int i = 0; i < s.Length; i++) { switch (priorDist) { case "norm": resList[i] = Math.Pow(s[i] - thEst, 2) * CatRcs.Utils.CommonHelper.Dnorm(s[i], priorPar[0], priorPar[1]) * L(s[i], it, x); break; case "unif": resList[i] = Math.Pow(s[i] - thEst, 2) * CatRcs.Utils.CommonHelper.Dunif(s[i], priorPar[0], priorPar[1]) * L(s[i], it, x); break; case "Jeffreys": resList[i] = Math.Pow(s[i] - thEst, 2) * Math.Sqrt(CatRcs.Utils.RowColumn.Sum(Ii.Ii_Calc(s[i], it, model, D).Ii)) * L(s[i], it, x); break; } } return(resList); }; #endregion #region "Function 'h' " Func <double[], double[]> h = (s) => { double[] resList = new double[s.Length]; for (int i = 0; i < s.Length; i++) { switch (priorDist) { case "norm": resList[i] = CatRcs.Utils.CommonHelper.Dnorm(s[i], priorPar[0], priorPar[1]) * L(s[i], it, x); break; case "unif": resList[i] = CatRcs.Utils.CommonHelper.Dunif(s[i], priorPar[0], priorPar[1]) * L(s[i], it, x); break; case "Jeffreys": resList[i] = Math.Sqrt(CatRcs.Utils.RowColumn.Sum(Ii.Ii_Calc(s[i], it, model, D).Ii)) * L(s[i], it, x); break; } } return(resList); }; #endregion Y1 = g(X); Y2 = h(X); } else // Polytomous Items { #region "Function 'LL' " Func <double, CATItems, int[], double> LL = (th, items, x_in) => { double result = 1; double[,] prob = Pi.Pi_Poly_Calc(th, it, model, D).Pi; for (int i = 0; i < x_in.Length; i++) { result = result * prob[i, x_in[i]]; } return(result); }; #endregion #region "Function 'gg' " Func <double[], double[]> gg = (s) => { double[] resList = new double[s.Length]; for (int i = 0; i < s.Length; i++) { switch (priorDist) { case "norm": resList[i] = Math.Pow(s[i] - thEst, 2) * CatRcs.Utils.CommonHelper.Dnorm(s[i], priorPar[0], priorPar[1]) * LL(s[i], it, x); break; case "unif": resList[i] = Math.Pow(s[i] - thEst, 2) * CatRcs.Utils.CommonHelper.Dunif(s[i], priorPar[0], priorPar[1]) * LL(s[i], it, x); break; case "Jeffreys": resList[i] = Math.Pow(s[i] - thEst, 2) * Math.Sqrt(CatRcs.Utils.RowColumn.Sum(Ii.Ii_Calc(s[i], it, model, D).Ii)) * LL(s[i], it, x); break; } } return(resList); }; #endregion #region "Function 'hh' " Func <double[], double[]> hh = (s) => { double[] resList = new double[s.Length]; for (int i = 0; i < s.Length; i++) { switch (priorDist) { case "norm": resList[i] = CatRcs.Utils.CommonHelper.Dnorm(s[i], priorPar[0], priorPar[1]) * LL(s[i], it, x); break; case "unif": resList[i] = CatRcs.Utils.CommonHelper.Dunif(s[i], priorPar[0], priorPar[1]) * LL(s[i], it, x); break; case "Jeffreys": resList[i] = Math.Sqrt(CatRcs.Utils.RowColumn.Sum(Ii.Ii_Calc(s[i], it, model, D).Ii)) * LL(s[i], it, x); break; } } return(resList); }; #endregion Y1 = gg(X); Y2 = hh(X); } if ((Y1 != null) && (Y2 != null)) { res = Math.Sqrt(CatRcs.Integrate_catR.Integrate_CatR_Calc(X, Y1) / CatRcs.Integrate_catR.Integrate_CatR_Calc(X, Y2)); } return(res); }